This repository was archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwechatwork.go
66 lines (57 loc) · 1.85 KB
/
wechatwork.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package grobot
// WechatWorkTextMessage 企业微信机器人文本消息体
type WechatWorkTextMessage struct {
Content string `json:"content"`
}
// WechatWorkMarkdownMessage 企业微信机器人 Markdown 消息体
type WechatWorkMarkdownMessage struct {
Title string `json:"title"`
Text string `json:"text"`
}
// newWechatWorkRobot 初始化企业微信机器人
// @see https://work.weixin.qq.com/api/doc#90000/90136/91770
func newWechatWorkRobot(token string) *Robot {
return &Robot{
Webhook: stringBuilder("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=", token),
ParseTextMessage: parseDingTalkTextMessage,
ParseMarkdownMessage: parseWechatWorkMarkdownMessage,
}
}
// 请求参数示例
// {
// "msgtype": "text",
// "text": {
// "content": "广州今日天气:29度,大部分多云,降雨概率:60%",
// "mentioned_list":["wangqing","@all"],
// "mentioned_mobile_list":["13800001111","@all"]
// }
// }
func parseWechatWorkTextMessage(text string) map[string]interface{} {
msg := WechatWorkTextMessage{
Content: text,
}
body := make(map[string]interface{})
body["msgtype"] = "text"
body["text"] = msg
return body
}
// 请求参数示例
// {
// "msgtype": "markdown",
// "markdown": {
// "content": "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n
// >类型:<font color=\"comment\">用户反馈</font> \n
// >普通用户反馈:<font color=\"comment\">117例</font> \n
// >VIP用户反馈:<font color=\"comment\">15例</font>"
// }
// }
func parseWechatWorkMarkdownMessage(title string, text string) map[string]interface{} {
msg := WechatWorkMarkdownMessage{
Title: title,
Text: text,
}
body := make(map[string]interface{})
body["msgtype"] = "markdown"
body["markdown"] = msg
return body
}