ChatController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace business\controllers;
  3. use biz\user\services\UserService;
  4. use Yii;
  5. use common\components\util;
  6. use GatewayClient\Gateway;
  7. class ChatController extends BaseController
  8. {
  9. //聊天 shish 2019.12.28
  10. public function actionIndex()
  11. {
  12. $get = Yii::$app->request->get();
  13. $userId = isset($get['userId']) ? $get['userId'] : 0;
  14. $user = UserService::getById($userId);
  15. UserService::valid($user, $this->merchantId);
  16. return $this->renderPartial('index',['userId'=>$userId]);
  17. }
  18. //绑定 shish 2019.12.28
  19. public function actionBind()
  20. {
  21. $post = Yii::$app->request->post();
  22. $clientId = isset($post['clientId']) ? $post['clientId'] : '';
  23. $id = 'merchant_' . $this->merchantId;
  24. Gateway::bindUid($clientId, $id);
  25. }
  26. //发消息给客户 shish 2019.12.28
  27. public function actionSend()
  28. {
  29. $post = Yii::$app->request->post();
  30. $msg = isset($post['msg']) ? $post['msg'] : '';
  31. $userId = isset($post['userId']) ? $post['userId'] : 0;
  32. $user = UserService::getById($userId);
  33. UserService::valid($user, $this->merchantId);
  34. $m = json_encode(array(
  35. 'type' => 'msg',
  36. 'msg' => $msg,
  37. ));
  38. Gateway::sendToUid($userId, $m);
  39. }
  40. }