DingService.php
1.4 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
<?php
/**
* @author:wlj
* @date: 2022/8/10 15:02
*/
namespace App\Services;
use App\Enums\Common\RedisKey;
use App\Services\BaseService;
use App\Traits\RedisTrait;
use App\Utils\HttpUtils;
class DingService extends BaseService
{
use RedisTrait;
const LINK = 'https://oapi.dingtalk.com/robot/send?access_token=723c99369cc16806a26fee8b8ab2c5ae37a78ef842e6a3af89fed0b2a6211836';
const INFO = 'INFO';
const ERROR = 'ERROR';
const WARNNING = 'WARNNING';
const OTHER = 'OTHER';
/**
* @notes: 发送钉钉消息 同样的消息 1分钟内不重复
* @param array $body
* @return int|mixed
* @author:wlj
* @date: 2022/8/10 15:31
*/
public function handle(array $body)
{
$msgKey = mb_substr($body['msg'], 50);
if (!$this->getData(RedisKey::DING_MSG . $msgKey)) {
$arr = [
'msgtype' => 'text',
'text' => [
'content' => $body['keyword'] . PHP_EOL . $body['msg']
],
'at' => [
'atMobiles' => [],
'atUserIds' => [],
'isAtAll' => $body['isAtAll'],
]
];
$re = json_decode(HttpUtils::post(self::LINK, $arr), true);
$this->setData(RedisKey::DING_MSG . $msgKey, true, 60);
return $re['errcode'] ?? 0;
}
return 0;
}
}