-
Notifications
You must be signed in to change notification settings - Fork 157
/
client.go
114 lines (85 loc) · 3.34 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
package tag
import (
"context"
"fmt"
"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/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/90210
func (comp *Client) Create(ctx context.Context, tagName string, tagID int64) (*response.ResponseTagCreate, error) {
result := &response.ResponseTagCreate{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tag/create", &object.HashMap{
"tagname": tagName,
"tagid": tagID,
}, nil, nil, result)
return result, err
}
// 更新标签名字
// https://developer.work.weixin.qq.com/document/path/90211
func (comp *Client) Update(ctx context.Context, tagName string, tagID int64) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/tag/update", &object.HashMap{
"tagname": tagName,
"tagid": tagID,
}, nil, nil, result)
return result, err
}
// 删除标签
// https://developer.work.weixin.qq.com/document/path/90212
func (comp *Client) Delete(ctx context.Context, tagID int64) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/tag/delete", &object.StringMap{
"tagid": fmt.Sprintf("%d", tagID),
}, nil, result)
return result, err
}
// 获取标签成员
// https://developer.work.weixin.qq.com/document/path/90832
func (comp *Client) Get(ctx context.Context, tagID int64) (*response.ResponseTagDetail, error) {
result := &response.ResponseTagDetail{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/tag/get", &object.StringMap{
"tagid": fmt.Sprintf("%d", tagID),
}, nil, result)
return result, err
}
// 获取标签成员
// https://developer.work.weixin.qq.com/document/path/90833
func (comp *Client) TagUsers(ctx context.Context, tagID int64, userList []string) (*response.ResponseTagCreateUser, error) {
return comp.TagOrUntagUsers(ctx, "cgi-bin/tag/addtagusers", tagID, userList, []string{})
}
// 增加标签成员
// https://developer.work.weixin.qq.com/document/path/90833
func (comp *Client) TagDepartments(ctx context.Context, tagID int64, partyList []string) (*response.ResponseTagCreateUser, error) {
return comp.TagOrUntagUsers(ctx, "cgi-bin/tag/addtagusers", tagID, []string{}, partyList)
}
func (comp *Client) TagOrUntagUsers(ctx context.Context, endpoint string, tagID int64, userList []string, partyList []string) (*response.ResponseTagCreateUser, error) {
result := &response.ResponseTagCreateUser{}
_, err := comp.BaseClient.HttpPostJson(ctx, endpoint, &object.HashMap{
"tagid": tagID,
"userlist": userList,
"partylist": partyList,
}, nil, nil, result)
return result, err
}
// 获取标签列表
// https://developer.work.weixin.qq.com/document/path/90216
func (comp *Client) List(ctx context.Context) (*response.ResponseTagList, error) {
result := &response.ResponseTagList{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/tag/list", nil, nil, result)
return result, err
}