-
Notifications
You must be signed in to change notification settings - Fork 1
/
messageSender.go
53 lines (45 loc) · 897 Bytes
/
messageSender.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
package mp
import (
"encoding/json"
"fmt"
"github.com/bysir-zl/bygo/wx_open/util"
)
type Message struct {
Touser string `json:"touser"`
Msgtype string `json:"msgtype"`
}
type MessageText struct {
Message
Text struct {
Content string `json:"content"`
} `json:"text"`
}
type Response struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
// 客服接口-发消息
func SendMessageText(accessToken string, toUser, context string) (err error) {
m := MessageText{
Text: struct{ Content string `json:"content"` }{Content: context},
Message: Message{
Touser: toUser,
Msgtype: "text",
},
}
bs, _ := json.Marshal(m)
rsp, err := util.Post(URLMessageSend+accessToken, bs)
if err != nil {
return
}
r := Response{}
err = json.Unmarshal(rsp, &r)
if err != nil {
return
}
if r.ErrCode != 0 {
err = fmt.Errorf("%+v", r)
return
}
return
}