Gatewayworker.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\common\library;
  3. use think\Request;
  4. use GatewayClient\Gateway;
  5. require_once VENDOR_PATH . 'workerman/gatewayclient/Gateway.php';
  6. /**
  7. * gateway绑定接口
  8. */
  9. class Gatewayworker
  10. {
  11. public function __construct(Request $request = null)
  12. {
  13. parent::__construct($request);
  14. $params_from = $this->request->request('params_from'); // 客户端
  15. if ($params_from == "wxmin") {
  16. Gateway::$registerAddress = "127.0.0.1:1239";
  17. } else {
  18. Gateway::$registerAddress = "127.0.0.1:1238";
  19. }
  20. }
  21. /**
  22. * 直播间中发送大礼物,全服通告
  23. */
  24. public static function sendBigGiftInParty($sender, $receiver, $partyInfo, $giftUserParty)
  25. {
  26. $aData = [
  27. 'code' => 'party',
  28. 'data' => [
  29. 'cmd' => 'send_big_gift_in_party',
  30. 'content' => [
  31. 'party_info' => [
  32. 'party_id' => $partyInfo['id'],
  33. 'room_type' => $partyInfo['room_type'],
  34. 'party_name' => $partyInfo['party_name']
  35. ],
  36. 'notice_info' => [
  37. 'sender' => $sender,
  38. 'receiver' => $receiver,
  39. 'gift_num' => $giftUserParty['number'],
  40. 'gift_name' => $giftUserParty['gift_name'],
  41. 'gift_image' => $giftUserParty['gift_gif_image']
  42. ]
  43. ]
  44. ]
  45. ];
  46. dump($aData);
  47. Gateway::sendToAll(json_encode($aData));
  48. }
  49. /**
  50. * 直播间中发送礼物,本房间飘屏
  51. */
  52. public static function sendGiftInParty($sender, $receiver, $partyInfo, $giftUserParty)
  53. {
  54. $aData = [
  55. 'code' => 'party',
  56. 'data' => [
  57. 'cmd' => 'send_gift_in_party',
  58. 'content' => [
  59. 'party_info' => [
  60. 'party_id' => $partyInfo['id'],
  61. 'room_type' => $partyInfo['room_type'],
  62. 'party_name' => $partyInfo['party_name']
  63. ],
  64. 'notice_info' => [
  65. 'sender' => $sender,
  66. 'receiver' => $receiver,
  67. 'gift_num' => $giftUserParty['number'],
  68. 'gift_name' => $giftUserParty['gift_name'],
  69. 'gift_image' => $giftUserParty['gift_gif_image']
  70. ]
  71. ]
  72. ]
  73. ];
  74. Gateway::sendToGroup($partyInfo['id'],json_encode($aData));
  75. }
  76. // 注意除了不支持sendToCurrentClient和closeCurrentClient方法
  77. // Gateway::sendToAll($data);
  78. // Gateway::sendToClient($client_id, $data);
  79. // Gateway::closeClient($client_id);
  80. // Gateway::isOnline($client_id);
  81. // Gateway::bindUid($client_id, $uid);
  82. // Gateway::isUidOnline($uid);
  83. // Gateway::getClientIdByUid($uid);
  84. // Gateway::unbindUid($client_id, $uid);
  85. // Gateway::sendToUid($uid, $data);
  86. // Gateway::joinGroup($client_id, $group);
  87. // Gateway::sendToGroup($group, $data);
  88. // Gateway::leaveGroup($client_id, $group);
  89. // Gateway::getClientCountByGroup($group);
  90. // Gateway::getClientSessionsByGroup($group);
  91. // Gateway::getAllClientCount();
  92. // Gateway::getAllClientSessions();
  93. // Gateway::setSession($client_id, $session);
  94. // Gateway::updateSession($client_id, $session);
  95. // Gateway::getSession($client_id);
  96. }