feat: send recode adjust
This commit is contained in:
@@ -62,6 +62,26 @@ func (t *Dtalk) SendMessageText(text string, at ...string) ([]byte, error) {
|
||||
"content": text,
|
||||
},
|
||||
}
|
||||
|
||||
// 添加@功能
|
||||
if len(at) > 0 {
|
||||
atMobiles := []string{}
|
||||
isAtAll := false
|
||||
|
||||
for _, mobile := range at {
|
||||
if mobile == "all" || mobile == "@all" {
|
||||
isAtAll = true
|
||||
} else {
|
||||
atMobiles = append(atMobiles, mobile)
|
||||
}
|
||||
}
|
||||
|
||||
msg["at"] = map[string]interface{}{
|
||||
"atMobiles": atMobiles,
|
||||
"isAtAll": isAtAll,
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := t.Request(msg)
|
||||
return resp, err
|
||||
}
|
||||
@@ -74,6 +94,26 @@ func (t *Dtalk) SendMessageMarkdown(title, text string, at ...string) ([]byte, e
|
||||
"text": text,
|
||||
},
|
||||
}
|
||||
|
||||
// 添加@功能
|
||||
if len(at) > 0 {
|
||||
atMobiles := []string{}
|
||||
isAtAll := false
|
||||
|
||||
for _, mobile := range at {
|
||||
if mobile == "all" || mobile == "@all" {
|
||||
isAtAll = true
|
||||
} else {
|
||||
atMobiles = append(atMobiles, mobile)
|
||||
}
|
||||
}
|
||||
|
||||
msg["at"] = map[string]interface{}{
|
||||
"atMobiles": atMobiles,
|
||||
"isAtAll": isAtAll,
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := t.Request(msg)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
+36
-3
@@ -53,10 +53,40 @@ func (t *QyWeiXin) Request(msg interface{}) ([]byte, error) {
|
||||
func (t *QyWeiXin) SendMessageText(text string, at ...string) ([]byte, error) {
|
||||
msg := map[string]interface{}{
|
||||
"msgtype": "text",
|
||||
"text": map[string]string{
|
||||
"text": map[string]interface{}{
|
||||
"content": text,
|
||||
},
|
||||
}
|
||||
|
||||
// 添加@功能
|
||||
// 企业微信支持两种@方式:
|
||||
// 1. mentioned_list: userid列表或"@all"
|
||||
// 2. mentioned_mobile_list: 手机号列表
|
||||
if len(at) > 0 {
|
||||
mentionedList := []string{}
|
||||
mentionedMobileList := []string{}
|
||||
|
||||
for _, item := range at {
|
||||
if item == "@all" || item == "all" {
|
||||
mentionedList = append(mentionedList, "@all")
|
||||
} else if len(item) == 11 && item[0] == '1' {
|
||||
// 判断是否为手机号(简单判断:11位且以1开头)
|
||||
mentionedMobileList = append(mentionedMobileList, item)
|
||||
} else {
|
||||
// 否则当作userid处理
|
||||
mentionedList = append(mentionedList, item)
|
||||
}
|
||||
}
|
||||
|
||||
textContent := msg["text"].(map[string]interface{})
|
||||
if len(mentionedList) > 0 {
|
||||
textContent["mentioned_list"] = mentionedList
|
||||
}
|
||||
if len(mentionedMobileList) > 0 {
|
||||
textContent["mentioned_mobile_list"] = mentionedMobileList
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := t.Request(msg)
|
||||
return resp, err
|
||||
}
|
||||
@@ -64,11 +94,14 @@ func (t *QyWeiXin) SendMessageText(text string, at ...string) ([]byte, error) {
|
||||
func (t *QyWeiXin) SendMessageMarkdown(title, text string, at ...string) ([]byte, error) {
|
||||
msg := map[string]interface{}{
|
||||
"msgtype": "markdown",
|
||||
"markdown": map[string]string{
|
||||
"title": title,
|
||||
"markdown": map[string]interface{}{
|
||||
"content": text,
|
||||
},
|
||||
}
|
||||
|
||||
// 企业微信Markdown消息不支持@功能,但可以在内容中手动添加
|
||||
// 如果需要@功能,建议使用text类型
|
||||
|
||||
resp, err := t.Request(msg)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user