Robot.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\admin\controller\vbot;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\Exception;
  6. use think\exception\PDOException;
  7. use think\exception\ValidateException;
  8. /**
  9. * 微信机器人管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Robot extends Backend
  14. {
  15. /**
  16. * VbotRobot模型对象
  17. * @var \app\admin\model\VbotRobot
  18. */
  19. protected $model = null;
  20. protected $multiFields = 'openswitch';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new \app\admin\model\VbotRobot;
  25. }
  26. /*验证机器人配置*/
  27. public function msg_test()
  28. {
  29. $VbotLib = new \addons\vbot\library\VbotLib();
  30. $webhook = $this->request->only('webhook');
  31. if (!$webhook['webhook']) {
  32. $this->error('请输入Hook地址!');
  33. }
  34. $data = array(
  35. 'msgtype' => 'text',
  36. 'text' => [
  37. 'content' => '这是一条测试消息!',
  38. 'mentioned_mobile_list' => ["@all"]
  39. ]
  40. );
  41. $res = $VbotLib->msgSend($webhook['webhook'], $data);
  42. if ($res['errcode'] == 0) {
  43. $this->success('消息发送成功!');
  44. } else {
  45. $this->error($res['errmsg'] . '(' . $res['errcode'] . ')');
  46. }
  47. }
  48. }