Feishu.php
2.5 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
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Jiaoyin;
class Feishu{
private static $users = [
'liquid' => 'gd1d6b34',
'jiaoyin' => 'efdgdecb',
'linghu' => '6ac9fb35',
'tanli' => 'f16c2bd7',
'small' => 'db9d9g4d',
'007' => '9de6cgf3',
];
//发送预警通知
static public function send($content,$users=[])
{
return self::notice($content,'follow',$users);
}
static public function sendNoError($content,$users=[])
{
return self::notice($content,'error',$users);
}
static public function notice($content,$channel="warning",$users=[])
{
$urls = [
'follow' => 'https://open.feishu.cn/open-apis/bot/v2/hook/f30bbb72-091c-499d-a577-43c45dceb158',//跟单
'warning' => 'https://open.feishu.cn/open-apis/bot/v2/hook/d48c2e4a-0ef9-4684-88d4-e62d878fdaca',//盈迪苟异常报警
'error' => 'https://open.feishu.cn/open-apis/bot/v2/hook/a344e313-4d5d-4aa4-912b-dda37b2e3ee8',//零容忍
'strategy'=>'https://open.feishu.cn/open-apis/bot/v2/hook/53444f37-cfec-420c-a4e6-2f415b908dee',//A01-交易策略研发沟通
];
$url = $urls[$channel] ?? $urls['warning'];
$userXml = '';
foreach ($users as $user) {
if(!empty(self::$users[$user])){
$userXml .= "<at user_id='" . self::$users[$user] . "'></at>";
}else{
$userXml .= "<at user_id='" . $user. "'></at>";//直接用传入的。
}
}
$content = [
'msg_type'=>"text",
'content'=>[
'text'=>$content.$userXml
]
];
$con = json_encode($content);
return self::send_post_json($url,$con);
}
static public function send_post_json($url, $jsonStr)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($jsonStr)
)
);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($httpCode, $response);
}
}