Pushmessage.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\controller\fastchat;
  3. use addons\fastchat\library\Chat;
  4. use app\common\controller\Backend;
  5. /**
  6. *
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Pushmessage extends Backend
  11. {
  12. /**
  13. * FastChatServiceUser模型对象
  14. * @var \app\admin\model\FastChatServiceUser
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. }
  21. public function index()
  22. {
  23. if ($this->request->isPost()) {
  24. $params = $this->request->post("row/a");
  25. if ($params) {
  26. if ($params['serviceuser_id'] <= 0) {
  27. $this->error('请选择服务账号!');
  28. }
  29. if ($params['group_id'] <= 0 && $params['admin_group_id'] <= 0) {
  30. $this->error('请选择用户或管理员分组!');
  31. }
  32. if ($params['message'] == '') {
  33. $this->error('请填写消息内容!');
  34. }
  35. // 先实例化再链式调用
  36. /*$Chat = new Chat(1);//这里传的是服务号ID
  37. $Chat->user('1,2,3')->send('消息内容');*/
  38. // 静态链式调用
  39. $res = Chat::init($params['serviceuser_id'])
  40. ->user_group($params['group_id'])
  41. ->admin_group($params['admin_group_id'])
  42. ->send($params['message']);
  43. if ($res['errcode'] == 0) {
  44. $this->success('消息推送成功!');
  45. } else {
  46. $this->error($res['errmsg']);
  47. }
  48. }
  49. }
  50. return $this->view->fetch();
  51. }
  52. public function example()
  53. {
  54. $res = Chat::init(1)
  55. ->user('1,2')
  56. // ->user(array(1,2))
  57. ->admin('2')
  58. ->user_group('1,2')
  59. ->admin_group('1,2')
  60. ->send('消息内容');
  61. if ($res['errcode'] == 0) {
  62. $this->success('消息推送成功!');
  63. } else {
  64. $this->error($res['errmsg']);
  65. }
  66. }
  67. }