work/externalcontact/customer_acquisition.pm untested

filter: Statementstmt 0.0% 0 / 91 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 202 CC 15 SCAR 22.8
CC
15
Cov
0%
list_link
12.0
get
12.0
create_link
12.0
CRAP 9.8
1 package QQ::weixin::work::externalcontact::customer_acquisition;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::externalcontact::customer_acquisition
8
9 =head1 DESCRIPTION
10
11 获客链接管理
12 最后更新:2023/11/13
13
14 =head2 SYNOPSIS
15
16 L<https://developer.work.weixin.qq.com/document/path/97297>
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_link get create_link update_link delete_link
29 customer
30 statistic /;
31
32 =head1 FUNCTION
33
34 =head2 list_link(access_token, hash);
35
36 获取获客链接列表
37
38 =head2 SYNOPSIS
39
40 L<https://developer.work.weixin.qq.com/document/path/97297#获取获客链接列表>
41
42 =head3 请求说明:
43
44 企业可通过此接口获取当前仍然有效的获客链接。
45
46 =head4 请求包结构体为:
47
48 {
49 "limit":100,
50 "cursor":"CURSOR"
51 }
52
53 =head4 参数说明:
54
55 参数 必须 说明
56 access_token 是 调用接口凭证
57 limit 否 返回的最大记录数,整型,最大值100
58 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
59
60 =head4 权限说明:
61
62 调企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
63 第三方或代开发应用需具有“企业客户权限->获客助手”权限
64 不支持客户联系系统应用调用
65
66 =head3 RETURN 返回结果:
67
68 {
69 "errcode": 0,
70 "errmsg": "ok",
71 "link_id_list":
72 [
73 "LINK_ID_AAA",
74 "LINK_ID_BBB",
75 "LINK_ID_CCC"
76 ],
77 "next_cursor":"CURSOR"
78 }
79
80 =head4 RETURN 参数说明:
81
82 参数 说明
83 errcode 返回码
84 errmsg 对返回码的文本描述内容
85 link_id_list link_id列表
86 next_cursor 分页游标,在下次请求时填写以获取之后分页的记录
87
88 =cut
89
90 sub list_link {
91 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
92 my $access_token = $_[0];
93 my $json = $_[1];
94 my $ua = LWP::UserAgent->new;
95 $ua->timeout(30);
96 $ua->env_proxy;
97
98 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/list_link?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
99 if ($response->is_success) {
100 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
101 }
102
103 }
104 return 0;
105 }
106
107 =head2 get(access_token, hash);
108
109 获取获客链接详情
110
111 =head2 SYNOPSIS
112
113 L<https://developer.work.weixin.qq.com/document/path/97297#获取获客链接详情>
114
115 =head3 请求说明:
116
117 企业可通过此接口根据获客链接id获取链接配置详情。
118
119 =head4 请求包结构体为:
120
121 {
122 "link_id":"LINK_ID_AAA"
123 }
124
125 =head4 参数说明:
126
127 参数 必须 说明
128 access_token 是 调用接口凭证
129 link_id 是 获客链接id
130
131 =head4 权限说明:
132
133 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
134 第三方或代开发应用需具有“企业客户权限->获客助手”权限
135 不支持客户联系系统应用调用
136
137 =head3 RETURN 返回结果:
138
139 {
140 "errcode": 0,
141 "errmsg": "ok",
142 "link":
143 {
144 "link_name":"LINK_NAME",
145 "url":"https://work.weixin.qq.com/ca/xxxxxx",
146 "create_time":1672502400,
147 "skip_verify":true
148 },
149 "range":
150 {
151 "user_list":["rocky","sam"],
152 "department_list":[1]
153 },
154 }
155
156 =head4 RETURN 参数说明:
157
158 参数 说明
159 errcode 返回码
160 errmsg 对返回码的文本描述内容
161 link.link_name 获客链接的名称
162 link.url 获客链接实际的url
163 link.create_time 创建时间
164 link.skip_verify 是否无需验证,默认为true
165 range.user_list 该获客链接使用范围成员列表
166 range.department_list 该获客链接使用范围的部门列表
167
168 =cut
169
170 sub get {
171 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
172 my $access_token = $_[0];
173 my $json = $_[1];
174 my $ua = LWP::UserAgent->new;
175 $ua->timeout(30);
176 $ua->env_proxy;
177
178 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/get?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
179 if ($response->is_success) {
180 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
181 }
182
183 }
184 return 0;
185 }
186
187 =head2 create_link(access_token, hash);
188
189 创建获客链接
190
191 =head2 SYNOPSIS
192
193 L<https://developer.work.weixin.qq.com/document/path/97297#创建获客链接>
194
195 =head3 请求说明:
196
197 企业可通过此接口创建新的获客链接。
198
199 =head4 请求包结构体为:
200
201 {
202 "link_name":"获客链接1号",
203 "range":
204 {
205 "user_list":["zhangsan","lisi"],
206 "department_list":[2,3]
207 },
208 "skip_verify":true
209 }
210
211 =head4 参数说明:
212
213 参数 必须 说明
214 access_token 是 调用接口凭证
215 link_name 是 链接名称
216 range.user_list 否 此获客链接关联的userid列表,最多500人
217 range.department_list 否 此获客链接关联的部门id列表,部门覆盖总人数最多500个
218 skip_verify 否 是否无需验证,默认为true
219
220 range.user_list和range.department_list不可同时为空,range覆盖的总用户数不得超过500人。
221
222 =head4 权限说明:
223
224 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
225 第三方或代开发应用需具有“企业客户权限->获客助手”权限
226 不支持客户联系系统应用调用
227
228 =head3 RETURN 返回结果:
229
230 {
231 "errcode": 0,
232 "errmsg": "ok",
233 "link":{
234 "link_id":"LINK_ID",
235 "link_name":"获客链接1号",
236 "url":"URL",
237 "create_time":1667232000
238 }
239 }
240
241 =head4 RETURN 参数说明:
242
243 参数 说明
244 errcode 返回码
245 errmsg 对返回码的文本描述内容
246 link.link_id 获客链接的id
247 link.link_name 获客链接名称
248 link.url 获客链接
249 create_time 获客链接创建时间
250
251 如为获取更好的跳转体验,也可将获客链接的url调整为scheme使用,方法如下:
252 scheme = weixin://biz/ww/profile/{urlencode(LINK_URL?customer_channel=STATE)}
253
254 示例,如果创建的获客链接为https://work.weixin.qq.com/ca/caXXXXX,
255 希望配置的customer_channel参数为WORK,则生成的scheme为:
256 weixin://biz/ww/profile/https%3A%2F%2Fwork.weixin.qq.com%2Fca%2FcaXXXXX%3Fcustomer_channel%3DWORK
257
258 =cut
259
260 sub create_link {
261 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
262 my $access_token = $_[0];
263 my $json = $_[1];
264 my $ua = LWP::UserAgent->new;
265 $ua->timeout(30);
266 $ua->env_proxy;
267
268 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/create_link?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
269 if ($response->is_success) {
270 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
271 }
272
273 }
274 return 0;
275 }
276
277 =head2 update_link(access_token, hash);
278
279 编辑获客链接
280
281 =head2 SYNOPSIS
282
283 L<https://developer.work.weixin.qq.com/document/path/97297#编辑获客链接>
284
285 =head3 请求说明:
286
287 企业可通过此接口编辑获客链接,修改获客链接的关联范围或修改获客链接的名称。
288
289 =head4 请求包结构体为:
290
291 {
292 "link_id":"LINK_ID",
293 "link_name":"获客链接1号",
294 "range":
295 {
296 "user_list":["zhangsan","lisi"],
297 "department_list":[2,3]
298 },
299 "skip_verify":true
300 }
301
302 =head4 参数说明:
303
304 参数 必须 说明
305 access_token 是 调用接口凭证
306 link_id 是 获客链接的id
307 link_name 否 更新的链接名称
308 range.user_list 否 此获客链接关联的userid列表,最多可关联500个
309 range.department_list 否 此获客链接关联的部门id列表,部门覆盖总人数最多500个
310 skip_verify 否 是否无需验证,默认为true
311
312 range为覆盖更新,覆盖的总人数不能超过500人。
313
314 =head4 权限说明:
315
316 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
317 第三方或代开发应用需具有“企业客户权限->获客助手”权限
318 不支持客户联系系统应用调用
319
320 =head3 RETURN 返回结果:
321
322 {
323 "errcode": 0,
324 "errmsg": "ok"
325 }
326
327 =head4 RETURN 参数说明:
328
329 参数 说明
330 errcode 返回码
331 errmsg 对返回码的文本描述内容
332
333 =cut
334
335 sub update_link {
336 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
337 my $access_token = $_[0];
338 my $json = $_[1];
339 my $ua = LWP::UserAgent->new;
340 $ua->timeout(30);
341 $ua->env_proxy;
342
343 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/update_link?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
344 if ($response->is_success) {
345 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
346 }
347
348 }
349 return 0;
350 }
351
352 =head2 delete_link(access_token, hash);
353
354 删除获客链接
355
356 =head2 SYNOPSIS
357
358 L<https://developer.work.weixin.qq.com/document/path/97297#删除获客链接>
359
360 =head3 请求说明:
361
362 企业可通过此接口删除获客链接,删除后的获客链接将无法继续使用。
363
364 =head4 请求包结构体为:
365
366 {
367 "link_id":"LINK_ID"
368 }
369
370 =head4 参数说明:
371
372 参数 必须 说明
373 access_token 是 调用接口凭证
374 link_id 是 获客链接的id
375
376 =head4 权限说明:
377
378 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
379 第三方或代开发应用需具有“企业客户权限->获客助手”权限
380 不支持客户联系系统应用调用
381
382 =head3 RETURN 返回结果:
383
384 {
385 "errcode": 0,
386 "errmsg": "ok"
387 }
388
389 =head4 RETURN 参数说明:
390
391 参数 说明
392 errcode 返回码
393 errmsg 对返回码的文本描述内容
394
395 =cut
396
397 sub delete_link {
398 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
399 my $access_token = $_[0];
400 my $json = $_[1];
401 my $ua = LWP::UserAgent->new;
402 $ua->timeout(30);
403 $ua->env_proxy;
404
405 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/delete_link?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
406 if ($response->is_success) {
407 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
408 }
409
410 }
411 return 0;
412 }
413
414 =head2 customer(access_token, hash);
415
416 获取由获客链接添加的客户信息
417 最后更新:2023/10/18
418
419 获取获客客户列表
420
421 =head2 SYNOPSIS
422
423 L<https://developer.work.weixin.qq.com/document/path/97298>
424
425 =head3 请求说明:
426
427 企业可通过此接口获取到由指定的获客链接添加的客户列表。
428
429 =head4 请求包结构体为:
430
431 {
432 "link_id":"LINK_ID",
433 "limit":1000,
434 "cursor":"CURSOR"
435 }
436
437 =head4 参数说明:
438
439 参数 必须 说明
440 access_token 是 调用接口凭证
441 link_id 是 获客链接id
442 limit 否 返回的最大记录数,整型,最大值1000
443 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
444
445 =head4 权限说明:
446
447 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
448 第三方或代开发应用需具有“企业客户权限->获客助手”权限
449 不支持客户联系系统应用调用
450
451 =head3 RETURN 返回结果:
452
453 {
454 "errcode": 0,
455 "errmsg": "ok",
456 "customer_list":
457 [
458 {
459 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAA",
460 "userid":"zhangsan",
461 "chat_status":0,
462 "state":"CHANNEL_A"
463 },
464 {
465 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAA",
466 "userid":"lisi",
467 "chat_status":0,
468 "state":"CHANNEL_B"
469 },
470 {
471 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mBCBBB",
472 "userid":"rocky",
473 "chat_status":1,
474 "state":"CHANNEL_A"
475 }
476 ],
477 "next_cursor":"CURSOR"
478 }
479
480 =head4 RETURN 参数说明:
481
482 参数 说明
483 errcode 返回码
484 errmsg 对返回码的文本描述内容
485 customer_list.external_userid 客户external_userid
486 customer_list.userid 通过获客链接添加此客户的跟进人userid
487 customer_list.chat_status 会话状态,0-客户未发消息 1-客户已发送消息 2-客户发送消息状态未知
488 customer_list.state 用于区分客户具体是通过哪个获客链接进行添加,用户可在获客链接后拼接customer_channel=自定义字符串,字符串不超过64字节,超过会被截断。通过点击带有customer_channel参数的链接获取到的客户,调用获客信息接口或获取客户详情接口时,返回的state参数即为链接后拼接自定义字符串
489 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
490
491 =cut
492
493 sub customer {
494 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
495 my $access_token = $_[0];
496 my $json = $_[1];
497 my $ua = LWP::UserAgent->new;
498 $ua->timeout(30);
499 $ua->env_proxy;
500
501 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/customer?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
502 if ($response->is_success) {
503 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
504 }
505
506 }
507 return 0;
508 }
509
510 =head2 statistic(access_token, hash);
511
512 获客助手额度管理与使用统计
513 最后更新:2023/08/08
514
515 查询链接使用详情
516
517 =head2 SYNOPSIS
518
519 L<https://developer.work.weixin.qq.com/document/path/97375#查询链接使用详情>
520
521 =head3 请求说明:
522
523 企业可通过此接口查询指定获客链接在指定时间范围内的访问情况。
524
525 =head4 请求包结构体为:
526
527 {
528 "link_id":"caxxxxxxx",
529 "start_time":1688140800,
530 "end_time":1688486400
531 }
532
533 =head4 参数说明:
534
535 参数 必须 说明
536 access_token 是 调用接口凭证
537 link_id 是 获客链接的id
538 start_time 是 统计起始时间戳
539 end_time 是 统计结束时间戳
540
541 注意:
542 1.统计范围的最小粒度为日,将自动转换为时间戳所在日进行统计,区间为闭区间。
543 2.仅可查询最近180天内的使用记录,起始和结束时间相差不可超过30天
544
545 =head4 权限说明:
546
547 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?);
548 第三方或代开发应用需具有“企业客户权限->获客助手”权限
549 不支持客户联系系统应用调用
550
551 =head3 RETURN 返回结果:
552
553 {
554 "errcode": 0,
555 "errmsg": "ok",
556 "click_link_customer_cnt":1000,
557 "new_customer_cnt":500,
558 }
559
560 =head4 RETURN 参数说明:
561
562 参数 说明
563 errcode 返回码
564 errmsg 对返回码的文本描述内容
565 click_link_customer_cnt 点击链接客户数
566 new_customer_cnt 新增客户数
567
568 =cut
569
570 sub statistic {
571 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
572 my $access_token = $_[0];
573 my $json = $_[1];
574 my $ua = LWP::UserAgent->new;
575 $ua->timeout(30);
576 $ua->env_proxy;
577
578 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/statistic?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
579 if ($response->is_success) {
580 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
581 }
582
583 }
584 return 0;
585 }
586
587 1;
588 __END__