parent
5333fb8eab
commit
9ba1c2c32d
|
@ -1,6 +1,7 @@
|
||||||
package sender
|
package sender
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -38,24 +39,38 @@ func SendDingtalk(message DingtalkMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(message.Tokens); i++ {
|
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{
|
body := dingtalk{
|
||||||
Msgtype: "markdown",
|
Msgtype: "markdown",
|
||||||
Markdown: dingtalkMarkdown{
|
Markdown: dingtalkMarkdown{
|
||||||
Title: message.Title,
|
Title: message.Title,
|
||||||
Text: message.Text + " " + strings.Join(ats, " "),
|
Text: message.Text,
|
||||||
},
|
|
||||||
At: dingtalkAt{
|
|
||||||
AtMobiles: message.AtMobiles,
|
|
||||||
IsAtAll: false,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
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 {
|
} 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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue