-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwecom.go
67 lines (57 loc) · 1.41 KB
/
wecom.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
67
package msgpush
import (
"github.com/imroc/req"
)
const wecomBase = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key="
type weComSendTextContent struct {
Msgtype string `json:"msgtype"`
Text struct {
Content string `json:"content"`
MentionedList []string `json:"mentioned_list"`
MentionedMobileList []string `json:"mentioned_mobile_list"`
} `json:"text"`
}
type weComSendMDContent struct {
Msgtype string `json:"msgtype"`
Markdown struct {
Content string `json:"content"`
} `json:"markdown"`
}
type WeCom struct {
Token string
ReqUrl string
}
//NewWeCom
func NewWeCom(token string) *WeCom {
return &WeCom{Token: token, ReqUrl: wecomBase + token}
}
func (w *WeCom) Send(content string) error {
return w.SendMd(content)
}
func (w *WeCom) SendMd(content string) error {
_, err := req.Post(w.ReqUrl, req.BodyJSON(&weComSendMDContent{
Msgtype: "markdown",
Markdown: struct {
Content string `json:"content"`
}{
Content: content,
},
}))
return err
}
func (w *WeCom) SendText(content string) error {
_, err := req.Post(w.ReqUrl, req.BodyJSON(&weComSendTextContent{
Msgtype: "text",
Text: struct {
Content string `json:"content"`
MentionedList []string `json:"mentioned_list"`
MentionedMobileList []string `json:"mentioned_mobile_list"`
}{
Content: content,
},
}))
return err
}
func (w *WeCom) String() string {
return "wecom"
}