-
Notifications
You must be signed in to change notification settings - Fork 174
/
client.go
237 lines (169 loc) · 7.04 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
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
package user
import (
"context"
"errors"
"fmt"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/power"
response2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response"
response3 "github.com/ArtisanCloud/PowerWeChat/v3/src/work/user/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/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://developer.work.weixin.qq.com/document/path/90195
func (comp *Client) Create(ctx context.Context, data *response3.RequestUserDetail) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/create", data, nil, nil, result)
return result, err
}
// 更新成员
// https://developer.work.weixin.qq.com/document/path/90197
func (comp *Client) Update(ctx context.Context, data *response3.RequestUserDetail) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/update", data, nil, nil, result)
return result, err
}
// 删除成员
// https://developer.work.weixin.qq.com/document/path/90198
func (comp *Client) Delete(ctx context.Context, userID string) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/user/delete", &object.StringMap{
"userid": userID,
}, nil, result)
return result, err
}
// 批量删除成员
// https://developer.work.weixin.qq.com/document/path/90335
func (comp *Client) BatchDelete(ctx context.Context, userIDs []string) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/batchdelete", &object.HashMap{
"useridlist": userIDs,
}, nil, nil, result)
return result, err
}
// 获取成员
// https://developer.work.weixin.qq.com/document/path/90196
func (comp *Client) Get(ctx context.Context, userID string) (*response.ResponseGetUserDetail, error) {
result := &response.ResponseGetUserDetail{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/user/get", &object.StringMap{
"userid": userID,
}, nil, result)
return result, err
}
// 获取部门的成员
// https://developer.work.weixin.qq.com/document/path/90200
func (comp *Client) GetDepartmentUsers(ctx context.Context, departmentID int, fetchChild int) (*response.ResponseGetSimpleUserList, error) {
result := &response.ResponseGetSimpleUserList{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/user/simplelist", &object.StringMap{
"department_id": fmt.Sprintf("%d", departmentID),
"fetch_child": fmt.Sprintf("%d", fetchChild),
}, nil, result)
return result, err
}
// 获取部门成员详情
// https://developer.work.weixin.qq.com/document/path/90201
func (comp *Client) GetDetailedDepartmentUsers(ctx context.Context, departmentID int, fetchChild int) (*response.ResponseGetUserList, error) {
result := &response.ResponseGetUserList{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/user/list", &object.StringMap{
"department_id": fmt.Sprintf("%d", departmentID),
"fetch_child": fmt.Sprintf("%d", fetchChild),
}, nil, result)
return result, err
}
// userid与openid互换
// https://developer.work.weixin.qq.com/document/path/90202
func (comp *Client) UserIdToOpenID(ctx context.Context, userID string) (*response.ResponseUserIDToOpenID, error) {
result := &response.ResponseUserIDToOpenID{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/convert_to_openid", &object.StringMap{
"userid": userID,
}, nil, nil, result)
return result, err
}
// 获取成员ID列表
// https://developer.work.weixin.qq.com/document/path/96067
func (comp *Client) ListID(ctx context.Context, cursor string, limit int) (*response.ResponseListID, error) {
result := &response.ResponseListID{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/list_id", &object.HashMap{
"cursor": cursor,
"limit": limit,
}, nil, nil, result)
return result, err
}
// openid转userid
// https://developer.work.weixin.qq.com/document/path/90202
func (comp *Client) OpenIDToUserID(ctx context.Context, openID string) (*response.ResponseOpenIDToUserID, error) {
result := &response.ResponseOpenIDToUserID{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/convert_to_userid", &object.StringMap{
"openid": openID,
}, nil, nil, result)
return result, err
}
// 手机号获取userid
// https://developer.work.weixin.qq.com/document/path/95402
func (comp *Client) MobileToUserID(ctx context.Context, mobile string) (*response.ResponseMobileToUserID, error) {
result := &response.ResponseMobileToUserID{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/getuserid", &object.StringMap{
"mobile": mobile,
}, nil, nil, result)
return result, err
}
// 邮箱获取userid
// https://developer.work.weixin.qq.com/document/path/95895
func (comp *Client) EmailToUserID(ctx context.Context, email string, emailType int) (*response.ResponseConvertToUserID, error) {
result := &response.ResponseConvertToUserID{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/get_userid_by_email", &object.HashMap{
"email": email,
"email_type": emailType,
}, nil, nil, result)
return result, err
}
// 二次验证
// https://developer.work.weixin.qq.com/document/path/90203
func (comp *Client) Accept(ctx context.Context, userID string) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/user/authsucc", &object.StringMap{
"userid": userID,
}, nil, result)
return result, err
}
// 邀请成员
// https://developer.work.weixin.qq.com/document/path/90975
func (comp *Client) Invite(ctx context.Context, params *power.HashMap) (*response.ResponseMobileToUserID, error) {
result := &response.ResponseMobileToUserID{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/batch/invite", params, nil, nil, result)
return result, err
}
// 获取加入企业二维码
// https://developer.work.weixin.qq.com/document/path/91714
func (comp *Client) GetJoinQrCode(ctx context.Context, sizeType int) (*response.ResponseJoinCode, error) {
if sizeType < 1 || sizeType > 4 {
return nil, errors.New("The sizeType must be 1, 2, 3, 4.")
}
result := &response.ResponseJoinCode{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/corp/get_join_qrcode", &object.StringMap{
"size_type": fmt.Sprintf("%d", sizeType),
}, nil, result)
return result, err
}
// 获取企业活跃成员数
// https://developer.work.weixin.qq.com/document/path/92714
func (comp *Client) GetActiveStat(ctx context.Context, date string) (*response.ResponseUserActiveCount, error) {
result := &response.ResponseUserActiveCount{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/user/get_active_stat", &object.HashMap{
"date": date,
}, nil, nil, result)
return result, err
}