factory_client.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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,$finvite = true)
  56. {
  57. $param = ["act" => 'fcgi','op' => 'create', "type" => proto_type::sroom_chat,'creator' => $creator,'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_shake($creator,$finvite = true)
  69. {
  70. $param = ["act" => 'fcgi','op' => 'create', "type" => 'shake_bonus','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. //////////////////////////////////////fcgi//////////////////////////////////////////////////////////////////////////
  82. public function invite($roomid, $inviter,$invitees)
  83. {
  84. $users = [];
  85. foreach ($invitees as $user) {
  86. $users[] = intval($user);
  87. }
  88. $users = array_unique($users);
  89. if(empty($users)) return false;
  90. $param = ["act" => 'fcgi','op' => 'invite','room' => $roomid,'inviter' => $inviter,'invitees' => $users];
  91. $result = $this->request($param);
  92. if(empty($result)) return false;
  93. $code = intval($result['code']);
  94. if($code != 200 || empty($result['data']['invitees'])) {
  95. return false;
  96. }
  97. else {
  98. return $result['data'];
  99. }
  100. }
  101. public function leave($roomid, $user)
  102. {
  103. $param = ["act" => 'fcgi','op' => 'leave','room' => $roomid,'user' => $user];
  104. $result = $this->request($param);
  105. if(empty($result)) return false;
  106. $code = intval($result['code']);
  107. if($code != 200) {
  108. return false;
  109. } else {
  110. return $result['data'];
  111. }
  112. }
  113. public function kickout($roomid,$user,$kicks)
  114. {
  115. $users = [];
  116. foreach ($kicks as $kick) {
  117. $uid = intval($kick);
  118. if($uid > 0) $users[] = $uid;
  119. }
  120. if(empty($kicks)) return false;
  121. $param = ["act" => 'fcgi','op' => 'kickout','room' => $roomid,'user' => $user,'kicks' => $users];
  122. $result = $this->request($param);
  123. if(empty($result)) return false;
  124. $code = intval($result['code']);
  125. if($code != 200) {
  126. return false;
  127. } else {
  128. return $result['data'];
  129. }
  130. }
  131. public function change($roomid)
  132. {
  133. $param = ["act" => 'fcgi','op' => 'change','room' => $roomid];
  134. $result = $this->request($param);
  135. if(empty($result)) return false;
  136. $code = intval($result['code']);
  137. if($code != 200) {
  138. return false;
  139. } else {
  140. return $result['data'];
  141. }
  142. }
  143. public function notice_all($type,$content,$msg)
  144. {
  145. $param = ["act" => 'fcgi','op' => 'notice_all','type' => $type,'content' => $content,'msg' => $msg];
  146. $result = $this->request($param);
  147. if(empty($result)) return false;
  148. $code = intval($result['code']);
  149. if($code != 200) {
  150. return false;
  151. } else {
  152. return true;
  153. }
  154. }
  155. public function notice_users($users,$type,$content,$msg)
  156. {
  157. $receivers = [];
  158. foreach ($users as $user) {
  159. $receivers[] = intval($user);
  160. }
  161. $param = ["act" => 'fcgi','op' => 'notice_users','users' => $receivers,'type' => $type,'content' => $content,'msg' => $msg];
  162. $result = $this->request($param);
  163. if(empty($result)) return false;
  164. $code = intval($result['code']);
  165. if($code != 200) {
  166. return false;
  167. } else {
  168. return true;
  169. }
  170. }
  171. public function notice_room($room, $sender, $type, $content)
  172. {
  173. $param = ["act" => 'fcgi','op' => 'notice_room','room' => $room,'type' => $type,'content' => $content,'user' => $sender];
  174. $result = $this->request($param);
  175. if(empty($result)) return false;
  176. $code = intval($result['code']);
  177. if($code != 200) {
  178. return false;
  179. } else {
  180. return true;
  181. }
  182. }
  183. //////////////////////////////////////access////////////////////////////////////////////////////////////////////////
  184. public function access()
  185. {
  186. $param = ["act" => 'access','op' => 'who'];
  187. $result = $this->request($param);
  188. if(empty($result)) return false;
  189. $code = intval($result['code']);
  190. if($code != 200) {
  191. return false;
  192. }
  193. else {
  194. return true;
  195. }
  196. }
  197. }