WsController.php 805 B

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