-
Notifications
You must be signed in to change notification settings - Fork 146
/
client.go
85 lines (66 loc) · 2.42 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
package batchJobs
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/power"
"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/90980
func (comp *Client) SyncUser(ctx context.Context, mediaID string, toInvite bool, callback *power.StringMap) (*response.ResponseUserBatchJobs, error) {
result := &response.ResponseUserBatchJobs{}
options := &object.HashMap{
"media_id": mediaID,
"to_invite": toInvite,
"callbacks": callback,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/batch/syncuser", options, nil, nil, result)
return result, err
}
// 全量覆盖成员
// https://developer.work.weixin.qq.com/document/path/90981
func (comp *Client) ReplaceUser(ctx context.Context, mediaID string, toInvite bool, callback *power.StringMap) (*response.ResponseUserBatchJobs, error) {
result := &response.ResponseUserBatchJobs{}
options := &object.HashMap{
"media_id": mediaID,
"to_invite": toInvite,
"callbacks": callback,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/batch/replaceuser", options, nil, nil, result)
return result, err
}
// 全量覆盖部门
// https://developer.work.weixin.qq.com/document/path/90982
func (comp *Client) ReplaceParty(ctx context.Context, mediaID string, toInvite bool, callback *power.StringMap) (*response.ResponseUserBatchJobs, error) {
result := &response.ResponseUserBatchJobs{}
options := &object.HashMap{
"media_id": mediaID,
"to_invite": toInvite,
"callbacks": callback,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/batch/replaceparty", options, nil, nil, result)
return result, err
}
// 获取异步任务结果
// https://developer.work.weixin.qq.com/document/path/90983
func (comp *Client) GetBatchResult(ctx context.Context, jobID string) (*response.ResponseUserBatchGetResult, error) {
result := &response.ResponseUserBatchGetResult{}
params := &object.StringMap{
"jobid": jobID,
}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/batch/getresult", params, nil, result)
return result, err
}