diff --git a/app/utils/MsgNotice.php b/app/utils/MsgNotice.php index 4870e4b..746208e 100644 --- a/app/utils/MsgNotice.php +++ b/app/utils/MsgNotice.php @@ -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('', '', $content); + if (!empty($atuser)) { + if ($atuser == 'all') { + $content .= "\n".' '; + } else { + $atusers = explode(',', $atuser); + $content .= "\n"; + foreach ($atusers as $u) { + $content .= ' '; + } + } + } + $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 { diff --git a/app/view/system/noticeset.html b/app/view/system/noticeset.html index bd9f6d0..496abd2 100644 --- a/app/view/system/noticeset.html +++ b/app/view/system/noticeset.html @@ -121,6 +121,10 @@
+
+ +
+
@@ -130,7 +134,9 @@