-
Notifications
You must be signed in to change notification settings - Fork 157
/
client.go
145 lines (101 loc) · 4.3 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
137
138
139
140
141
142
143
144
145
package user
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/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/user/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/Get_users_basic_information_UnionID.html#UinonId
func (comp *Client) Get(ctx context.Context, openID string, lang string) (*response.ResponseGetUserInfo, error) {
result := &response.ResponseGetUserInfo{}
params := &object.StringMap{
"openid": openID,
"lang": lang,
}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/user/info", params, nil, result)
return result, err
}
// 批量获取用户基本信息
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/Get_users_basic_information_UnionID.html#UinonId
func (comp *Client) BatchGet(ctx context.Context, data *request.RequestBatchGetUserInfo) (*response.ResponseBatchGetUserInfo, error) {
result := &response.ResponseBatchGetUserInfo{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/info/batchget", data, nil, nil, result)
return result, err
}
// 获取用户列表
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/Getting_a_User_List.html
func (comp *Client) List(ctx context.Context, nextOpenID string) (*response.ResponseGetUserList, error) {
result := &response.ResponseGetUserList{}
params := &object.StringMap{
"next_openid": nextOpenID,
}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/user/get", params, nil, result)
return result, err
}
// 设置用户备注名
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/Configuring_user_notes.html
func (comp *Client) Remark(ctx context.Context, openID string, remark string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.StringMap{
"openid": openID,
"remark": remark,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/info/updateremark", params, nil, nil, result)
return result, err
}
// 黑名单管理
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/Manage_blacklist.html
func (comp *Client) Blacklist(ctx context.Context, beginOpenID string) (*response.ResponseBlacklist, error) {
result := &response.ResponseBlacklist{}
params := &object.StringMap{
"begin_openid": beginOpenID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/members/getblacklist", params, nil, nil, result)
return result, err
}
// 拉黑用户
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/Manage_blacklist.html
func (comp *Client) Block(ctx context.Context, openIDList []string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"openid_list": openIDList,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/members/batchblacklist", params, nil, nil, result)
return result, err
}
// 取消拉黑用户
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/Manage_blacklist.html
func (comp *Client) Unblock(ctx context.Context, openIDList []string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"openid_list": openIDList,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tags/members/batchunblacklist", params, nil, nil, result)
return result, err
}
// 帐号迁移 转换 openid
// https://developers.weixin.qq.com/doc/offiaccount/User_Management/Getting_a_User_List.html
func (comp *Client) ChangeOpenID(ctx context.Context, fromAppID string, openIDList []string) (*response.ResponseChangeOpenID, error) {
result := &response.ResponseChangeOpenID{}
params := &object.HashMap{
"from_appid": fromAppID,
"openid_list": openIDList,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/changeopenid", params, nil, nil, result)
return result, err
}