WsController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. Yii::info("ws band shopAdminId clientId ". $shopAdminId.'---'.$clientId);
  18. Gateway::bindUid($clientId, $shopAdminId);
  19. util::complete();
  20. }
  21. //关闭当前链接
  22. public function actionClose()
  23. {
  24. $post = Yii::$app->request->post();
  25. $clientId = isset($post['clientId']) ? $post['clientId'] : '';
  26. Gateway::closeClient($clientId);
  27. }
  28. //模拟推送ws (仅供测试联调用)
  29. public function actionSend()
  30. {
  31. WsService::arrivalNotice($this->shopAdminId, 9866.29);
  32. util::complete();
  33. }
  34. //模拟推送订单通知
  35. public function actionSendOrder()
  36. {
  37. WsService::newOrderNotice($this->shopAdminId);
  38. util::complete();
  39. }
  40. }