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|\GuzzleHttp\Exception\GuzzleException |
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|\GuzzleHttp\Exception\GuzzleException |
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|\GuzzleHttp\Exception\GuzzleException |
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|\GuzzleHttp\Exception\GuzzleException |
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 $userId |
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
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
108
|
|
|
*/ |
109
|
|
|
public function batchGetByUser(string $userId, string $cursor, int $limit) |
110
|
|
|
{ |
111
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/batch/get_by_user', [ |
112
|
|
|
'userid' => $userId, |
113
|
|
|
'cursor' => $cursor, |
114
|
|
|
'limit' => $limit |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* 修改客户备注信息. |
121
|
|
|
* |
122
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92115 |
123
|
|
|
* |
124
|
|
|
* @param array $data |
125
|
|
|
* |
126
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
127
|
|
|
* |
128
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException |
129
|
|
|
*/ |
130
|
|
|
public function remark(array $data) |
131
|
|
|
{ |
132
|
|
|
return $this->httpPostJson( |
133
|
|
|
'cgi-bin/externalcontact/remark', |
134
|
|
|
$data |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* 获取离职成员的客户列表. |
141
|
|
|
* |
142
|
|
|
* @see https://work.weixin.qq.com/api/doc#90000/90135/91563 |
143
|
|
|
* |
144
|
|
|
* @param int $pageId |
145
|
|
|
* @param int $pageSize |
146
|
|
|
* |
147
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
148
|
|
|
* |
149
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
150
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
151
|
|
|
*/ |
152
|
1 |
|
public function getUnassigned(int $pageId = 0, int $pageSize = 1000) |
153
|
|
|
{ |
154
|
1 |
|
return $this->httpPostJson('cgi-bin/externalcontact/get_unassigned_list', [ |
155
|
1 |
|
'page_id' => $pageId, |
156
|
1 |
|
'page_size' => $pageSize, |
157
|
|
|
]); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* 离职成员的外部联系人再分配. |
162
|
|
|
* |
163
|
|
|
* @see https://work.weixin.qq.com/api/doc#90000/90135/91564 |
164
|
|
|
* |
165
|
|
|
* @param string $externalUserId |
166
|
|
|
* @param string $handoverUserId |
167
|
|
|
* @param string $takeoverUserId |
168
|
|
|
* @param string $transferSuccessMessage |
169
|
|
|
* |
170
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
171
|
|
|
* |
172
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
173
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
174
|
|
|
*/ |
175
|
1 |
|
public function transfer(string $externalUserId, string $handoverUserId, string $takeoverUserId, string $transferSuccessMessage) |
176
|
|
|
{ |
177
|
|
|
$params = [ |
178
|
1 |
|
'external_userid' => $externalUserId, |
179
|
1 |
|
'handover_userid' => $handoverUserId, |
180
|
1 |
|
'takeover_userid' => $takeoverUserId, |
181
|
1 |
|
'transfer_success_msg' => $transferSuccessMessage |
182
|
|
|
]; |
183
|
|
|
|
184
|
1 |
|
return $this->httpPostJson('cgi-bin/externalcontact/transfer', $params); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* 离职成员的群再分配. |
189
|
|
|
* |
190
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92127 |
191
|
|
|
* |
192
|
|
|
* @param array $chatIds |
193
|
|
|
* @param string $newOwner |
194
|
|
|
* |
195
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
196
|
|
|
* |
197
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
198
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
199
|
|
|
*/ |
200
|
|
|
public function transferGroupChat(array $chatIds, string $newOwner) |
201
|
|
|
{ |
202
|
|
|
$params = [ |
203
|
|
|
'chat_id_list' => $chatIds, |
204
|
|
|
'new_owner' => $newOwner |
205
|
|
|
]; |
206
|
|
|
|
207
|
|
|
return $this->httpPostJson('cgi-bin/groupchat/transfer', $params); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* 查询客户接替结果. |
212
|
|
|
* |
213
|
|
|
* @see https://work.weixin.qq.com/api/doc/90001/90143/93009 |
214
|
|
|
* |
215
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
216
|
|
|
* |
217
|
|
|
* @param string $externalUserId |
218
|
|
|
* @param string $handoverUserId |
219
|
|
|
* @param string $takeoverUserId |
220
|
|
|
* |
221
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
222
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
223
|
|
|
*/ |
224
|
|
|
public function getTransferResult(string $externalUserId, string $handoverUserId, string $takeoverUserId) |
225
|
|
|
{ |
226
|
|
|
$params = [ |
227
|
|
|
'external_userid' => $externalUserId, |
228
|
|
|
'handover_userid' => $handoverUserId, |
229
|
|
|
'takeover_userid' => $takeoverUserId, |
230
|
|
|
]; |
231
|
|
|
|
232
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/get_transfer_result', $params); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* 获取客户群列表. |
237
|
|
|
* |
238
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92120 |
239
|
|
|
* |
240
|
|
|
* @param array $params |
241
|
|
|
* |
242
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
243
|
|
|
* |
244
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
245
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
246
|
|
|
*/ |
247
|
|
|
|
248
|
|
|
public function getGroupChats(array $params) |
249
|
|
|
{ |
250
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/groupchat/list', $params); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* 获取客户群详情. |
255
|
|
|
* |
256
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92122 |
257
|
|
|
* |
258
|
|
|
* @param string $chatId |
259
|
|
|
* |
260
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
261
|
|
|
* |
262
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
263
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
264
|
|
|
*/ |
265
|
|
|
|
266
|
|
|
public function getGroupChat(string $chatId) |
267
|
|
|
{ |
268
|
|
|
$params = [ |
269
|
|
|
'chat_id' => $chatId |
270
|
|
|
]; |
271
|
|
|
|
272
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/groupchat/get', $params); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* 获取企业标签库. |
277
|
|
|
* |
278
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#获取企业标签库 |
279
|
|
|
* |
280
|
|
|
* @param array $tagIds |
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 getCorpTags(array $tagIds = []) |
289
|
|
|
{ |
290
|
|
|
$params = [ |
291
|
|
|
'tag_id' => $tagIds |
292
|
|
|
]; |
293
|
|
|
|
294
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/get_corp_tag_list', $params); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
|
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* 添加企业客户标签. |
301
|
|
|
* |
302
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#添加企业客户标签 |
303
|
|
|
* |
304
|
|
|
* @param array $params |
305
|
|
|
* |
306
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
307
|
|
|
* |
308
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
309
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
310
|
|
|
*/ |
311
|
|
|
|
312
|
|
|
public function addCorpTag(array $params) |
313
|
|
|
{ |
314
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/add_corp_tag', $params); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* 编辑企业客户标签. |
320
|
|
|
* |
321
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#编辑企业客户标签 |
322
|
|
|
* |
323
|
|
|
* @param string $id |
324
|
|
|
* @param string $name |
325
|
|
|
* @param int $order |
326
|
|
|
* |
327
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
328
|
|
|
* |
329
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
330
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
331
|
|
|
*/ |
332
|
|
|
|
333
|
|
|
public function updateCorpTag(string $id, string $name, int $order = 1) |
334
|
|
|
{ |
335
|
|
|
$params = [ |
336
|
|
|
"id" => $id, |
337
|
|
|
"name" => $name, |
338
|
|
|
"order" => $order, |
339
|
|
|
]; |
340
|
|
|
|
341
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/edit_corp_tag', $params); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* 删除企业客户标签. |
347
|
|
|
* |
348
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92117#删除企业客户标签 |
349
|
|
|
* |
350
|
|
|
* @param array $tagId |
351
|
|
|
* @param array $groupId |
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 deleteCorpTag(array $tagId, array $groupId) |
360
|
|
|
{ |
361
|
|
|
$params = [ |
362
|
|
|
"tag_id" => $tagId, |
363
|
|
|
"group_id" => $groupId, |
364
|
|
|
]; |
365
|
|
|
|
366
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/del_corp_tag', $params); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* 编辑客户企业标签. |
372
|
|
|
* |
373
|
|
|
* @see https://work.weixin.qq.com/api/doc/90000/90135/92118 |
374
|
|
|
* |
375
|
|
|
* @param array $params |
376
|
|
|
* |
377
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
378
|
|
|
* |
379
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
380
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
381
|
|
|
*/ |
382
|
|
|
|
383
|
|
|
public function markTags(array $params) |
384
|
|
|
{ |
385
|
|
|
return $this->httpPostJson('cgi-bin/externalcontact/mark_tag', $params); |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
|