ChatController.php 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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::$registerAddress = '127.0.0.1:1238';
  25. Gateway::bindUid($clientId, $userId);
  26. }
  27. //发消息 shish 2019.12.28
  28. public function actionSend()
  29. {
  30. $post = Yii::$app->request->post();
  31. $msg = isset($post['msg']) ? $post['msg'] : '';
  32. $m = json_encode(array(
  33. 'type' => 'msg',
  34. 'msg' => $msg,
  35. ));
  36. Gateway::sendToUid($uid, $m);
  37. }
  38. }