-
Notifications
You must be signed in to change notification settings - Fork 156
/
client.go
136 lines (107 loc) · 4.15 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
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
package tag
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
response2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/user/tag/response"
)
type Client struct {
BaseClient *kernel.BaseClient
}
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 创建标签
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) Create(ctx context.Context, name string) (*response.ResponseTagGet, error) {
result := &response.ResponseTagGet{}
params := &object.HashMap{
"tag": &object.HashMap{
"name": name,
},
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/create", params, nil, nil, result)
return result, err
}
// 获取公众号已创建的标签
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) List(ctx context.Context) (*response.ResponseTagGetList, error) {
result := &response.ResponseTagGetList{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/tags/get", nil, nil, result)
return result, err
}
// 用户标签管理
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) Update(ctx context.Context, tagID string, name string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"tag": &object.HashMap{
"id": tagID,
"name": name,
},
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/update", params, nil, nil, result)
return result, err
}
// 删除标签
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) Delete(ctx context.Context, tagID string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"tag": &object.HashMap{
"id": tagID,
},
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/delete", params, nil, nil, result)
return result, err
}
// 获取用户身上的标签列表
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) UserTags(ctx context.Context, openID string) (*response.ResponseUserTags, error) {
result := &response.ResponseUserTags{}
params := &object.HashMap{
"openid": openID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/getidlist", params, nil, nil, result)
return result, err
}
// 获取标签下粉丝列表
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) UsersOfTag(ctx context.Context, tagID string, nextOpenID string) (*response.ResponseUserOfTag, error) {
result := &response.ResponseUserOfTag{}
params := &object.HashMap{
"tagid": tagID,
"next_openid": nextOpenID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/tag/get", params, nil, nil, result)
return result, err
}
// 批量为用户打标签
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) TagUsers(ctx context.Context, openIDs []string, tagID int) (*response.ResponseTagUsers, error) {
result := &response.ResponseTagUsers{}
params := &object.HashMap{
"openid_list": openIDs,
"tagid": tagID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/members/batchtagging", params, nil, nil, result)
return result, err
}
// 批量为用户取消标签
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/User_Tag_Management.html
func (comp *Client) UntagUsers(ctx context.Context, openIDs []string, tagID string) (*response.ResponseUntagUsers, error) {
result := &response.ResponseUntagUsers{}
params := &object.HashMap{
"openid_list": openIDs,
"tagid": tagID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/members/batchuntagging", params, nil, nil, result)
return result, err
}