mirror of
https://github.com/netcccyun/dnsmgr.git
synced 2026-02-21 15:31:12 +08:00
群机器人通知支持@用户
This commit is contained in:
parent
70d3922013
commit
86c557face
@ -257,6 +257,7 @@ class MsgNotice
|
||||
public static function send_webhook($title, $content)
|
||||
{
|
||||
$url = config_get('webhook_url');
|
||||
$atuser = config_get('webhook_user');
|
||||
if (!$url || !parse_url($url)) return false;
|
||||
if (strpos($url, 'oapi.dingtalk.com')) {
|
||||
$content = '### '.$title." \n ".str_replace("\n", " \n ", $content);
|
||||
@ -267,6 +268,14 @@ class MsgNotice
|
||||
'text' => $content,
|
||||
],
|
||||
];
|
||||
if (!empty($atuser)) {
|
||||
if ($atuser == 'all') {
|
||||
$post['at'] = ['isAtAll' => true];
|
||||
} else {
|
||||
$atusers = explode(',', $atuser);
|
||||
$post['at'] = ['atMobiles' => $atusers, 'isAtAll' => false];
|
||||
}
|
||||
}
|
||||
} elseif (strpos($url, 'qyapi.weixin.qq.com')) {
|
||||
$content = '## '.$title."\n".$content;
|
||||
$post = [
|
||||
@ -276,11 +285,63 @@ class MsgNotice
|
||||
],
|
||||
];
|
||||
} elseif (strpos($url, 'open.feishu.cn') || strpos($url, 'open.larksuite.com')) {
|
||||
$content = str_replace(['\*', '**'], ['*', ''], strip_tags($content));
|
||||
$content = str_replace('<font color="warning">', '<font color="red">', $content);
|
||||
if (!empty($atuser)) {
|
||||
if ($atuser == 'all') {
|
||||
$content .= "\n".'<at id=all></at> ';
|
||||
} else {
|
||||
$atusers = explode(',', $atuser);
|
||||
$content .= "\n";
|
||||
foreach ($atusers as $u) {
|
||||
$content .= '<at user_id="'.$u.'"></at> ';
|
||||
}
|
||||
}
|
||||
}
|
||||
$template = 'blue';
|
||||
if(strpos($title, '发生告警') !== false || strpos($title, '失败') !== false) $template = 'red';
|
||||
else if(strpos($title, '恢复正常') !== false) $template = 'green';
|
||||
else if(strpos($title, '到期提醒') !== false) $template = 'yellow';
|
||||
$post = [
|
||||
'msg_type' => 'text',
|
||||
'content' => [
|
||||
'text' => $content,
|
||||
'msg_type' => 'interactive',
|
||||
'card' => [
|
||||
'schema' => '2.0',
|
||||
'config' => [
|
||||
'update_multi' => true,
|
||||
'style' => [
|
||||
'text_size' => [
|
||||
'normal_v2' => [
|
||||
'default' => 'normal',
|
||||
'pc' => 'normal',
|
||||
'mobile' => 'heading',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'header' => [
|
||||
'title' => [
|
||||
'tag' => 'plain_text',
|
||||
'content' => $title,
|
||||
],
|
||||
'subtitle' => [
|
||||
'tag' => 'plain_text',
|
||||
'content' => '',
|
||||
],
|
||||
'template' => $template,
|
||||
'padding' => '12px 12px 12px 12px',
|
||||
],
|
||||
'body' => [
|
||||
'direction' => 'vertical',
|
||||
'padding' => '12px 12px 12px 12px',
|
||||
'elements' => [
|
||||
[
|
||||
'tag' => 'markdown',
|
||||
'content' => $content,
|
||||
'text_align' => 'left',
|
||||
'text_size' => 'normal_v2',
|
||||
'margin' => '0px 0px 0px 0px',
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
} else {
|
||||
|
||||
@ -121,6 +121,10 @@
|
||||
<label class="col-sm-3 control-label">Webhook地址</label>
|
||||
<div class="col-sm-9"><input type="text" name="webhook_url" value="{:config_get('webhook_url')}" class="form-control"/></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">@用户手机号</label>
|
||||
<div class="col-sm-9"><input type="text" name="webhook_user" value="{:config_get('webhook_user')}" class="form-control" placeholder="非必填,可填写用户的手机号,@全体填写all"/></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-9">
|
||||
<input type="submit" name="submit" value="保存" class="btn btn-primary btn-block"/>
|
||||
@ -130,7 +134,9 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
仅支持填写企业微信、钉钉、飞书群机器人的Webhook地址
|
||||
仅支持填写企业微信、钉钉、飞书群机器人的Webhook地址<br/>
|
||||
认证方式可以选自定义关键词“DNS”或IP白名单。<br/>
|
||||
@用户不支持企业微信,飞书用户手机号需要填写<a href="https://open.feishu.cn/document/home/user-identity-introduction/open-id" target="_blank" rel="noreferrer">用户ID</a>。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user