WsController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. //模拟推送订单通知
  34. public function actionSendOrder()
  35. {
  36. WsService::newOrderNotice($this->shopAdminId);
  37. util::complete();
  38. }
  39. }