-
Notifications
You must be signed in to change notification settings - Fork 156
/
client.go
151 lines (111 loc) · 5.02 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
package externalContact
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerSocialite/v3/src/response/weCom"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
response2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response"
response3 "github.com/ArtisanCloud/PowerWeChat/v3/src/work/externalContact/groupChat/response"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/externalContact/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/externalContact/response"
"strconv"
)
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/92571
func (comp *Client) GetFollowUsers(ctx context.Context) (*response.ResponseGetFollowUserList, error) {
result := &response.ResponseGetFollowUserList{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/externalcontact/get_follow_user_list", nil, nil, result)
return result, err
}
// 获取外部联系人列表.
// https://developer.work.weixin.qq.com/document/path/92113
func (comp *Client) List(ctx context.Context, userID string) (*response.ResponseGetList, error) {
result := &response.ResponseGetList{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/externalcontact/list", &object.StringMap{
"userid": userID,
}, nil, result)
return result, err
}
// 获取外部联系人详情.
// https://developer.work.weixin.qq.com/document/path/92114
func (comp *Client) Get(ctx context.Context, externalUserID string, cursor string) (*weCom.ResponseGetExternalContact, error) {
result := &weCom.ResponseGetExternalContact{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/externalcontact/get", &object.StringMap{
"external_userid": externalUserID,
"cursor": cursor,
}, nil, result)
return result, err
}
// 批量获取客户详情.
// https://developer.work.weixin.qq.com/document/path/92994
func (comp *Client) BatchGet(ctx context.Context, userID []string, cursor string, limit int) (*response.ResponseBatchGetByUser, error) {
result := &response.ResponseBatchGetByUser{}
options := &object.HashMap{
"userid_list": userID,
"cursor": cursor,
"limit": limit,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/externalcontact/batch/get_by_user", options, nil, nil, result)
return result, err
}
// 修改客户备注信息.
// https://developer.work.weixin.qq.com/document/path/92115
func (comp *Client) Remark(ctx context.Context, data *request.RequestExternalContactRemark) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/externalcontact/remark", data, nil, nil, result)
return result, err
}
// 获取待分配的离职成员列表
// https://developer.work.weixin.qq.com/document/path/92124
func (comp *Client) GetUnassigned(ctx context.Context, pageID int, pageSize int) (*response.ResponseGetUnassignedList, error) {
result := &response.ResponseGetUnassignedList{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/externalcontact/get_unassigned_list", &object.HashMap{
"page_id": strconv.Itoa(pageID),
"page_size": strconv.Itoa(pageSize),
}, nil, nil, result)
return result, err
}
// 分配离职成员的客户
// https://developer.work.weixin.qq.com/document/path/94081
func (comp *Client) Transfer(ctx context.Context, externalUserID []string, handoverUserID string, takeoverUserID string) (*response.ResponseGetTransferedCustomerList, error) {
result := &response.ResponseGetTransferedCustomerList{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/externalcontact/transfer_customer", &object.HashMap{
"handover_userid": handoverUserID,
"takeover_userid": takeoverUserID,
"external_userid": externalUserID,
}, nil, nil, result)
return result, err
}
// 分配离职成员的客户群
// https://developer.work.weixin.qq.com/document/path/92127
func (comp *Client) TransferGroupChat(ctx context.Context, chatIDs []string, newOwner string) (*response3.ResponseGroupChatTransfer, error) {
result := &response3.ResponseGroupChatTransfer{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/externalcontact/groupchat/transfer", &object.HashMap{
"chat_id_list": chatIDs,
"new_owner": newOwner,
}, nil, nil, result)
return result, err
}
// 查询客户接替结果.
// https://developer.work.weixin.qq.com/document/path/94082
func (comp *Client) GetResignedTransferResult(ctx context.Context, handoverUserID string, takeoverUserID string, cursor string) (*response.ResponseGetTransferedCustomerList, error) {
result := &response.ResponseGetTransferedCustomerList{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/externalcontact/resigned/transfer_result?", &object.StringMap{
"handover_userid": handoverUserID,
"takeover_userid": takeoverUserID,
"cursor": cursor,
}, nil, nil, result)
return result, err
}