-
Notifications
You must be signed in to change notification settings - Fork 152
/
client.go
106 lines (70 loc) · 3.27 KB
/
client.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package templateMessage
import (
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/power"
response2 "github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/templateMessage/request"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/templateMessage/response"
)
const API_TEMPLATE_MESSAGE_SEND string = "cgi-bin/message/template/send"
type Client struct {
*kernel.BaseClient
Message *object.HashMap
Required []string
}
// 设置所属行业
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
func (comp *Client) SetIndustry(industryOne string, industryTwo string, optional *power.HashMap) (*response.ResponseTemplateIndustry, error) {
result := &response.ResponseTemplateIndustry{}
params := &object.HashMap{
"industry_id1": industryOne,
"industry_id2": industryTwo,
}
_, err := comp.HttpPostJson("cgi-bin/template/api_set_industry", params, nil, nil, result)
return result, err
}
// 获取设置的行业信息
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
func (comp *Client) GetIndustry() (*response.ResponseTemplateIndustry, error) {
result := &response.ResponseTemplateIndustry{}
_, err := comp.HttpPostJson("cgi-bin/template/get_industry", nil, nil, nil, result)
return result, err
}
// 获得模板ID
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
func (comp *Client) AddTemplate(industryOne string) (*response.ResponseTemplate, error) {
result := &response.ResponseTemplate{}
params := &object.HashMap{
"template_id_short": industryOne,
}
_, err := comp.HttpPostJson("cgi-bin/template/api_add_template", params, nil, nil, result)
return result, err
}
// 获取模板列表
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
func (comp *Client) GetPrivateTemplates() (*response.ResponseTemplateGetPrivate, error) {
result := &response.ResponseTemplateGetPrivate{}
_, err := comp.HttpPostJson("cgi-bin/template/get_all_private_template", nil, nil, nil, result)
return result, err
}
// 删除模板
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
func (comp *Client) DeletePrivateTemplate(templateID string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"template_id": templateID,
}
_, err := comp.HttpPostJson("cgi-bin/template/del_private_template", params, nil, nil, result)
return result, err
}
func (comp *Client) Send(message *request.RequestTemlateMessage) (*response.ResponseTemplateSend, error) {
result := &response.ResponseTemplateSend{}
_, err := comp.HttpPostJson(API_TEMPLATE_MESSAGE_SEND, message, nil, nil, result)
return result, err
}
func (comp *Client) SendSubscription(message *request.RequestTemlateMessageSubscribe) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
_, err := comp.HttpPostJson("cgi-bin/message/template/subscribe", message, nil, nil, result)
return result, err
}