forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe.go
172 lines (147 loc) · 4.48 KB
/
subscribe.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package offia
import (
"encoding/json"
"strconv"
"github.com/liniu/gochat/urls"
"github.com/liniu/gochat/wx"
)
type ParamsSubscribeTemplAdd struct {
TID string `json:"tid"`
KidList []int `json:"kidList"`
SceneDesc string `json:"sceneDesc"`
}
type ResultSubscribeTemplAdd struct {
PriTmplID string `json:"priTmplId"`
}
// AddSubscribeTemplate 订阅通知 - 选用模板
func AddSubscribeTemplate(params *ParamsSubscribeTemplAdd, result *ResultSubscribeTemplAdd) wx.Action {
return wx.NewPostAction(urls.OffiaSubscribeAddTemplate,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsSubscribeTemplDelete struct {
PriTmplID string `json:"priTmplId"`
}
// DeleteSubscribeTemplate 订阅通知 - 删除模板
func DeleteSubscribeTemplate(priTmplID string) wx.Action {
params := &ParamsSubscribeTemplDelete{
PriTmplID: priTmplID,
}
return wx.NewPostAction(urls.OffiaSubscribeDeleteTemplate,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
)
}
type SubscribeCategory struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
type ResultSubscribeCategory struct {
Data []*SubscribeCategory `json:"data"`
}
// GetSubscribeCategory 订阅通知 - 获取公众号类目
func GetSubscribeCategory(result *ResultSubscribeCategory) wx.Action {
return wx.NewGetAction(urls.OffiaSubscribeGetCategory,
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type PubTemplKeywords struct {
KID int64 `json:"kid"`
Name string `json:"name"`
Example string `json:"example"`
Rule string `json:"rule"`
}
type ResultPubTemplKeywords struct {
Data []*PubTemplKeywords `json:"data"`
}
// GetPubTemplateKeywords 订阅通知 - 获取模板中的关键词
func GetPubTemplateKeywords(tid string, result *ResultPubTemplKeywords) wx.Action {
return wx.NewGetAction(urls.OffiaSubscribeGetPubTemplateKeywords,
wx.WithQuery("tid", tid),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type PubTemplTitle struct {
TID int64 `json:"tid"`
Title string `json:"title"`
Type int `json:"type"`
CategoryID string `json:"categoryId"`
}
type ResultPubTemplTitles struct {
Count int `json:"count"`
Data []*PubTemplTitle `json:"data"`
}
// GetPubTemplateTitles 订阅通知 - 获取类目下的公共模板
func GetPubTemplateTitles(ids string, start, limit int, result *ResultPubTemplTitles) wx.Action {
return wx.NewGetAction(urls.OffiaSubscribeGetPubTemplateTitles,
wx.WithQuery("ids", ids),
wx.WithQuery("start", strconv.Itoa(start)),
wx.WithQuery("limit", strconv.Itoa(limit)),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ResultSubscribeTemplList struct {
Data []*SubscribeTemplInfo `json:"data"`
}
type SubscribeTemplInfo struct {
PriTmplID string `json:"priTmplId"`
Title string `json:"title"`
Content string `json:"content"`
Example string `json:"example"`
Type int `json:"type"`
}
// ListSubscribeTemplate 订阅通知 - 获取私有模板列表
func ListSubscribeTemplate(result *ResultSubscribeTemplList) wx.Action {
return wx.NewGetAction(urls.OffiaSubscribeGetTemplateList,
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type SubscribeMsg struct {
ToUser string `json:"touser"`
TemplateID string `json:"template_id"`
Page string `json:"page,omitempty"`
Minip *MsgMinip `json:"miniprogram,omitempty"`
Data MsgTemplData `json:"data"`
}
// SendSubscribePageMsg 订阅通知 - 发送订阅通知(网页跳转)
func SendSubscribePageMsg(templateID, openid, page string, data MsgTemplData) wx.Action {
msg := &SubscribeMsg{
ToUser: openid,
TemplateID: templateID,
Page: page,
Data: data,
}
return wx.NewPostAction(urls.OffiaSubscribeMsgBizSend,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(msg)
}),
)
}
// SendSubscribeMinipMsg 订阅通知 - 发送订阅通知(小程序跳转)
func SendSubscribeMinipMsg(templateID, openid string, minip *MsgMinip, data MsgTemplData) wx.Action {
msg := &SubscribeMsg{
ToUser: openid,
TemplateID: templateID,
Minip: minip,
Data: data,
}
return wx.NewPostAction(urls.OffiaSubscribeMsgBizSend,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(msg)
}),
)
}