1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/wechat. |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace EasyWeChat\Work\ExternalContact; |
13
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\BaseClient; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Client. |
18
|
|
|
* |
19
|
|
|
* @author mingyoung <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Client extends BaseClient |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* 获取配置了客户联系功能的成员列表. |
25
|
|
|
* |
26
|
|
|
* @see https://work.weixin.qq.com/api/doc#90000/90135/91554 |
27
|
|
|
* |
28
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
29
|
|
|
* |
30
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
31
|
|
|
*/ |
32
|
1 |
|
public function getFollowUsers() |
33
|
|
|
{ |
34
|
1 |
|
return $this->httpGet('cgi-bin/externalcontact/get_follow_user_list'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* 获取外部联系人列表. |
39
|
|
|
* |
40
|
|
|
* @see https://work.weixin.qq.com/api/doc#90000/90135/91555 |
41
|
|
|
* |
42
|
|
|
* @param string $userId |
43
|
|
|
* |
44
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
45
|
|
|
* |
46
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
47
|
|
|
*/ |
48
|
1 |
|
public function list(string $userId) |
49
|
|
|
{ |
50
|
1 |
|
return $this->httpGet('cgi-bin/externalcontact/list', [ |
51
|
1 |
|
'userid' => $userId, |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* 批量获取客户详情. |
57
|
|
|
* |
58
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92994 |
59
|
|
|
* |
60
|
|
|
* @param string $userId |
61
|
|
|
* @param string $cursor |
62
|
|
|
* @param integer $limit |
63
|
|
|
* |
64
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
65
|
|
|
* |
66
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
67
|
|
|
*/ |
68
|
|
|
public function batchGet(string $userId, string $cursor = '', int $limit = 100) |
69
|
|
|
{ |
70
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/batch/get_by_user', [ |
71
|
|
|
'userid' => $userId, |
72
|
|
|
'cursor' => $cursor, |
73
|
|
|
'limit' => $limit, |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* 获取外部联系人详情. |
79
|
|
|
* |
80
|
|
|
* @see https://work.weixin.qq.com/api/doc#90000/90135/91556 |
81
|
|
|
* |
82
|
|
|
* @param string $externalUserId |
83
|
|
|
* |
84
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
85
|
|
|
* |
86
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
87
|
|
|
*/ |
88
|
1 |
|
public function get(string $externalUserId) |
89
|
|
|
{ |
90
|
1 |
|
return $this->httpGet('cgi-bin/externalcontact/get', [ |
91
|
1 |
|
'external_userid' => $externalUserId, |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* 批量获取外部联系人详情. |
97
|
|
|
* |
98
|
|
|
* @see https://work.weixin.qq.com/api/doc/90001/90143/93010 |
99
|
|
|
* |
100
|
|
|
* @param string $externalUserId |
101
|
|
|
* @param string $cursor |
102
|
|
|
* @param int $limit |
103
|
|
|
* |
104
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
105
|
|
|
* |
106
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
107
|
|
|
*/ |
108
|
|
|
public function batchGetByUser(string $userid, string $cursor, int $limit) |
109
|
|
|
{ |
110
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/batch/get_by_user', [ |
111
|
|
|
'userid' => $userid, |
112
|
|
|
'cursor' => $cursor, |
113
|
|
|
'limit' => $limit |
114
|
|
|
]); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* 修改客户备注信息. |
120
|
|
|
* |
121
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92115 |
122
|
|
|
* |
123
|
|
|
* @param array $data |
124
|
|
|
* |
125
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
126
|
|
|
* |
127
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
128
|
|
|
*/ |
129
|
1 |
|
public function remark(array $data) |
130
|
|
|
{ |
131
|
1 |
|
return $this->httpPostJson( |
132
|
1 |
|
'cgi-bin/externalcontact/remark', |
133
|
1 |
|
$data |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* 获取离职成员的客户列表. |
140
|
|
|
* |
141
|
|
|
* @see https://work.weixin.qq.com/api/doc#90000/90135/91563 |
142
|
|
|
* |
143
|
|
|
* @param int $pageId |
144
|
|
|
* @param int $pageSize |
145
|
|
|
* |
146
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
147
|
|
|
* |
148
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
149
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
150
|
|
|
*/ |
151
|
1 |
|
public function getUnassigned(int $pageId = 0, int $pageSize = 1000) |
152
|
|
|
{ |
153
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/get_unassigned_list', [ |
154
|
1 |
|
'page_id' => $pageId, |
155
|
1 |
|
'page_size' => $pageSize, |
156
|
1 |
|
]); |
157
|
|
|
} |
158
|
|
|
|
159
|
1 |
|
/** |
160
|
|
|
* 离职成员的外部联系人再分配. |
161
|
|
|
* |
162
|
|
|
* @see https://work.weixin.qq.com/api/doc#90000/90135/91564 |
163
|
|
|
* |
164
|
|
|
* @param string $externalUserId |
165
|
|
|
* @param string $handoverUserId |
166
|
|
|
* @param string $takeoverUserId |
167
|
|
|
* @param string $transfer_success_msg |
168
|
|
|
* |
169
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
170
|
|
|
* |
171
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
172
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
173
|
|
|
*/ |
174
|
|
|
public function transfer(string $externalUserId, string $handoverUserId, string $takeoverUserId, string $transfer_success_msg) |
175
|
|
|
{ |
176
|
|
|
$params = [ |
177
|
|
|
'external_userid' => $externalUserId, |
178
|
|
|
'handover_userid' => $handoverUserId, |
179
|
|
|
'takeover_userid' => $takeoverUserId, |
180
|
|
|
'transfer_success_msg' => $transfer_success_msg |
181
|
|
|
]; |
182
|
|
|
|
183
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/transfer', $params); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* 查询客户接替结果. |
188
|
|
|
* |
189
|
|
|
* @see https://work.weixin.qq.com/api/doc/90001/90143/93009 |
190
|
|
|
* |
191
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
192
|
|
|
* |
193
|
|
|
* @param string $externalUserId |
194
|
|
|
* @param string $handoverUserId |
195
|
|
|
* @param string $takeoverUserId |
196
|
|
|
* |
197
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
198
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
199
|
|
|
*/ |
200
|
|
|
public function getTransferResult(string $externalUserId, string $handoverUserId, string $takeoverUserId) |
201
|
|
|
{ |
202
|
|
|
$params = [ |
203
|
|
|
'external_userid' => $externalUserId, |
204
|
|
|
'handover_userid' => $handoverUserId, |
205
|
|
|
'takeover_userid' => $takeoverUserId, |
206
|
|
|
]; |
207
|
|
|
|
208
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/get_transfer_result', $params); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* 获取客户群列表. |
213
|
|
|
* |
214
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92120 |
215
|
|
|
* |
216
|
|
|
* @param array $params |
217
|
|
|
* |
218
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
219
|
|
|
* |
220
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
221
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
222
|
|
|
*/ |
223
|
|
|
|
224
|
|
|
public function getGroupChats(array $params) |
225
|
|
|
{ |
226
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/groupchat/list', $params); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* 获取客户群详情. |
231
|
|
|
* |
232
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92122 |
233
|
|
|
* |
234
|
|
|
* @param string $chatId |
235
|
|
|
* |
236
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
237
|
|
|
* |
238
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
239
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
240
|
|
|
*/ |
241
|
|
|
|
242
|
|
|
public function getGroupChat(string $chatId) |
243
|
|
|
{ |
244
|
|
|
$params = [ |
245
|
|
|
'chat_id' => $chatId |
246
|
|
|
]; |
247
|
|
|
|
248
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/groupchat/get', $params); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* 获取企业标签库. |
253
|
|
|
* |
254
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#获取企业标签库 |
255
|
|
|
* |
256
|
|
|
* @param array $tagIds |
257
|
|
|
* |
258
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
259
|
|
|
* |
260
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
261
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
262
|
|
|
*/ |
263
|
|
|
|
264
|
|
|
public function getCorpTags(array $tagIds = []) |
265
|
|
|
{ |
266
|
|
|
$params = [ |
267
|
|
|
'tag_id' => $tagIds |
268
|
|
|
]; |
269
|
|
|
|
270
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/get_corp_tag_list', $params); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* 添加企业客户标签. |
277
|
|
|
* |
278
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#添加企业客户标签 |
279
|
|
|
* |
280
|
|
|
* @param array $params |
281
|
|
|
* |
282
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
283
|
|
|
* |
284
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
285
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
286
|
|
|
*/ |
287
|
|
|
|
288
|
|
|
public function addCorpTag(array $params) |
289
|
|
|
{ |
290
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/add_corp_tag', $params); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* 编辑企业客户标签. |
296
|
|
|
* |
297
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#编辑企业客户标签 |
298
|
|
|
* |
299
|
|
|
* @param string $id |
300
|
|
|
* @param string $name |
301
|
|
|
* @param int $order |
302
|
|
|
* |
303
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
304
|
|
|
* |
305
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
306
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
307
|
|
|
*/ |
308
|
|
|
|
309
|
|
|
public function updateCorpTag(string $id, string $name, int $order = 1) |
310
|
|
|
{ |
311
|
|
|
$params = [ |
312
|
|
|
"id" => $id, |
313
|
|
|
"name" => $name, |
314
|
|
|
"order" => $order, |
315
|
|
|
]; |
316
|
|
|
|
317
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/edit_corp_tag', $params); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* 删除企业客户标签. |
323
|
|
|
* |
324
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#删除企业客户标签 |
325
|
|
|
* |
326
|
|
|
* @param array $tagId |
327
|
|
|
* @param array $groupId |
328
|
|
|
* |
329
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
330
|
|
|
* |
331
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
332
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
333
|
|
|
*/ |
334
|
|
|
|
335
|
|
|
public function deleteCorpTag(array $tagId, array $groupId) |
336
|
|
|
{ |
337
|
|
|
$params = [ |
338
|
|
|
"tag_id" => $tagId, |
339
|
|
|
"group_id" => $groupId, |
340
|
|
|
]; |
341
|
|
|
|
342
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/del_corp_tag', $params); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* 编辑客户企业标签. |
348
|
|
|
* |
349
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92118 |
350
|
|
|
* |
351
|
|
|
* @param array $params |
352
|
|
|
* |
353
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
354
|
|
|
* |
355
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
356
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
357
|
|
|
*/ |
358
|
|
|
|
359
|
|
|
public function markTags(array $params) |
360
|
|
|
{ |
361
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/mark_tag', $params); |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
|