From 9ba1c2c32d7e8507bc10c3b9bdea3489f45ef215 Mon Sep 17 00:00:00 2001 From: zheng Date: Tue, 19 Apr 2022 15:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=92=89=E9=92=89@=20?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=85=81=E8=AE=B8=E5=85=B3=E9=97=AD?= =?UTF-8?q?at=20(#917)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit token_xxx?noat=1 --- src/server/common/sender/dingtalk.go | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/server/common/sender/dingtalk.go b/src/server/common/sender/dingtalk.go index 0c51738d..e845e2d5 100644 --- a/src/server/common/sender/dingtalk.go +++ b/src/server/common/sender/dingtalk.go @@ -1,6 +1,7 @@ package sender import ( + "net/url" "strings" "time" @@ -38,24 +39,38 @@ func SendDingtalk(message DingtalkMessage) { } for i := 0; i < len(message.Tokens); i++ { - url := "https://oapi.dingtalk.com/robot/send?access_token=" + message.Tokens[i] + u, err := url.Parse(message.Tokens[i]) + if err != nil { + logger.Errorf("dingtalk_sender: failed to parse error=%v", err) + } + + v, err := url.ParseQuery(u.RawQuery) + if err != nil { + logger.Errorf("dingtalk_sender: failed to parse query error=%v", err) + } + + ur := "https://oapi.dingtalk.com/robot/send?access_token=" + u.Path body := dingtalk{ Msgtype: "markdown", Markdown: dingtalkMarkdown{ Title: message.Title, - Text: message.Text + " " + strings.Join(ats, " "), - }, - At: dingtalkAt{ - AtMobiles: message.AtMobiles, - IsAtAll: false, + Text: message.Text, }, } - res, code, err := poster.PostJSON(url, time.Second*5, body) + if v.Get("noat") != "1" { + body.Markdown.Text = message.Text + " " + strings.Join(ats, " ") + body.At = dingtalkAt{ + AtMobiles: message.AtMobiles, + IsAtAll: false, + } + } + + res, code, err := poster.PostJSON(ur, time.Second*5, body) if err != nil { - logger.Errorf("dingtalk_sender: result=fail url=%s code=%d error=%v response=%s", url, code, err, string(res)) + logger.Errorf("dingtalk_sender: result=fail url=%s code=%d error=%v response=%s", ur, code, err, string(res)) } else { - logger.Infof("dingtalk_sender: result=succ url=%s code=%d response=%s", url, code, string(res)) + logger.Infof("dingtalk_sender: result=succ url=%s code=%d response=%s", ur, code, string(res)) } } }