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