forked from chanxuehong/wechat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.go
337 lines (307 loc) · 8.19 KB
/
info.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
package wxa
import (
"fmt"
"net/url"
"github.com/charsunny/wechat/mp/core"
)
// 获取支付的unionid信息
func GetPaidUnionId(clt *core.Client, openid string, transId string) (unionid string, err error) {
incompleteURL := fmt.Sprintf("https://api.weixin.qq.com/wxa/getpaidunionid?openid=%s&transaction_id=%s&access_token=", url.QueryEscape(openid), transId)
var result struct {
core.Error
UnionId string `json:"unionid"`
}
if err = clt.GetJSON(incompleteURL, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
unionid = result.UnionId
return
}
// 获取帐号基本信息
func GetBaseInfo(clt *core.Client) (info *WxaInfo, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo?access_token="
var result struct {
core.Error
WxaInfo
}
if err = clt.GetJSON(incompleteURL, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
info = &result.WxaInfo
return
}
// 小程序改名
func SetNickName(clt *core.Client, info *WxaNameRequestInfo) (wording string, audit_id int, err error) {
const incompleteURL = "https://api.weixin.qq.com/wxa/setnickname?access_token="
var result struct {
core.Error
Wording string `json:"wording"` // 材料说明
AuditId int `json:"audit_id"` // 审核单id 若接口未返回audit_id,说明名称已直接设置成功,无需审核;若返回audit_id则名称正在审核中
}
if err = clt.PostJSON(incompleteURL, info, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
wording = result.Wording
audit_id = result.AuditId
return
}
// 小程序改名
func QuerySetNickStatus(clt *core.Client, audit_id int) (info *WxaNameResultInfo, err error) {
const incompleteURL = "https://api.weixin.qq.com/wxa/api_wxa_querynickname?access_token="
var request = struct {
AuditId int `json:"audit_id"`
}{
AuditId:audit_id,
}
var result struct {
core.Error
WxaNameResultInfo
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
info = &result.WxaNameResultInfo
return
}
// 微信认证名称检测
func CheckNickName(clt *core.Client, nickname string) (wording string, hit bool, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/wxverify/checkwxverifynickname?access_token="
var request = struct {
NickName string `json:"nick_name"`
}{
NickName:nickname,
}
var result struct {
core.Error
Wording string `json:"wording"` // 命中关键字的说明描述(给用户看的)
HitCondition bool `json:"hit_condition"` // 是否命中关键字策略。若命中,可以选填关键字材料
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
wording = result.Wording
hit = result.HitCondition
return
}
// 修改小程序头像
func ModifyHeadImage(clt *core.Client, head_img_media_id string) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/account/modifyheadimage?access_token="
var request = struct {
HeadImgMediaId string `json:"head_img_media_id"`
X1 float64 `json:"x1"`
X2 float64 `json:"x2"`
Y1 float64 `json:"y1"`
Y2 float64 `json:"y2"`
}{
HeadImgMediaId:head_img_media_id,
X1: 0,
X2: 1,
Y1: 0,
Y2: 1,
}
var result struct {
core.Error
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
return
}
// 修改小程序功能介绍
func ModifySignature(clt *core.Client, signature string) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/account/modifysignature?access_token="
var request = struct {
Signature string `json:"signature"`
}{
Signature:signature,
}
var result struct {
core.Error
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
return
}
// TODO: 换绑小程序管理员接口
// 获取所有可设置类目接口
func GetAllCategories(clt *core.Client) (list []*WxaCategory, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/wxopen/getallcategories?access_token="
var result struct {
core.Error
List struct{
List []*WxaCategory `json:"categories"`
} `json:"categories_list"`
}
if err = clt.GetJSON(incompleteURL, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
list = result.List.List
return
}
// 添加类目
func AddCategory(clt *core.Client, list [] *WxaActionCateInfo) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/wxopen/addcategory?access_token="
var request = struct {
List [] *WxaActionCateInfo `json:"categories"`
}{
List:list,
}
var result struct {
core.Error
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
return
}
// 删除类目
func DeleteCategory(clt *core.Client, first, second int) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/wxopen/deletecategory?access_token="
var request = struct {
First int `json:"first"`
Second int `json:"second"`
}{
First:first,
Second:second,
}
var result struct {
core.Error
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
return
}
// 获取商户的设置类目
func GetAccountCategory(clt *core.Client) (item *CategoryItem, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/wxopen/getcategory?access_token="
var result struct {
core.Error
*CategoryItem
}
if err = clt.GetJSON(incompleteURL, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
item = result.CategoryItem
return
}
// 添加类目
func ModifyCategory(clt *core.Client, item *WxaActionCateInfo) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/wxopen/modifycategory?access_token="
var result struct {
core.Error
}
if err = clt.PostJSON(incompleteURL, item, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
return
}
// 修改域名
func ModifyDomain(clt *core.Client, action string, requestdomain , wsrequestdomain, uploaddoamin, downloaddomain []string) ( requst, ws, upload, download []string, err error) {
const incompleteURL = "https://api.weixin.qq.com/wxa/modify_domain?access_token="
var req = struct{
Action string `json:"action"`
RequestDomain []string `json:"requestdomain"`
WsrequestDomain []string `json:"wsrequestdomain"`
UploadDomain []string `json:"uploaddomain"`
DownloadDomain []string `json:"downloaddomain"`
} {
Action:action,
RequestDomain:requestdomain,
WsrequestDomain:wsrequestdomain,
UploadDomain:uploaddoamin,
DownloadDomain:downloaddomain,
}
var result struct {
core.Error
RequestDomain []string `json:"requestdomain"`
WsrequestDomain []string `json:"wsrequestdomain"`
UploadDomain []string `json:"uploaddomain"`
DownloadDomain []string `json:"downloaddomain"`
}
if err = clt.PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
requst = result.RequestDomain
ws = result.WsrequestDomain
upload = result.UploadDomain
download = result.DownloadDomain
return
}
// 设置webviewdomain
func SetWebviewDomain(clt *core.Client, action string, domains []string) (list []string, err error) {
const incompleteURL = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token="
var req = struct{
Action string `json:"action"`
Domains []string `json:"webviewdomain"`
} {
Action:action,
Domains: domains,
}
var result struct {
core.Error
Domains []string `json:"webviewdomain"`
}
if err = clt.PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
list = result.Domains
return
}