WsController.php 951 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. // websocket相关
  3. namespace ghs\controllers;
  4. use bizGhs\ws\services\WsService;
  5. use common\components\util;
  6. use Yii;
  7. use GatewayClient\Gateway;
  8. class WsController extends BaseController
  9. {
  10. public $guestAccess = ['bind','send'];
  11. //绑定用户
  12. public function actionBind()
  13. {
  14. $post = Yii::$app->request->post();
  15. $clientId = isset($post['clientId']) ? $post['clientId'] : '';
  16. $shopAdminId = $this->shopAdminId;
  17. Gateway::bindUid($clientId, $shopAdminId);
  18. util::complete();
  19. }
  20. //关闭当前链接
  21. public function actionClose()
  22. {
  23. $post = Yii::$app->request->post();
  24. $clientId = isset($post['clientId']) ? $post['clientId'] : '';
  25. Gateway::closeClient($clientId);
  26. }
  27. //模拟推送ws (仅供测试联调用)
  28. public function actionSend()
  29. {
  30. WsService::arrivalNotice($this->shopAdminId, 9866.29);
  31. util::complete();
  32. }
  33. }