ChatController.php 910 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace client\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use common\components\util;
  6. use GatewayClient\Gateway;
  7. class ChatController extends BaseController
  8. {
  9. public function beforeAction($action)
  10. {
  11. return parent::beforeAction($action);
  12. }
  13. //聊天首页,前端使用
  14. public function actionIndex()
  15. {
  16. return $this->renderPartial('index');
  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. $userId = $this->userId;
  24. Gateway::bindUid($clientId, $userId);
  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. $id = 'merchant_' . $this->merchantId;
  32. $m = json_encode(array(
  33. 'type' => 'msg',
  34. 'msg' => $msg,
  35. ));
  36. Gateway::sendToUid($id, $m);
  37. }
  38. }