MainController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace business\controllers;
  3. use common\components\stringUtil;
  4. use common\components\util;
  5. use Yii;
  6. use GatewayClient\Gateway;
  7. class MainController extends BaseController
  8. {
  9. public function actionDemo()
  10. {
  11. return $this->renderPartial('demo');
  12. }
  13. public function actionBind()
  14. {
  15. //加载GatewayClient。安装GatewayClient参见本页面底部介绍
  16. require_once '/your/path/GatewayClient/Gateway.php';
  17. // GatewayClient 3.0.0版本开始要使用命名空间
  18. // 设置GatewayWorker服务的Register服务ip和端口,请根据实际情况改成实际值
  19. Gateway::$registerAddress = '127.0.0.1:1236';
  20. // 假设用户已经登录,用户uid和群组id在session中
  21. $uid = $_SESSION['uid'];
  22. $group_id = $_SESSION['group'];
  23. // client_id与uid绑定
  24. Gateway::bindUid($client_id, $uid);
  25. // 加入某个群组(可调用多次加入多个群组)
  26. Gateway::joinGroup($client_id, $group_id);
  27. }
  28. public function actionSend()
  29. {
  30. //加载GatewayClient。安装GatewayClient参见本页面底部介绍
  31. require_once '/your/path/GatewayClient/Gateway.php';
  32. // GatewayClient 3.0.0版本开始要使用命名空间
  33. // 设置GatewayWorker服务的Register服务ip和端口,请根据实际情况改成实际值
  34. Gateway::$registerAddress = '127.0.0.1:1236';
  35. // 向任意uid的网站页面发送数据
  36. Gateway::sendToUid($uid, $message);
  37. // 向任意群组的网站页面发送数据
  38. Gateway::sendToGroup($group, $message);
  39. }
  40. }