factory_client.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/12/14
  6. * Time: 上午11:43
  7. */
  8. namespace room;
  9. use search\tcp_client;
  10. class factory_client extends tcp_client
  11. {
  12. protected static $stInstance;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->mBodyType = tcp_client::JsonType;
  17. }
  18. public static function instance()
  19. {
  20. if(self::$stInstance == null) {
  21. self::$stInstance = new factory_client();
  22. }
  23. return self::$stInstance;
  24. }
  25. public function __destruct()
  26. {
  27. parent::__destruct();
  28. }
  29. public function remote_addr()
  30. {
  31. global $config;
  32. $host = $config['room_factory']['host'];
  33. $port = $config['room_factory']['port'];
  34. return "tcp://{$host}:{$port}";
  35. }
  36. //////////////////////////////////////fcgi//////////////////////////////////////////////////////////////////////////
  37. public function create_bargain($goods_id,$user,$lowest_price,$usable_days,$random = true,$total_num = 10,$finvite = true)
  38. {
  39. $random = $random ? 1 : 0;
  40. $param = ["act" => 'fcgi','op' => 'create', "type" => 'bargain_goods','creator' => $user,'invite' => $finvite,
  41. 'goods_id' => $goods_id,
  42. 'lowest_price' => $lowest_price,
  43. 'usable_days' => $usable_days,
  44. 'random' => $random,'total_num' => $total_num];
  45. $result = $this->request($param);
  46. if(empty($result)) return false;
  47. $code = intval($result['code']);
  48. if($code != 200) {
  49. return false;
  50. }
  51. else {
  52. return $result['data'];
  53. }
  54. }
  55. public function create_chat($creator,$user,$finvite = true)
  56. {
  57. $param = ["act" => 'fcgi','op' => 'create', "type" => 'chat','creator' => $creator,'user' => $user,'invite' => $finvite];
  58. $result = $this->request($param);
  59. if(empty($result)) return false;
  60. $code = intval($result['code']);
  61. if($code != 200) {
  62. return false;
  63. }
  64. else {
  65. return $result['data'];
  66. }
  67. }
  68. public function create_group($creator,$finvite = true)
  69. {
  70. $param = ["act" => 'fcgi','op' => 'create', "type" => 'group','creator' => $creator,'invite' => $finvite];
  71. $result = $this->request($param);
  72. if(empty($result)) return false;
  73. $code = intval($result['code']);
  74. if($code != 200) {
  75. return false;
  76. }
  77. else {
  78. return $result['data'];
  79. }
  80. }
  81. public function create_shake($creator,$finvite = true)
  82. {
  83. $param = ["act" => 'fcgi','op' => 'create', "type" => 'shake_bonus','creator' => $creator,'invite' => $finvite];
  84. $result = $this->request($param);
  85. if(empty($result)) return false;
  86. $code = intval($result['code']);
  87. if($code != 200) {
  88. return false;
  89. }
  90. else {
  91. return $result['data'];
  92. }
  93. }
  94. public function invite($roomid, $inviter,$invitees)
  95. {
  96. $param = ["act" => 'fcgi','op' => 'invite','room' => $roomid,'inviter' => $inviter,'invitees' => $invitees];
  97. $result = $this->request($param);
  98. if(empty($result)) return false;
  99. $code = intval($result['code']);
  100. if($code != 200 || empty($result['data']['invitees'])) {
  101. return false;
  102. }
  103. else {
  104. return $result['data'];
  105. }
  106. }
  107. public function leave($roomid, $user)
  108. {
  109. $param = ["act" => 'fcgi','op' => 'invite','room' => $roomid,'user' => $user];
  110. $result = $this->request($param);
  111. if(empty($result)) return false;
  112. $code = intval($result['code']);
  113. if($code != 200) {
  114. return false;
  115. }
  116. else {
  117. return $result['data'];
  118. }
  119. }
  120. public function push($content)
  121. {
  122. $param = ["act" => 'fcgi','op' => 'push','content' => $content];
  123. $result = $this->request($param);
  124. if(empty($result)) return false;
  125. $code = intval($result['code']);
  126. if($code != 200) {
  127. return false;
  128. }
  129. else {
  130. return true;
  131. }
  132. }
  133. //////////////////////////////////////access////////////////////////////////////////////////////////////////////////
  134. public function access()
  135. {
  136. $param = ["act" => 'access','op' => 'who'];
  137. $result = $this->request($param);
  138. if(empty($result)) return false;
  139. $code = intval($result['code']);
  140. if($code != 200) {
  141. return false;
  142. }
  143. else {
  144. return true;
  145. }
  146. }
  147. }