factory_client.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "{$host}:{$port}";
  35. }
  36. public function create_bargain($goods_id,$user)
  37. {
  38. $param = ["act" => 'factory','op' => 'create', "type" => 'bargain','params' => ['goods_id' => $goods_id,'user' => $user]];
  39. $result = $this->request($param);
  40. if(empty($result)) return false;
  41. $code = intval($result['code']);
  42. if($code != 200) {
  43. return false;
  44. }
  45. else {
  46. return true;
  47. }
  48. }
  49. public function create_chat($creator,$user)
  50. {
  51. $param = ["act" => 'factory','op' => 'create', "type" => 'chat','params' => ['creator' => $creator,'user' => $user] ];
  52. $result = $this->request($param);
  53. if(empty($result)) return false;
  54. $code = intval($result['code']);
  55. if($code != 200) {
  56. return false;
  57. }
  58. else {
  59. return $result['data'];
  60. }
  61. }
  62. public function create_group($creator)
  63. {
  64. $param = ["act" => 'factory','op' => 'create', "type" => 'group','creator' => $creator];
  65. $result = $this->request($param);
  66. if(empty($result)) return false;
  67. $code = intval($result['code']);
  68. if($code != 200) {
  69. return false;
  70. }
  71. else {
  72. return $result['data'];
  73. }
  74. }
  75. public function create_shake($creator)
  76. {
  77. $param = ["act" => 'factory','op' => 'create', "type" => 'shake_bonus','creator' => $creator];
  78. $result = $this->request($param);
  79. if(empty($result)) return false;
  80. $code = intval($result['code']);
  81. if($code != 200) {
  82. return false;
  83. }
  84. else {
  85. return $result['data'];
  86. }
  87. }
  88. public function invite($roomid,$user)
  89. {
  90. $param = ["act" => 'factory','op' => 'invite','room' => $roomid,'user' => $user];
  91. $result = $this->request($param);
  92. if(empty($result)) return false;
  93. $code = intval($result['code']);
  94. if($code != 200) {
  95. return false;
  96. }
  97. else {
  98. return $result['data'];
  99. }
  100. }
  101. }