work/externalcontact/customer_strategy.pm untested

filter: Statementstmt 0.0% 0 / 81 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 177 CC 13 SCAR 22.5
CC
13
Cov
0%
list
12.0
get
12.0
get_range
12.0
CRAP 9.5
1 package QQ::weixin::work::externalcontact::customer_strategy;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::externalcontact::customer_strategy
8
9 =head1 DESCRIPTION
10
11 客户联系规则组管理
12 最后更新:2023/12/01
13
14 =head2 SYNOPSIS
15
16 L<https://developer.work.weixin.qq.com/document/path/94883>
17
18 =cut
19
20 use strict;
21 use base qw(QQ::weixin::work::externalcontact);
22 use Encode;
23 use LWP::UserAgent;
24 use JSON;
25 use utf8;
26
27 our $VERSION = '0.10';
28 our @EXPORT = qw/ list get get_range create edit del /;
29
30 =head1 FUNCTION
31
32 =head2 list(access_token, hash);
33
34 获取规则组列表
35
36 =head2 SYNOPSIS
37
38 L<https://developer.work.weixin.qq.com/document/path/94883#获取规则组列表>
39
40 =head3 请求说明:
41
42 企业可通过此接口获取企业配置的所有客户规则组id列表。
43
44 =head4 请求包结构体为:
45
46 {
47 "cursor":"CURSOR",
48 "limit":1000
49 }
50
51 =head4 参数说明:
52
53 参数 必须 说明
54 access_token 是 调用接口凭证
55 cursor 否 分页查询游标,首次调用可不填
56 limit 否 分页大小,默认为1000,最大不超过1000
57
58 =head4 权限说明:
59
60 调用客户联系规则组接口的应用需要满足如下的权限:
61
62 应用类型 权限要求
63 自建应用 配置到「客户联系 可调用接口的应用」中
64 代开发应用 具有「管理客户联系规则组」权限
65 第三方应用 具有「管理客户联系规则组」权限
66
67 提示
68 应用仅能获取和管理由本应用创建的规则组
69
70 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
71
72
73 =head3 RETURN 返回结果:
74
75 {
76 "errcode": 0,
77 "errmsg": "ok",
78 "strategy":
79 [
80 {
81 "strategy_id":1
82 },
83 {
84 "strategy_id":2
85 }
86 ],
87 "next_cursor":"NEXT_CURSOR"
88 }
89
90 =head4 RETURN 参数说明:
91
92 参数 说明
93 errcode 返回码
94 errmsg 对返回码的文本描述内容
95 strategy_id 规则组id
96 next_cursor 分页游标,用于查询下一个分页的数据,无更多数据时不返回
97
98 =cut
99
100 sub list {
101 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
102 my $access_token = $_[0];
103 my $json = $_[1];
104 my $ua = LWP::UserAgent->new;
105 $ua->timeout(30);
106 $ua->env_proxy;
107
108 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_strategy/list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
109 if ($response->is_success) {
110 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
111 }
112
113 }
114 return 0;
115 }
116
117 =head2 get(access_token, hash);
118
119 获取规则组详情
120
121 =head2 SYNOPSIS
122
123 L<https://developer.work.weixin.qq.com/document/path/94883#获取规则组详情>
124
125 =head3 请求说明:
126
127 企业可以通过此接口获取某个客户规则组的详细信息。
128
129 =head4 请求包结构体为:
130
131 {
132 "strategy_id":1
133 }
134
135 =head4 参数说明:
136
137 参数 必须 说明
138 access_token 是 调用接口凭证
139 strategy_id 是 规则组id
140
141 =head4 权限说明:
142
143 =head3 RETURN 返回结果:
144
145 {
146 "errcode": 0,
147 "errmsg": "ok",
148 "strategy": {
149 "strategy_id":1,
150 "parent_id":0,
151 "strategy_name": "NAME",
152 "create_time": 1557838797,
153 "admin_list":[
154 "zhangsan",
155 "lisi"
156 ],
157 "privilege":
158 {
159 "view_customer_list":true,
160 "view_customer_data":true,
161 "view_room_list":true,
162 "contact_me":true,
163 "join_room":true,
164 "share_customer":false,
165 "oper_resign_customer":true,
166 "oper_resign_group":true,
167 "send_customer_msg":true,
168 "edit_welcome_msg":true,
169 "view_behavior_data":true,
170 "view_room_data":true,
171 "send_group_msg":true,
172 "room_deduplication":true,
173 "rapid_reply":true,
174 "onjob_customer_transfer":true,
175 "edit_anti_spam_rule":true,
176 "export_customer_list":true,
177 "export_customer_data":true,
178 "export_customer_group_list":true,
179 "manage_customer_tag":true
180 }
181 }
182 }
183
184 =head4 RETURN 参数说明:
185
186 参数 说明
187 errcode 返回码
188 errmsg 对返回码的文本描述内容
189 strategy_id 规则组id
190 parent_id 父规则组id, 如果当前规则组没父规则组,则为0
191 strategy_name 规则组名称
192 create_time 规则组创建时间戳
193 admin_list 规则组管理员userid列表
194 privilege.view_customer_list 查看客户列表,基础权限,不可取消
195 privilege.view_customer_data 查看客户统计数据,基础权限,不可取消
196 privilege.view_room_list 查看群聊列表,基础权限,不可取消
197 privilege.contact_me 可使用联系我,基础权限,不可取消
198 privilege.join_room 可加入群聊,基础权限,不可取消
199 privilege.share_customer 允许分享客户给其他成员,默认为true
200 privilege.oper_resign_customer 允许分配离职成员客户,默认为true
201 privilege.oper_resign_group 允许分配离职成员客户群,默认为true
202 privilege.send_customer_msg 允许给企业客户发送消息,默认为true
203 privilege.edit_welcome_msg 允许配置欢迎语,默认为true
204 privilege.view_behavior_data 允许查看成员联系客户统计
205 privilege.view_room_data 允许查看群聊数据统计,默认为true
206 privilege.send_group_msg 允许发送消息到企业的客户群,默认为true
207 privilege.room_deduplication 允许对企业客户群进行去重,默认为true
208 privilege.rapid_reply 配置快捷回复,默认为true
209 privilege.onjob_customer_transfer 转接在职成员的客户,默认为true
210 privilege.edit_anti_spam_rule 编辑企业成员防骚扰规则,默认为true
211 privilege.export_customer_list 导出客户列表,默认为true
212 privilege.export_customer_data 导出成员客户统计,默认为true
213 privilege.export_customer_group_list 导出客户群列表,默认为true
214 privilege.manage_customer_tag 配置企业客户标签,默认为true
215
216 如果规则组具有父规则组则其管理范围必须是父规则组的子集。
217
218 =cut
219
220 sub get {
221 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
222 my $access_token = $_[0];
223 my $json = $_[1];
224 my $ua = LWP::UserAgent->new;
225 $ua->timeout(30);
226 $ua->env_proxy;
227
228 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_strategy/get?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
229 if ($response->is_success) {
230 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
231 }
232
233 }
234 return 0;
235 }
236
237 =head2 get_range(access_token, hash);
238
239 获取规则组管理范围
240
241 =head2 SYNOPSIS
242
243 L<https://developer.work.weixin.qq.com/document/path/94883#获取规则组管理范围>
244
245 =head3 请求说明:
246
247 企业可通过此接口获取某个客户规则组管理的成员和部门列表。
248
249 =head4 请求包结构体为:
250
251 {
252 "strategy_id":1,
253 "cursor":"CURSOR",
254 "limit":1000
255 }
256
257 =head4 参数说明:
258
259 参数 必须 说明
260 access_token 是 调用接口凭证
261 strategy_id 是 规则组id
262 cursor 否 分页游标
263 limit 否 每个分页的成员/部门节点数,默认为1000,最大为1000
264
265 =head4 权限说明:
266
267 =head3 RETURN 返回结果:
268
269 {
270 "errcode": 0,
271 "errmsg": "ok",
272 "range":
273 [
274 {
275 "type":1,
276 "userid":"zhangsan"
277 },
278 {
279 "type":2,
280 "partyid":1
281 }
282 ],
283 "next_cursor":"NEXT_CURSOR"
284 }
285
286 =head4 RETURN 参数说明:
287
288 参数 说明
289 errcode 返回码
290 errmsg 对返回码的文本描述内容
291 range.type 节点类型,1-成员 2-部门
292 range.userid 管理范围内配置的成员userid,仅type为1时返回
293 item.partyid 管理范围内配置的部门partyid,仅type为2时返回
294 next_cursor 分页游标,用于查询下一个分页的数据,无更多数据时不返回
295
296 =cut
297
298 sub get_range {
299 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
300 my $access_token = $_[0];
301 my $json = $_[1];
302 my $ua = LWP::UserAgent->new;
303 $ua->timeout(30);
304 $ua->env_proxy;
305
306 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_strategy/get_range?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
307 if ($response->is_success) {
308 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
309 }
310
311 }
312 return 0;
313 }
314
315 =head2 create(access_token, hash);
316
317 创建新的规则组
318
319 =head2 SYNOPSIS
320
321 L<https://developer.work.weixin.qq.com/document/path/94883#创建新的规则组>
322
323 =head3 请求说明:
324
325 企业可通过此接口创建一个新的客户规则组。该接口仅支持串行调用,请勿并发创建规则组。
326
327 =head4 请求包结构体为:
328
329 {
330 "parent_id":0,
331 "strategy_name": "NAME",
332 "admin_list":[
333 "zhangsan",
334 "lisi"
335 ],
336 "privilege":
337 {
338 "view_customer_list":true,
339 "view_customer_data":true,
340 "view_room_list":true,
341 "contact_me":true,
342 "join_room":true,
343 "share_customer":false,
344 "oper_resign_customer":true,
345 "send_customer_msg":true,
346 "edit_welcome_msg":true,
347 "view_behavior_data":true,
348 "view_room_data":true,
349 "send_group_msg":true,
350 "room_deduplication":true,
351 "rapid_reply":true,
352 "onjob_customer_transfer":true,
353 "edit_anti_spam_rule":true,
354 "export_customer_list":true,
355 "export_customer_data":true,
356 "export_customer_group_list":true,
357 "manage_customer_tag":true
358 },
359 "range":
360 [
361 {
362 "type":1,
363 "userid":"zhangsan"
364 },
365 {
366 "type":2,
367 "partyid":1
368 }
369 ]
370 }
371
372 =head4 参数说明:
373
374 参数 必须 说明
375 access_token 是 调用接口凭证
376 parent_id 否 父规则组id
377 strategy_name 是 规则组名称
378 admin_list 是 规则组管理员userid列表,不可配置超级管理员,每个规则组最多可配置20个负责人
379 privilege.view_customer_list 否 查看客户列表,基础权限,不可取消
380 privilege.view_customer_data 否 查看客户统计数据,基础权限,不可取消
381 privilege.view_room_list 否 查看群聊列表,基础权限,不可取消
382 privilege.contact_me 否 可使用联系我,基础权限,不可取消
383 privilege.join_room 否 可加入群聊,基础权限,不可取消
384 privilege.share_customer 否 允许分享客户给其他成员,默认为true
385 privilege.oper_resign_customer 否 允许分配离职成员客户,默认为true
386 privilege.oper_resign_group 否 允许分配离职成员客户群,默认为true
387 privilege.send_customer_msg 否 允许给企业客户发送消息,默认为true
388 privilege.edit_welcome_msg 否 允许配置欢迎语,默认为true
389 privilege.view_behavior_data 否 允许查看成员联系客户统计,默认为true
390 privilege.view_room_data 否 允许查看群聊数据统计,默认为true
391 privilege.send_group_msg 否 允许发送消息到企业的客户群,默认为true
392 privilege.room_deduplication 否 允许对企业客户群进行去重,默认为true
393 privilege.rapid_reply 否 配置快捷回复,默认为true
394 privilege.onjob_customer_transfer 否 转接在职成员的客户,默认为true
395 privilege.edit_anti_spam_rule 否 编辑企业成员防骚扰规则,默认为true
396 privilege.export_customer_list 否 导出客户列表,默认为true
397 privilege.export_customer_data 否 导出成员客户统计,默认为true
398 privilege.export_customer_group_list 否 导出客户群列表,默认为true
399 privilege.manage_customer_tag 否 配置企业客户标签,默认为true
400 range.type 是 规则组的管理范围节点类型 1-成员 2-部门
401 range.userid 否 规则组的管理成员id
402 range.partyid 否 规则组的管理部门id
403
404 单次最多可配置20个管理员和100个管理节点
405 如果要创建的规则组具有父规则组,则其管理范围必须是父规则组的子集,且将完全继承父规则组的权限配置(privilege将被忽略)
406 管理组的最大层级为5层
407 每个管理组的管理范围内最多支持3000个节点
408
409 =head4 权限说明:
410
411 =head3 RETURN 返回结果:
412
413 {
414 "errcode": 0,
415 "errmsg": "ok",
416 "strategy_id":1
417 }
418
419 =head4 RETURN 参数说明:
420
421 参数 说明
422 errcode 返回码
423 errmsg 对返回码的文本描述内容
424 strategy_id 规则组id
425
426 =cut
427
428 sub create {
429 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
430 my $access_token = $_[0];
431 my $json = $_[1];
432 my $ua = LWP::UserAgent->new;
433 $ua->timeout(30);
434 $ua->env_proxy;
435
436 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_strategy/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
437 if ($response->is_success) {
438 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
439 }
440
441 }
442 return 0;
443 }
444
445 =head2 edit(access_token, hash);
446
447 编辑规则组及其管理范围
448
449 =head2 SYNOPSIS
450
451 L<https://developer.work.weixin.qq.com/document/path/94883#编辑规则组及其管理范围>
452
453 =head3 请求说明:
454
455 企业可通过此接口编辑规则组的基本信息和修改客户规则组管理范围。该接口仅支持串行调用,请勿并发修改规则组。
456
457 =head4 请求包结构体为:
458
459 {
460 "strategy_id":1,
461 "strategy_name": "NAME",
462 "admin_list":[
463 "zhangsan",
464 "lisi"
465 ],
466 "privilege":
467 {
468 "view_customer_list":true,
469 "view_customer_data":true,
470 "view_room_list":true,
471 "contact_me":true,
472 "join_room":true,
473 "share_customer":false,
474 "oper_resign_customer":true,
475 "oper_resign_group":true,
476 "send_customer_msg":true,
477 "edit_welcome_msg":true,
478 "view_behavior_data":true,
479 "view_room_data":true,
480 "send_group_msg":true,
481 "room_deduplication":true,
482 "rapid_reply":true,
483 "onjob_customer_transfer":true,
484 "edit_anti_spam_rule":true,
485 "export_customer_list":true,
486 "export_customer_data":true,
487 "export_customer_group_list":true,
488 "manage_customer_tag":true
489 },
490 "range_add":
491 [
492 {
493 "type":1,
494 "userid":"zhangsan"
495 },
496 {
497 "type":2,
498 "partyid":1
499 }
500 ],
501 "range_del":
502 [
503 {
504 "type":1,
505 "userid":"lisi"
506 },
507 {
508 "type":2,
509 "partyid":2
510 }
511 ]
512 }
513
514 =head4 参数说明:
515
516 参数 必须 说明
517 access_token 是 调用接口凭证
518 strategy_id 是 规则组id
519 strategy_name 否 规则组名称
520 admin_list 否 管理员列表,如果为空则不对负责人做编辑,如果有则覆盖旧的负责人列表
521 privilege 否 权限配置,如果为空则不对权限做编辑,如果有则覆盖旧的权限配置
522 range_add.type 否 向管理范围添加的节点类型 1-成员 2-部门
523 range_add.userid 否 向管理范围添加成员的userid,仅type为1时有效
524 range_add.partyid 否 向管理范围添加部门的partyid,仅type为2时有效
525 range_del.type 否 从管理范围删除的节点类型 1-成员 2-部门
526 range_del.userid 否 从管理范围删除的成员的userid,仅type为1时有效
527 range_del.partyid 否 从管理范围删除的部门的partyid,仅type为2时有效
528
529 单次最多可配置20个管理员和100个管理节点
530 如果规则组具有父管理组则其管理范围必须是父规则组的子集,且将完全继承父规则组的权限配置(privilege将被忽略)
531
532 =head4 权限说明:
533
534 =head3 RETURN 返回结果:
535
536 {
537 "errcode": 0,
538 "errmsg": "ok"
539 }
540
541 =head4 RETURN 参数说明:
542
543 参数 说明
544 errcode 返回码
545 errmsg 对返回码的文本描述内容
546
547 =cut
548
549 sub edit {
550 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
551 my $access_token = $_[0];
552 my $json = $_[1];
553 my $ua = LWP::UserAgent->new;
554 $ua->timeout(30);
555 $ua->env_proxy;
556
557 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_strategy/edit?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
558 if ($response->is_success) {
559 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
560 }
561
562 }
563 return 0;
564 }
565
566 =head2 del(access_token, hash);
567
568 删除规则组
569
570 =head2 SYNOPSIS
571
572 L<https://developer.work.weixin.qq.com/document/path/94883#删除规则组>
573
574 =head3 请求说明:
575
576 企业可通过此接口删除某个规则组。
577
578 =head4 请求包结构体为:
579
580 {
581 "strategy_id":1
582 }
583
584 =head4 参数说明:
585
586 参数 必须 说明
587 access_token 是 调用接口凭证
588 strategy_id 是 规则组id
589
590 =head4 权限说明:
591
592 =head3 RETURN 返回结果:
593
594 {
595 "errcode": 0,
596 "errmsg": "ok"
597 }
598
599 =head4 RETURN 参数说明:
600
601 参数 说明
602 errcode 返回码
603 errmsg 对返回码的文本描述内容
604
605 =cut
606
607 sub del {
608 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
609 my $access_token = $_[0];
610 my $json = $_[1];
611 my $ua = LWP::UserAgent->new;
612 $ua->timeout(30);
613 $ua->env_proxy;
614
615 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_strategy/del?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
616 if ($response->is_success) {
617 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
618 }
619
620 }
621 return 0;
622 }
623
624 1;
625 __END__