work/externalcontact.pm untested

filter: Statementstmt 0.0% 0 / 529 Branchbran 0.0% 0 / 204 Conditioncond 0.0% 0 / 299 MC/DCmcdc 0.0% 0 / 151 Subroutinesub 0.0% 0 / 57 Podpod 0.0% 0 / 51 totaltotal 0.0% 0 / 1291 CC 103 SCAR 24.5
CC
103
Cov
0%
get_follow_user_list
12.0
list
12.0
get
12.0
CRAP 11.6
1 package QQ::weixin::work::externalcontact;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::externalcontact
8
9 =head1 DESCRIPTION
10
11 客户联系
12
13 =cut
14
15 use strict;
16 use base qw(QQ::weixin::work);
17 use Encode;
18 use LWP::UserAgent;
19 use JSON;
20 use utf8;
21
22 our $VERSION = '0.10';
23 our @EXPORT = qw/ get_follow_user_list list get remark
24 get_corp_tag_list add_corp_tag edit_corp_tag del_corp_tag
25 get_strategy_tag_list add_strategy_tag edit_strategy_tag del_strategy_tag
26 mark_tag
27 get_unassigned_list
28 transfer_customer transfer_result
29 opengid_to_chatid
30 add_contact_way get_contact_way list_contact_way update_contact_way del_contact_way close_temp_chat
31 add_moment_task get_moment_task_result cancel_moment_task
32 get_moment_list get_moment_task get_moment_customer_list get_moment_send_result get_moment_comments
33 customer_acquisition_quota
34 add_msg_template remind_groupmsg_send cancel_groupmsg_send
35 get_groupmsg_list_v2 get_groupmsg_task get_groupmsg_send_result
36 send_welcome_msg
37 get_user_behavior_data
38 add_product_album get_product_album get_product_album_list update_product_album delete_product_album
39 add_intercept_rule get_intercept_rule_list get_intercept_rule update_intercept_rule del_intercept_rule
40 contact_list /;
41
42 =head1 FUNCTION
43
44 =head2 get_follow_user_list(access_token);
45
46 获取配置了客户联系功能的成员列表
47 最后更新:2023/12/01
48
49 =head2 SYNOPSIS
50
51 L<https://developer.work.weixin.qq.com/document/path/92571>
52
53 =head3 请求说明:
54
55 企业和第三方服务商可通过此接口获取配置了客户联系功能的成员列表。
56
57 =head4 参数说明:
58
59 参数 必须 说明
60 access_token 是 调用接口凭证
61
62 =head4 权限说明:
63
64 调用接口的应用需要满足如下的权限:
65
66 应用类型 权限要求
67 自建应用 配置到「客户联系 可调用接口的应用」中
68 代开发应用 具有「客户基础信息」权限
69 第三方应用 具有「客户基础信息」权限
70
71 应用仅可获取可见范围内的成员。
72
73 =head3 RETURN 返回结果:
74
75 {
76 "errcode": 0,
77 "errmsg": "ok",
78 "follow_user":[
79 "zhangsan",
80 "lissi"
81 ]
82 }
83
84 =head4 RETURN 参数说明
85
86 参数 说明
87 errcode 返回码
88 errmsg 对返回码的文本描述内容
89 follow_user 配置了客户联系功能的成员userid列表
90
91 =cut
92
93 sub get_follow_user_list {
94 if ( @_ && $_[0] ) {
95 my $access_token = $_[0];
96 my $ua = LWP::UserAgent->new;
97 $ua->timeout(30);
98 $ua->env_proxy;
99
100 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list?access_token=$access_token");
101 if ($response->is_success) {
102 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
103 }
104
105 }
106 return 0;
107 }
108
109 =head2 list(access_token);
110
111 获取客户列表
112 最后更新:2023/12/01
113
114 =head2 SYNOPSIS
115
116 L<https://developer.work.weixin.qq.com/document/path/92113>
117
118 =head3 请求说明:
119
120 企业可通过此接口获取指定成员添加的客户列表。客户是指配置了客户联系功能的成员所添加的外部联系人。没有配置客户联系功能的成员,所添加的外部联系人将不会作为客户返回。
121
122 =head4 参数说明:
123
124 参数 必须 说明
125 access_token 是 调用接口凭证
126 userid 是 企业成员的userid
127
128 =head4 权限说明:
129
130 调用接口的应用需要满足如下的权限:
131
132 应用类型 权限要求
133 自建应用 配置到「客户联系 可调用接口的应用」中
134 代开发应用 具有「客户基础信息」权限
135 第三方应用 具有「客户基础信息」权限
136
137 应用只能获取到可见范围内的配置了客户联系功能的成员。
138
139 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
140
141 =head3 RETURN 返回结果:
142
143 {
144 "errcode": 0,
145 "errmsg": "ok",
146 "external_userid":
147 [
148 "woAJ2GCAAAXtWyujaWJHDDGi0mACAAA",
149 "wmqfasd1e1927831291723123109rAAA"
150 ]
151 }
152
153 =head4 RETURN 参数说明
154
155 参数 说明
156 errcode 返回码
157 errmsg 对返回码的文本描述内容
158 external_userid 外部联系人的userid列表
159
160 =cut
161
162 sub list {
163 if ( @_ && $_[0] && $_[1] ) {
164 my $access_token = $_[0];
165 my $userid = $_[1];
166 my $ua = LWP::UserAgent->new;
167 $ua->timeout(30);
168 $ua->env_proxy;
169
170 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list?access_token=$access_token&userid=$userid");
171 if ($response->is_success) {
172 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
173 }
174
175 }
176 return 0;
177 }
178
179 =head2 get(access_token, external_userid, cursor);
180
181 获取客户详情
182 最后更新:2023/12/01
183
184 =head2 SYNOPSIS
185
186 L<https://developer.work.weixin.qq.com/document/path/92114>
187
188 =head3 请求说明:
189
190 企业可通过此接口,根据外部联系人的userid(如何获取?),拉取客户详情。
191
192 =head4 参数说明:
193
194 参数 必须 说明
195 access_token 是 调用接口凭证
196 external_userid 是 外部联系人的userid,注意不是企业成员的帐号
197 cursor 否 上次请求返回的next_cursor
198
199 =head4 权限说明:
200
201 调用接口的应用需要满足如下的权限:
202
203 应用类型 权限要求
204 自建应用 配置到「客户联系 可调用接口的应用」中
205 代开发应用 具有「客户基础信息」权限
206 第三方应用 具有「客户基础信息」权限
207
208 应用只能获取到可见范围内的成员;当客户在企业内的跟进人超过500人时需要使用cursor参数进行分页获取。
209
210 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
211
212 =head3 RETURN 返回结果:
213
214 {
215 "errcode": 0,
216 "errmsg": "ok",
217 "external_contact":
218 {
219 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACHAAA",
220 "name":"李四",
221 "position":"Manager",
222 "avatar":"http://p.qlogo.cn/bizmail/IcsdgagqefergqerhewSdage/0",
223 "corp_name":"腾讯",
224 "corp_full_name":"腾讯科技有限公司",
225 "type":2,
226 "gender":1,
227 "unionid":"ozynqsulJFCZ2z1aYeS8h-nuasdAAA",
228 "external_profile":
229 {
230 "external_attr":
231 [
232 {
233 "type":0,
234 "name":"文本名称",
235 "text":
236 {
237 "value":"文本"
238 }
239 },
240 {
241 "type":1,
242 "name":"网页名称",
243 "web":
244 {
245 "url":"http://www.test.com",
246 "title":"标题"
247 }
248 },
249 {
250 "type":2,
251 "name":"测试app",
252 "miniprogram":
253 {
254 "appid": "wx8bd80126147df384",
255 "pagepath": "/index",
256 "title": "my miniprogram"
257 }
258 }
259 ]
260 }
261 },
262 "follow_user":
263 [
264 {
265 "userid":"rocky",
266 "remark":"李部长",
267 "description":"对接采购事务",
268 "createtime":1525779812,
269 "tags":
270 [
271 {
272 "group_name":"标签分组名称",
273 "tag_name":"标签名称",
274 "tag_id":"etAJ2GCAAAXtWyujaWJHDDGi0mACHAAA",
275 "type":1
276 },
277 {
278 "group_name":"标签分组名称",
279 "tag_name":"标签名称",
280 "type":2
281 },
282 {
283 "group_name":"标签分组名称",
284 "tag_name":"标签名称",
285 "tag_id":"stAJ2GCAAAXtWyujaWJHDDGi0mACHAAA",
286 "type":3
287 }
288 ],
289 "remark_corp_name":"腾讯科技",
290 "remark_mobiles":
291 [
292 "13800000001",
293 "13000000002"
294 ],
295 "oper_userid":"rocky",
296 "add_way":10,
297 "wechat_channels": {
298 "nickname": "视频号名称",
299 "source": 1
300 }
301 },
302 {
303 "userid":"tommy",
304 "remark":"李总",
305 "description":"采购问题咨询",
306 "createtime":1525881637,
307 "state":"外联二维码1",
308 "oper_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACHAAA",
309 "add_way":3
310 }
311 ],
312 "next_cursor":"NEXT_CURSOR"
313 }
314
315 =head4 RETURN 参数说明
316
317 参数 说明
318 errcode 返回码
319 errmsg 对返回码的文本描述内容
320 external_userid 外部联系人的userid
321 name 外部联系人的名称[注1]
322 avatar 外部联系人头像,代开发自建应用需要管理员授权才可以获取,第三方不可获取,上游企业不可获取下游企业客户该字段
323 type 外部联系人的类型,1表示该外部联系人是微信用户,2表示该外部联系人是企业微信用户
324 gender 外部联系人性别 0-未知 1-男性 2-女性。第三方不可获取,上游企业不可获取下游企业客户该字段,返回值为0,表示未定义
325 unionid 外部联系人在微信开放平台的唯一身份标识(微信unionid),通过此字段企业可将外部联系人与公众号/小程序用户关联起来。仅当联系人类型是微信用户,且企业绑定了微信开发者ID有此字段。查看绑定方法。第三方应用和代开发应用均不可获取,上游企业不可获取下游企业客户的unionid字段
326 position 外部联系人的职位,如果外部企业或用户选择隐藏职位,则不返回,仅当联系人类型是企业微信用户时有此字段
327 corp_name 外部联系人所在企业的简称,仅当联系人类型是企业微信用户时有此字段
328 corp_full_name 外部联系人所在企业的主体名称,仅当联系人类型是企业微信用户时有此字段。仅企业自建应用可获取;第三方应用、代开发应用、上下游应用不可获取,返回内容为企业名称,即corp_name。
329 external_profile 外部联系人的自定义展示信息,可以有多个字段和多种类型,包括文本,网页和小程序,仅当联系人类型是企业微信用户时有此字段,字段详情见对外属性;
330 follow_user.userid 添加了此外部联系人的企业成员userid
331 follow_user.remark 该成员对此外部联系人的备注
332 follow_user.description 该成员对此外部联系人的描述
333 follow_user.createtime 该成员添加此外部联系人的时间
334 follow_user.tags.group_name 该成员添加此外部联系人所打标签的分组名称(标签功能需要企业微信升级到2.7.5及以上版本)
335 follow_user.tags.tag_name 该成员添加此外部联系人所打标签名称
336 follow_user.tags.type 该成员添加此外部联系人所打标签类型, 1-企业设置,2-用户自定义,3-规则组标签
337 follow_user.tags.tag_id 该成员添加此外部联系人所打企业标签的id,用户自定义类型标签(type=2)不返回
338 follow_user.remark_corp_name 该成员对此微信客户备注的企业名称(仅微信客户有该字段)
339 follow_user.remark_mobiles 该成员对此客户备注的手机号码,代开发自建应用需要管理员授权才可以获取,第三方不可获取,上游企业不可获取下游企业客户该字段
340 follow_user.add_way 该成员添加此客户的来源,具体含义详见来源定义
341 follow_user.wechat_channels 该成员添加此客户的来源add_way为10时,对应的视频号信息
342 follow_user.wechat_channels.nickname 视频号名称
343 follow_user.wechat_channels.source 视频号添加场景,0-未知 1-视频号主页 2-视频号直播间 3-视频号留资服务(微信版本要求:iOS ≥ 8.0.20,Android ≥ 8.0.21,且添加时间不早于2022年4月21日。否则添加场景值为0)
344 follow_user.oper_userid 发起添加的userid,如果成员主动添加,为成员的userid;如果是客户主动添加,则为客户的外部联系人userid;如果是内部成员共享/管理员分配,则为对应的成员/管理员userid
345 follow_user.state 企业自定义的state参数,用于区分客户具体是通过哪个「联系我」或获客链接添加;由企业通过创建「联系我」或在获客链接中添加customer_channel参数进行指定
346 next_cursor 分页的cursor,当跟进人多于500人时返回
347
348 注1:如果是微信用户,则返回其微信昵称。如果是企业微信联系人,则返回其设置对外展示的别名或实名
349
350 =head3 来源定义
351
352 add_way表示添加客户的来源,有固定的值,而state表示此客户的渠道,可以由企业进行自定义的配置,请注意二者的不同。
353
354 值 含义
355 0 未知来源
356 1 扫描二维码
357 2 搜索手机号
358 3 名片分享
359 4 群聊
360 5 手机通讯录
361 6 微信联系人
362 8 安装第三方应用时自动添加的客服人员
363 9 搜索邮箱
364 10 视频号添加
365 11 通过日程参与人添加
366 12 通过会议参与人添加
367 13 添加微信好友对应的企业微信
368 14 通过智慧硬件专属客服添加
369 15 通过上门服务客服添加
370 16 通过获客链接添加
371 17 通过定制开发添加
372 18 通过需求回复添加
373 201 内部成员共享
374 202 管理员/负责人分配
375
376 =cut
377
378 sub get {
379 if ( @_ && $_[0] && $_[1] ) {
380 my $access_token = $_[0];
381 my $userid = $_[1];
382 my $cursor = $_[2] || 0;
383 my $ua = LWP::UserAgent->new;
384 $ua->timeout(30);
385 $ua->env_proxy;
386
387 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=$access_token&external_userid=$userid&cursor=$cursor");
388 if ($response->is_success) {
389 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
390 }
391
392 }
393 return 0;
394 }
395
396 =head2 remark(access_token, hash);
397
398 修改客户备注信息
399 最后更新:2023/12/01
400
401 =head2 SYNOPSIS
402
403 L<https://developer.work.weixin.qq.com/document/path/92115>
404
405 =head3 请求说明:
406
407 企业可通过此接口修改指定用户添加的客户的备注信息。
408
409 =head4 请求包结构体为:
410
411 {
412 "userid":"zhangsan",
413 "external_userid":"woAJ2GCAAAd1asdasdjO4wKmE8Aabj9AAA",
414 "remark":"备注信息",
415 "description":"描述信息",
416 "remark_company":"腾讯科技",
417 "remark_mobiles":[
418 "13800000001",
419 "13800000002"
420 ],
421 "remark_pic_mediaid":"MEDIAID"
422 }
423
424 =head4 参数说明:
425
426 参数 必须 说明
427 access_token 是 调用接口凭证
428 userid 是 企业成员的userid
429 external_userid 是 外部联系人userid
430 remark 否 此用户对外部联系人的备注,最多20个字符
431 description 否 此用户对外部联系人的描述,最多150个字符
432 remark_company 否 此用户对外部联系人备注的所属公司名称,最多20个字符
433 remark_mobiles 否 此用户对外部联系人备注的手机号
434 remark_pic_mediaid 否 备注图片的mediaid
435
436 remark_company只在此外部联系人为微信用户时有效。
437 remark,description,remark_company,remark_mobiles和remark_pic_mediaid不可同时为空。
438 如果填写了remark_mobiles,将会覆盖旧的备注手机号。
439 如果要清除所有备注手机号,请在remark_mobiles填写一个空字符串("")。
440 remark_pic_mediaid可以通过素材管理接口获得。
441
442 =head3 权限说明
443
444 调用接口的应用需要满足如下的权限:
445
446 应用类型 权限要求
447 自建应用 配置到「客户联系 可调用接口的应用」中
448 代开发应用 具有「客户基础信息」权限
449 第三方应用 具有「客户基础信息」权限
450
451 应用仅可编辑可见范围内的成员添加的企业客户备注信息。
452
453 =head3 RETURN 返回结果
454
455 {
456 "errcode": 0,
457 "errmsg": "ok"
458 }
459
460 =head4 RETURN 参数说明
461
462 参数 说明
463 errcode 返回码
464 errmsg 对返回码的文本描述内容
465
466 =cut
467
468 sub remark {
469 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
470 my $access_token = $_[0];
471 my $json = $_[1];
472 my $ua = LWP::UserAgent->new;
473 $ua->timeout(30);
474 $ua->env_proxy;
475
476 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
477 if ($response->is_success) {
478 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
479 }
480
481 }
482 return 0;
483 }
484
485 =head2 管理企业标签
486
487 最后更新:2023/12/01
488 企业客户标签是针对企业的外部联系人进行标记和分类的标签,由企业统一配置后,企业成员可使用此标签对客户进行标记。
489
490 =head2 SYNOPSIS
491
492 L<https://developer.work.weixin.qq.com/document/path/92117>
493
494 =head3 权限说明
495
496 调用接口的应用需要满足如下的权限:
497
498 应用类型 权限要求
499 自建应用 配置到「客户联系 可调用接口的应用」中
500 代开发应用 具有「管理企业客户标签」权限(添加、编辑、删除)或「客户基础信息」(读取)
501 第三方应用 具有「管理企业客户标签」权限(添加、编辑、删除)或「客户基础信息」(读取)
502
503 应用仅能编辑和删除本应用创建的标签
504
505 =head2 get_corp_tag_list(access_token, hash);
506
507 获取企业标签库
508
509 =head2 SYNOPSIS
510
511 L<https://developer.work.weixin.qq.com/document/path/92117#获取企业标签库>
512
513 =head3 请求说明:
514
515 企业可通过此接口获取企业客户标签详情。
516
517 =head4 请求包结构体为:
518
519 {
520 "tag_id":
521 [
522 "etXXXXXXXXXX",
523 "etYYYYYYYYYY"
524 ],
525 "group_id":
526 [
527 "etZZZZZZZZZZZZZ",
528 "etYYYYYYYYYYYYY"
529 ]
530 }
531
532 =head4 参数说明:
533
534 参数 必须 说明
535 access_token 是 调用接口凭证
536 tag_id 否 要查询的标签id
537 group_id 否 要查询的标签组id,返回该标签组以及其下的所有标签信息
538
539 若tag_id和group_id均为空,则返回所有标签。
540 同时传递tag_id和group_id时,忽略tag_id,仅以group_id作为过滤条件。
541
542 =head3 RETURN 返回结果
543
544 {
545 "errcode": 0,
546 "errmsg": "ok",
547 "tag_group": [{
548 "group_id": "TAG_GROUPID1",
549 "group_name": "GOURP_NAME",
550 "create_time": 1557838797,
551 "order": 1,
552 "deleted": false,
553 "tag": [{
554 "id": "TAG_ID1",
555 "name": "NAME1",
556 "create_time": 1557838797,
557 "order": 1,
558 "deleted": false
559 },
560 {
561 "id": "TAG_ID2",
562 "name": "NAME2",
563 "create_time": 1557838797,
564 "order": 2,
565 "deleted": true
566 }
567 ]
568 }]
569 }
570
571 =head4 RETURN 参数说明
572
573 参数 说明
574 errcode 返回码
575 errmsg 对返回码的文本描述内容
576 tag_group 标签组列表
577 tag_group.group_id 标签组id
578 tag_group.group_name 标签组名称
579 tag_group.create_time 标签组创建时间
580 tag_group.order 标签组排序的次序值,order值大的排序靠前。有效的值范围是[0, 2^32)
581 tag_group.deleted 标签组是否已经被删除,只在指定tag_id进行查询时返回
582 tag_group.tag 标签组内的标签列表
583 tag_group.tag.id 标签id
584 tag_group.tag.name 标签名称
585 tag_group.tag.create_time 标签创建时间
586 tag_group.tag.order 标签排序的次序值,order值大的排序靠前。有效的值范围是[0, 2^32)
587 tag_group.tag.deleted 标签是否已经被删除,只在指定tag_id/group_id进行查询时返回
588
589 =cut
590
591 sub get_corp_tag_list {
592 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
593 my $access_token = $_[0];
594 my $json = $_[1];
595 my $ua = LWP::UserAgent->new;
596 $ua->timeout(30);
597 $ua->env_proxy;
598
599 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
600 if ($response->is_success) {
601 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
602 }
603
604 }
605 return 0;
606 }
607
608 =head2 add_corp_tag(access_token, hash);
609
610 添加企业客户标签
611
612 =head2 SYNOPSIS
613
614 L<https://developer.work.weixin.qq.com/document/path/92117#添加企业客户标签>
615
616 =head3 请求说明:
617
618 企业可通过此接口向客户标签库中添加新的标签组和标签,每个企业最多可配置10000个企业标签。
619
620 =head4 请求包结构体为:
621
622 {
623 "group_id": "GROUP_ID",
624 "group_name": "GROUP_NAME",
625 "order": 1,
626 "tag": [{
627 "name": "TAG_NAME_1",
628 "order": 1
629 },
630 {
631 "name": "TAG_NAME_2",
632 "order": 2
633 }
634 ],
635 "agentid" : 1000014
636 }
637
638 =head4 参数说明:
639
640 参数 必须 说明
641 access_token 是 调用接口凭证
642 group_id 否 标签组id
643 group_name 否 标签组名称,最长为30个字符
644 order 否 标签组次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
645 tag.name 是 添加的标签名称,最长为30个字符
646 tag.order 否 标签次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
647 agentid 否 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数
648
649 注意:
650 如果要向指定的标签组下添加标签,需要填写group_id参数;如果要创建一个全新的标签组以及标签,则需要通过group_name参数指定新标签组名称,如果填写的groupname已经存在,则会在此标签组下新建标签。
651 如果填写了group_id参数,则group_name和标签组的order参数会被忽略。
652 不支持创建空标签组。
653 标签组内的标签不可同名,如果传入多个同名标签,则只会创建一个。
654
655 =head3 RETURN 返回结果
656
657 {
658 "errcode": 0,
659 "errmsg": "ok",
660 "tag_group": {
661 "group_id": "TAG_GROUPID1",
662 "group_name": "GOURP_NAME",
663 "create_time": 1557838797,
664 "order": 1,
665 "tag": [{
666 "id": "TAG_ID1",
667 "name": "NAME1",
668 "create_time": 1557838797,
669 "order": 1
670 },
671 {
672 "id": "TAG_ID2",
673 "name": "NAME2",
674 "create_time": 1557838797,
675 "order": 2
676 }
677 ]
678 }
679 }
680
681 =head4 RETURN 参数说明
682
683 参数 说明
684 errcode 返回码
685 errmsg 对返回码的文本描述内容
686 tag_group.group_id 标签组id
687 tag_group.group_name 标签组名称
688 tag_group.create_time 标签组创建时间
689 tag_group.order 标签组次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
690 tag_group.tag 标签组内的标签列表
691 tag_group.tag.id 新建标签id
692 tag_group.tag.name 新建标签名称
693 tag_group.tag.create_time 标签创建时间
694 tag_group.tag.order 标签次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
695
696 =cut
697
698 sub add_corp_tag {
699 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
700 my $access_token = $_[0];
701 my $json = $_[1];
702 my $ua = LWP::UserAgent->new;
703 $ua->timeout(30);
704 $ua->env_proxy;
705
706 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
707 if ($response->is_success) {
708 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
709 }
710
711 }
712 return 0;
713 }
714
715 =head2 edit_corp_tag(access_token, hash);
716
717 编辑企业客户标签
718
719 =head2 SYNOPSIS
720
721 L<https://developer.work.weixin.qq.com/document/path/92117#编辑企业客户标签>
722
723 =head3 请求说明:
724
725 企业可通过此接口编辑客户标签/标签组的名称或次序值。
726
727 =head4 请求包结构体为:
728
729 {
730 "id": "TAG_ID",
731 "name": "NEW_TAG_NAME",
732 "order": 1,
733 "agentid" : 1000014
734 }
735
736 =head4 参数说明:
737
738 参数 必须 说明
739 access_token 是 调用接口凭证
740 id 是 标签或标签组的id
741 name 否 新的标签或标签组名称,最长为30个字符
742 order 否 标签/标签组的次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
743 agentid 否 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数
744
745 注意:修改后的标签组不能和已有的标签组重名,标签也不能和同一标签组下的其他标签重名。
746
747 =head3 RETURN 返回结果
748
749 {
750 "errcode": 0,
751 "errmsg": "ok"
752 }
753
754 =head4 RETURN 参数说明
755
756 参数 说明
757 errcode 返回码
758 errmsg 对返回码的文本描述内容
759
760 =cut
761
762 sub edit_corp_tag {
763 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
764 my $access_token = $_[0];
765 my $json = $_[1];
766 my $ua = LWP::UserAgent->new;
767 $ua->timeout(30);
768 $ua->env_proxy;
769
770 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
771 if ($response->is_success) {
772 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
773 }
774
775 }
776 return 0;
777 }
778
779 =head2 del_corp_tag(access_token, hash);
780
781 删除企业客户标签
782
783 =head2 SYNOPSIS
784
785 L<https://developer.work.weixin.qq.com/document/path/92117#删除企业客户标签>
786
787 =head3 请求说明:
788
789 企业可通过此接口删除客户标签库中的标签,或删除整个标签组。
790
791 =head4 请求包结构体为:
792
793 {
794 "tag_id": [
795 "TAG_ID_1",
796 "TAG_ID_2"
797 ],
798 "group_id": [
799 "GROUP_ID_1",
800 "GROUP_ID_2"
801 ],
802 "agentid" : 1000014
803 }
804
805 =head4 参数说明:
806
807 参数 必须 说明
808 access_token 是 调用接口凭证
809 tag_id 否 标签的id列表
810 group_id 否 标签组的id列表
811 agentid 否 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数
812
813 tag_id和group_id不可同时为空。
814 如果一个标签组下所有的标签均被删除,则标签组会被自动删除。
815
816 =head3 RETURN 返回结果
817
818 {
819 "errcode": 0,
820 "errmsg": "ok"
821 }
822
823 =head4 RETURN 参数说明
824
825 参数 说明
826 errcode 返回码
827 errmsg 对返回码的文本描述内容
828
829 =cut
830
831 sub del_corp_tag {
832 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
833 my $access_token = $_[0];
834 my $json = $_[1];
835 my $ua = LWP::UserAgent->new;
836 $ua->timeout(30);
837 $ua->env_proxy;
838
839 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
840 if ($response->is_success) {
841 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
842 }
843
844 }
845 return 0;
846 }
847
848 =head2 管理企业规则组下的客户标签
849
850 最后更新:2023/12/01
851 企业规则组下的客户标签仅可被该规则组管理范围内的企业成员使用。
852
853 =head2 SYNOPSIS
854
855 L<https://developer.work.weixin.qq.com/document/path/94882>
856
857 =head3 权限说明:
858
859 调用的应用需要满足如下的权限
860
861 应用类型 权限要求
862 自建应用 配置到「客户联系 可调用接口的应用」中
863 代开发应用 具有「管理客户联系规则组」权限
864 第三方应用 具有「管理客户联系规则组」权限
865
866 提示
867 应用仅能获取和管理由本应用创建的规则组标签
868
869 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
870
871 =head2 get_strategy_tag_list(access_token, hash);
872
873 获取指定规则组下的企业客户标签
874
875 =head2 SYNOPSIS
876
877 L<https://developer.work.weixin.qq.com/document/path/94882#获取指定规则组下的企业客户标签>
878
879 =head3 请求说明:
880
881 企业可通过此接口获取某个规则组内的企业客户标签详情。
882
883 =head4 请求包结构体为:
884
885 {
886 "strategy_id":1,
887 "tag_id":
888 [
889 "etXXXXXXXXXX",
890 "etYYYYYYYYYY"
891 ],
892 "group_id":
893 [
894 "etZZZZZZZZZZZZZ",
895 "etYYYYYYYYYYYYY"
896 ]
897 }
898
899 =head4 参数说明:
900
901 参数 必须 说明
902 access_token 是 调用接口凭证
903 strategy_id 否 规则组id
904 tag_id 否 要查询的标签id
905 group_id 否 要查询的标签组id,返回该标签组以及其下的所有标签信息
906
907 若tag_id和group_id均为空,则返回所有标签。
908 同时传递tag_id和group_id时,忽略tag_id,仅以group_id作为过滤条件。
909
910 =head3 RETURN 返回结果
911
912 {
913 "errcode": 0,
914 "errmsg": "ok",
915 "tag_group": [{
916 "group_id": "TAG_GROUPID1",
917 "group_name": "GOURP_NAME",
918 "create_time": 1557838797,
919 "order": 1,
920 "strategy_id":1,
921 "tag": [{
922 "id": "TAG_ID1",
923 "name": "NAME1",
924 "create_time": 1557838797,
925 "order": 1
926 },
927 {
928 "id": "TAG_ID2",
929 "name": "NAME2",
930 "create_time": 1557838797,
931 "order": 2
932 }
933 ]
934 }]
935 }
936
937 =head4 RETURN 参数说明
938
939 参数 说明
940 errcode 返回码
941 errmsg 对返回码的文本描述内容
942 tag_group 标签组列表
943 tag_group.group_id 标签组id
944 tag_group.group_name 标签组名称
945 tag_group.create_time 标签组创建时间
946 tag_group.order 标签组排序的次序值,order值大的排序靠前。有效的值范围是[0, 2^32)
947 tag_group.strategy_id 标签组所属的规则组id
948 tag_group.tag 标签组内的标签列表
949 tag_group.tag.id 标签id
950 tag_group.tag.name 标签名称
951 tag_group.tag.create_time 标签创建时间
952 tag_group.tag.order 标签排序的次序值,order值大的排序靠前。有效的值范围是[0, 2^32)
953
954 =cut
955
956 sub get_strategy_tag_list {
957 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
958 my $access_token = $_[0];
959 my $json = $_[1];
960 my $ua = LWP::UserAgent->new;
961 $ua->timeout(30);
962 $ua->env_proxy;
963
964 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_strategy_tag_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
965 if ($response->is_success) {
966 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
967 }
968
969 }
970 return 0;
971 }
972
973 =head2 add_strategy_tag(access_token, hash);
974
975 为指定规则组创建企业客户标签
976
977 =head2 SYNOPSIS
978
979 L<https://developer.work.weixin.qq.com/document/path/94882#为指定规则组创建企业客户标签>
980
981 =head3 请求说明:
982
983 企业可通过此接口向规则组中添加新的标签组和标签,每个企业的企业标签和规则组标签合计最多可配置10000个。注意,仅可在一级规则组下添加标签。
984
985 =head4 请求包结构体为:
986
987 {
988 "strategy_id":1,
989 "group_id": "GROUP_ID",
990 "group_name": "GROUP_NAME",
991 "order": 1,
992 "tag": [{
993 "name": "TAG_NAME_1",
994 "order": 1
995 },
996 {
997 "name": "TAG_NAME_2",
998 "order": 2
999 }
1000 ]
1001 }
1002
1003 =head4 参数说明:
1004
1005 参数 必须 说明
1006 access_token 是 调用接口凭证
1007 strategy_id 是 规则组id
1008 group_id 否 标签组id
1009 group_name 否 标签组名称,最长为30个字符
1010 order 否 标签组次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
1011 tag.name 是 添加的标签名称,最长为30个字符
1012 tag.order 否 标签次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
1013
1014 注意:
1015 如果填写了group_id参数,则group_name和标签组的order参数会被忽略。
1016 如果填写的group_name和此规则组下的其他标签组同名,则会将相关标签加入已存在的同名标签组下
1017 不支持创建空标签组。
1018 标签组内的标签不可同名,如果传入多个同名标签,则只会创建一个。
1019
1020 =head3 RETURN 返回结果
1021
1022 {
1023 "errcode": 0,
1024 "errmsg": "ok",
1025 "tag_group": {
1026 "group_id": "TAG_GROUPID1",
1027 "group_name": "GOURP_NAME",
1028 "create_time": 1557838797,
1029 "order": 1,
1030 "tag": [{
1031 "id": "TAG_ID1",
1032 "name": "NAME1",
1033 "create_time": 1557838797,
1034 "order": 1
1035 },
1036 {
1037 "id": "TAG_ID2",
1038 "name": "NAME2",
1039 "create_time": 1557838797,
1040 "order": 2
1041 }
1042 ]
1043 }
1044 }
1045
1046 =head4 RETURN 参数说明
1047
1048 参数 说明
1049 errcode 返回码
1050 errmsg 对返回码的文本描述内容
1051 tag_group.group_id 标签组id
1052 tag_group.group_name 标签组名称
1053 tag_group.create_time 标签组创建时间
1054 tag_group.order 标签组次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
1055 tag_group.tag 标签组内的标签列表
1056 tag_group.tag.id 新建标签id
1057 tag_group.tag.name 新建标签名称
1058 tag_group.tag.create_time 标签创建时间
1059 tag_group.tag.order 标签次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
1060
1061 =cut
1062
1063 sub add_strategy_tag {
1064 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1065 my $access_token = $_[0];
1066 my $json = $_[1];
1067 my $ua = LWP::UserAgent->new;
1068 $ua->timeout(30);
1069 $ua->env_proxy;
1070
1071 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_strategy_tag?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1072 if ($response->is_success) {
1073 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1074 }
1075
1076 }
1077 return 0;
1078 }
1079
1080 =head2 edit_strategy_tag(access_token, hash);
1081
1082 编辑指定规则组下的企业客户标签
1083
1084 =head2 SYNOPSIS
1085
1086 L<https://developer.work.weixin.qq.com/document/path/94882#编辑指定规则组下的企业客户标签>
1087
1088 =head3 请求说明:
1089
1090 企业可通过此接口编辑指定规则组下的客户标签/标签组的名称或次序值,但不可重新指定标签/标签组所属规则组。
1091
1092 =head4 请求包结构体为:
1093
1094 {
1095 "id": "TAG_ID",
1096 "name": "NEW_TAG_NAME",
1097 "order": 1
1098 }
1099
1100 =head4 参数说明:
1101
1102 参数 必须 说明
1103 access_token 是 调用接口凭证
1104 id 是 标签或标签组的id
1105 name 否 新的标签或标签组名称,最长为30个字符
1106 order 否 标签/标签组的次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
1107
1108 注意:修改后的标签组不能和已有的标签组重名,标签也不能和同一标签组下的其他标签重名。
1109
1110 =head3 RETURN 返回结果
1111
1112 {
1113 "errcode": 0,
1114 "errmsg": "ok"
1115 }
1116
1117 =head4 RETURN 参数说明
1118
1119 参数 说明
1120 errcode 返回码
1121 errmsg 对返回码的文本描述内容
1122
1123 =cut
1124
1125 sub edit_strategy_tag {
1126 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1127 my $access_token = $_[0];
1128 my $json = $_[1];
1129 my $ua = LWP::UserAgent->new;
1130 $ua->timeout(30);
1131 $ua->env_proxy;
1132
1133 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_strategy_tag?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1134 if ($response->is_success) {
1135 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1136 }
1137
1138 }
1139 return 0;
1140 }
1141
1142 =head2 del_strategy_tag(access_token, hash);
1143
1144 删除指定规则组下的企业客户标签
1145
1146 =head2 SYNOPSIS
1147
1148 L<https://developer.work.weixin.qq.com/document/path/94882#删除指定规则组下的企业客户标签>
1149
1150 =head3 请求说明:
1151
1152 企业可通过此接口删除某个规则组下的标签,或删除整个标签组。
1153
1154 =head4 请求包结构体为:
1155
1156 {
1157 "tag_id": [
1158 "TAG_ID_1",
1159 "TAG_ID_2"
1160 ],
1161 "group_id": [
1162 "GROUP_ID_1",
1163 "GROUP_ID_2"
1164 ],
1165 }
1166
1167 =head4 参数说明:
1168
1169 参数 必须 说明
1170 access_token 是 调用接口凭证
1171 tag_id 否 标签的id列表
1172 group_id 否 标签组的id列表
1173
1174 tag_id和group_id不可同时为空。
1175 如果一个标签组下所有的标签均被删除,则标签组会被自动删除。
1176
1177 =head3 RETURN 返回结果
1178
1179 {
1180 "errcode": 0,
1181 "errmsg": "ok"
1182 }
1183
1184 =head4 RETURN 参数说明
1185
1186 参数 说明
1187 errcode 返回码
1188 errmsg 对返回码的文本描述内容
1189
1190 =cut
1191
1192 sub del_strategy_tag {
1193 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1194 my $access_token = $_[0];
1195 my $json = $_[1];
1196 my $ua = LWP::UserAgent->new;
1197 $ua->timeout(30);
1198 $ua->env_proxy;
1199
1200 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_strategy_tag?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1201 if ($response->is_success) {
1202 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1203 }
1204
1205 }
1206 return 0;
1207 }
1208
1209 =head2 mark_tag(access_token, hash);
1210
1211 编辑客户企业标签
1212 最后更新:2023/12/01
1213
1214 =head2 SYNOPSIS
1215
1216 L<https://developer.work.weixin.qq.com/document/path/92118>
1217
1218 =head3 请求说明:
1219
1220 企业可通过此接口为指定成员的客户添加上由企业统一配置的标签;注意,每个成员对同一个客户最多可以添加3000个标签。
1221
1222 =head4 请求包结构体为:
1223
1224 {
1225 "userid":"zhangsan",
1226 "external_userid":"woAJ2GCAAAd1NPGHKSD4wKmE8Aabj9AAA",
1227 "add_tag":["TAGID1","TAGID2"],
1228 "remove_tag":["TAGID3","TAGID4"]
1229 }
1230
1231 =head4 参数说明:
1232
1233 参数 必须 说明
1234 access_token 是 调用接口凭证
1235 userid 是 添加外部联系人的userid
1236 external_userid 是 外部联系人userid
1237 add_tag 否 要标记的标签列表
1238 remove_tag 否 要移除的标签列表
1239
1240 请确保external_userid是userid的外部联系人。
1241 add_tag和remove_tag不可同时为空。
1242 同一个标签组下现已支持多个标签
1243
1244 =head3 权限说明
1245
1246 调用接口的应用需要满足如下的权限:
1247
1248 应用类型 权限要求
1249 自建应用 配置到「客户联系 可调用接口的应用」中
1250 代开发应用 具有「客户基础信息」权限
1251 第三方应用 具有「客户基础信息」权限
1252
1253 应用只能编辑可见范围内的成员添加的企业客户标签。
1254 如果要使用某个客户联系规则组下的企业客户标签,则规则组必须由同一个应用创建并且相关成员在规则组的管理范围内。
1255
1256 =head3 RETURN 返回结果
1257
1258 {
1259 "errcode": 0,
1260 "errmsg": "ok"
1261 }
1262
1263 =head4 RETURN 参数说明
1264
1265 参数 说明
1266 errcode 返回码
1267 errmsg 对返回码的文本描述内容
1268
1269 =cut
1270
1271 sub mark_tag {
1272 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1273 my $access_token = $_[0];
1274 my $json = $_[1];
1275 my $ua = LWP::UserAgent->new;
1276 $ua->timeout(30);
1277 $ua->env_proxy;
1278
1279 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1280 if ($response->is_success) {
1281 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1282 }
1283
1284 }
1285 return 0;
1286 }
1287
1288 =head2 get_unassigned_list(access_token, hash);
1289
1290 获取待分配的离职成员列表
1291 最后更新:2023/12/01
1292
1293 =head2 SYNOPSIS
1294
1295 L<https://developer.work.weixin.qq.com/document/path/92124>
1296
1297 =head3 请求说明:
1298
1299 企业和第三方可通过此接口,获取所有离职成员的客户列表,并可进一步调用分配离职成员的客户接口将这些客户重新分配给其他企业成员。
1300
1301 =head4 请求包结构体为:
1302
1303 {
1304 "page_id":0,
1305 "cursor":"",
1306 "page_size":100
1307 }
1308
1309 =head4 参数说明:
1310
1311 参数 必须 说明
1312 access_token 是 调用接口凭证
1313 page_id 否 分页查询,要查询页号,从0开始
1314 page_size 否 每次返回的最大记录数,默认为1000,最大值为1000
1315 cursor 否 分页查询游标,字符串类型,适用于数据量较大的情况,如果使用该参数则无需填写page_id,该参数由上一次调用返回
1316
1317 =head3 权限说明
1318
1319 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)
1320 第三方应用需拥有“企业客户权限->客户联系->分配离职成员的客户”权限
1321
1322 =head3 RETURN 返回结果
1323
1324 {
1325 "errcode":0,
1326 "errmsg":"ok",
1327 "info":[
1328 {
1329 "handover_userid":"zhangsan",
1330 "external_userid":"woAJ2GCAAAd4uL12hdfsdasassdDmAAAAA",
1331 "dimission_time":1550838571
1332 },
1333 {
1334 "handover_userid":"lisi",
1335 "external_userid":"wmAJ2GCAAAzLTI123ghsdfoGZNqqAAAA",
1336 "dimission_time":1550661468
1337 }
1338 ],
1339 "is_last":false,
1340 "next_cursor":"aSfwejksvhToiMMfFeIGZZ"
1341 }
1342
1343 =head4 RETURN 参数说明
1344
1345 参数 说明
1346 errcode 返回码
1347 errmsg 对返回码的文本描述内容
1348 info.handover_userid 离职成员的userid
1349 info.external_userid 外部联系人userid
1350 info.dimission_time 成员离职时间
1351 is_last 是否是最后一条记录
1352 next_cursor 分页查询游标,已经查完则返回空(""),使用page_id作为查询参数时不返回
1353
1354 =cut
1355
1356 sub get_unassigned_list {
1357 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1358 my $access_token = $_[0];
1359 my $json = $_[1];
1360 my $ua = LWP::UserAgent->new;
1361 $ua->timeout(30);
1362 $ua->env_proxy;
1363
1364 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_unassigned_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1365 if ($response->is_success) {
1366 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1367 }
1368
1369 }
1370 return 0;
1371 }
1372
1373 =head2 transfer_customer(access_token, hash);
1374
1375 分配在职成员的客户
1376 最后更新:2023/12/01
1377
1378 =head2 SYNOPSIS
1379
1380 L<https://developer.work.weixin.qq.com/document/path/92125>
1381
1382 =head3 请求说明:
1383
1384 企业可通过此接口,转接在职成员的客户给其他成员。
1385
1386 =head4 请求包结构体为:
1387
1388 {
1389 "handover_userid": "zhangsan",
1390 "takeover_userid": "lisi",
1391 "external_userid":
1392 [
1393 "woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA",
1394 "woAJ2GCAAAXtWyujaWJHDDGi0mACBBBB"
1395 ],
1396 "transfer_success_msg":"您好,您的服务已升级,后续将由我的同事李四@腾讯接替我的工作,继续为您服务。"
1397 }
1398
1399 =head4 参数说明:
1400
1401 参数 必须 说明
1402 access_token 是 调用接口凭证
1403 handover_userid 是 原跟进成员的userid
1404 takeover_userid 是 接替成员的userid
1405 external_userid 是 客户的external_userid列表,每次最多分配100个客户
1406 transfer_success_msg 否 转移成功后发给客户的消息,最多200个字符,不填则使用默认文案
1407
1408 提示
1409 原跟进成员和接替成员在最近一年内需要登录过至少一次企业微信。
1410
1411 external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。
1412 为保障客户服务体验,90个自然日内,在职成员的每位客户仅可被转接2次。
1413 如果接替成员在转接前已成为客户好友,则不会触发添加企业客户事件。
1414 如果客户曾经被接替成员转移给其他成员,其他成员再次将此客户转移给此接替成员时,不会触发添加企业客户事件。
1415
1416 =head3 权限说明
1417
1418 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
1419 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
1420 接替成员必须在此第三方应用或自建应用的可见范围内。
1421 接替成员需要配置了客户联系功能。
1422 接替成员需要在企业微信激活且已经过实名认证。
1423
1424 =head3 RETURN 返回结果
1425
1426 {
1427 "errcode": 0,
1428 "errmsg": "ok",
1429 "customer":
1430 [
1431 {
1432 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA",
1433 "errcode":40096
1434 },
1435 {
1436 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACBBBB",
1437 "errcode":0
1438 }
1439 ]
1440 }
1441
1442 =head4 RETURN 参数说明
1443
1444 参数 说明
1445 errcode 返回码
1446 errmsg 对返回码的文本描述内容
1447 customer.external_userid 客户的external_userid
1448 customer.errcode 对此客户进行分配的结果, 具体可参考全局错误码, 0表示成功发起接替,待24小时后自动接替,并不代表最终接替成功
1449
1450 原接口分配在职或离职成员的客户后续将不再更新维护,请使用新接口
1451
1452 =cut
1453
1454 sub transfer_customer {
1455 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1456 my $access_token = $_[0];
1457 my $json = $_[1];
1458 my $ua = LWP::UserAgent->new;
1459 $ua->timeout(30);
1460 $ua->env_proxy;
1461
1462 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/transfer_customer?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1463 if ($response->is_success) {
1464 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1465 }
1466
1467 }
1468 return 0;
1469 }
1470
1471 =head2 transfer_result(access_token, hash);
1472
1473 查询客户接替状态
1474 最后更新:2023/12/01
1475
1476 =head2 SYNOPSIS
1477
1478 L<https://developer.work.weixin.qq.com/document/path/94088>
1479
1480 =head3 请求说明:
1481
1482 企业和第三方可通过此接口查询在职成员的客户转接情况。
1483
1484 =head4 请求包结构体为:
1485
1486 {
1487 "handover_userid": "zhangsan",
1488 "takeover_userid": "lisi",
1489 "cursor":"CURSOR"
1490 }
1491
1492 =head4 参数说明:
1493
1494 参数 必须 说明
1495 access_token 是 调用接口凭证
1496 handover_userid 是 原添加成员的userid
1497 takeover_userid 是 接替成员的userid
1498 cursor 否 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
1499
1500 =head3 权限说明
1501
1502 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
1503 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
1504 接替成员必须在此第三方应用或自建应用的可见范围内。
1505
1506 =head3 RETURN 返回结果
1507
1508 {
1509 "errcode": 0,
1510 "errmsg": "ok",
1511 "customer":
1512 [
1513 {
1514 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACCCC",
1515 "status":1,
1516 "takeover_time":1588262400
1517 },
1518 {
1519 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACBBBB",
1520 "status":2,
1521 "takeover_time":1588482400
1522 },
1523 {
1524 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA",
1525 "status":3,
1526 "takeover_time":0
1527 }
1528 ],
1529 "next_cursor":"NEXT_CURSOR"
1530 }
1531
1532 =head4 RETURN 参数说明
1533
1534 参数 说明
1535 errcode 返回码
1536 errmsg 对返回码的文本描述内容
1537 customer.external_userid 转接客户的外部联系人userid
1538 customer.status 接替状态, 1-接替完毕 2-等待接替 3-客户拒绝 4-接替成员客户达到上限 5-无接替记录
1539 customer.takeover_time 接替客户的时间,如果是等待接替状态,则为未来的自动接替时间
1540 next_cursor 下个分页的起始cursor
1541
1542 原接口查询客户接替结果后续将不再更新维护,请使用新接口
1543
1544 =cut
1545
1546 sub transfer_result {
1547 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1548 my $access_token = $_[0];
1549 my $json = $_[1];
1550 my $ua = LWP::UserAgent->new;
1551 $ua->timeout(30);
1552 $ua->env_proxy;
1553
1554 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/transfer_result?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1555 if ($response->is_success) {
1556 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1557 }
1558
1559 }
1560 return 0;
1561 }
1562
1563 =head2 opengid_to_chatid(access_token, hash);
1564
1565 客户群opengid转换
1566 最后更新:2023/12/01
1567
1568 =head2 SYNOPSIS
1569
1570 L<https://developer.work.weixin.qq.com/document/path/94822>
1571
1572 =head3 请求说明:
1573
1574 用户在微信里的客户群里打开小程序时,某些场景下可以获取到群的opengid,如果该群是企业微信的客户群,则企业或第三方可以调用此接口将一个opengid转换为客户群chat_id
1575
1576 =head4 请求包结构体为:
1577
1578 {
1579 "opengid":"oAAAAAAA"
1580 }
1581
1582 =head4 参数说明:
1583
1584 参数 必须 说明
1585 access_token 是 调用接口凭证
1586 opengid 是 小程序在微信获取到的群ID,参见wx.getGroupEnterInfo
1587
1588 =head3 权限说明
1589
1590 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)
1591 第三方应用需具有“企业客户权限->客户基础信息”权限
1592 对于第三方/自建应用,群主必须在应用的可见范围
1593 仅支持企业服务人员创建的客户群
1594 仅可转换出自己企业下的客户群chat_id
1595
1596 =head3 RETURN 返回结果
1597
1598 {
1599 "errcode":0,
1600 "errmsg":"ok",
1601 "chat_id":"ooAAAAAAAAAAA"
1602 }
1603
1604 =head4 RETURN 参数说明
1605
1606 参数 说明
1607 errcode 返回码
1608 errmsg 对返回码的文本描述内容
1609 chat_id 客户群ID,可以用来调用获取客户群详情
1610
1611 =cut
1612
1613 sub opengid_to_chatid {
1614 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1615 my $access_token = $_[0];
1616 my $json = $_[1];
1617 my $ua = LWP::UserAgent->new;
1618 $ua->timeout(30);
1619 $ua->env_proxy;
1620
1621 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/opengid_to_chatid?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1622 if ($response->is_success) {
1623 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1624 }
1625
1626 }
1627 return 0;
1628 }
1629
1630 =head2 联系我与客户入群方式
1631
1632 客户联系「联系我」管理
1633 最后更新:2023/12/01
1634
1635 =head2 SYNOPSIS
1636
1637 L<https://developer.work.weixin.qq.com/document/path/92228>
1638
1639 =head3 权限说明
1640
1641 调用接口的应用需要满足如下的权限:
1642
1643 应用类型 权限要求
1644 自建应用 配置到「客户联系 可调用接口的应用」中
1645 代开发应用 具有「配置「联系我」二维码」权限
1646 第三方应用 具有「配置「联系我」二维码」权限
1647
1648 传入的成员和部门需要在此应用的可见范围内。
1649 配置的使用成员必须在企业微信激活且已经过实名认证且配置了客户联系功能。。
1650 临时会话的二维码具有有效期,添加企业成员后仅能在指定有效期内进行会话,仅支持医疗行业企业创建。
1651 临时会话模式可以配置会话结束时自动发送给用户的结束语。
1652
1653 =head2 add_contact_way(access_token, hash);
1654
1655 配置客户联系「联系我」方式
1656
1657 =head2 SYNOPSIS
1658
1659 L<https://developer.work.weixin.qq.com/document/path/92228#配置客户联系「联系我」方式>
1660
1661 =head3 请求说明:
1662
1663 企业可以在管理后台-客户联系-加客户中配置成员的「联系我」的二维码或者小程序按钮,客户通过扫描二维码或点击小程序上的按钮,即可获取成员联系方式,主动联系到成员。
1664 企业可通过此接口为具有客户联系功能的成员生成专属的「联系我」二维码或者「联系我」按钮。
1665 如果配置的是「联系我」按钮,需要开发者的小程序接入小程序插件。
1666
1667 注意:
1668 通过API添加的「联系我」不会在管理端进行展示,每个企业可通过API最多配置50万个「联系我」。
1669 用户需要妥善存储返回的config_id,config_id丢失可能导致用户无法编辑或删除「联系我」。
1670 临时会话模式不占用「联系我」数量,但每日最多添加10万个,并且仅支持单人。
1671 临时会话模式的二维码,添加好友完成后该二维码即刻失效。
1672
1673 =head4 请求包结构体为:
1674
1675 {
1676 "type" :1,
1677 "scene":1,
1678 "style":1,
1679 "remark":"渠道客户",
1680 "skip_verify":true,
1681 "state":"teststate",
1682 "user" : ["zhangsan", "lisi", "wangwu"],
1683 "party" : [2, 3],
1684 "is_temp":true,
1685 "expires_in":86400,
1686 "chat_expires_in":86400,
1687 "unionid":"oxTWIuGaIt6gTKsQRLau2M0AAAA",
1688 "is_exclusive":true,
1689 "conclusions":
1690 {
1691 "text":
1692 {
1693 "content":"文本消息内容"
1694 },
1695 "image":
1696 {
1697 "media_id": "MEDIA_ID"
1698 },
1699 "link":
1700 {
1701 "title": "消息标题",
1702 "picurl": "https://example.pic.com/path",
1703 "desc": "消息描述",
1704 "url": "https://example.link.com/path"
1705 },
1706 "miniprogram":
1707 {
1708 "title": "消息标题",
1709 "pic_media_id": "MEDIA_ID",
1710 "appid": "wx8bd80126147dfAAA",
1711 "page": "/path/index.html"
1712 }
1713 }
1714 }
1715
1716 =head4 参数说明:
1717
1718 参数 必须 说明
1719 access_token 是 调用接口凭证
1720 type 是 联系方式类型,1-单人, 2-多人
1721 scene 是 场景,1-在小程序中联系,2-通过二维码联系
1722 style 否 在小程序中联系时使用的控件样式,详见附表
1723 remark 否 联系方式的备注信息,用于助记,不超过30个字符
1724 skip_verify 否 外部客户添加时是否无需验证,默认为true
1725 state 否 企业自定义的state参数,用于区分不同的添加渠道,在调用“获取外部联系人详情”时会返回该参数值,不超过30个字符
1726 user 否 使用该联系方式的用户userID列表,在type为1时为必填,且只能有一个
1727 party 否 使用该联系方式的部门id列表,只在type为2时有效
1728 is_temp 否 是否临时会话模式,true表示使用临时会话模式,默认为false
1729 expires_in 否 临时会话二维码有效期,以秒为单位。该参数仅在is_temp为true时有效,默认7天,最多为14天
1730 chat_expires_in 否 临时会话有效期,以秒为单位。该参数仅在is_temp为true时有效,默认为添加好友后24小时,最多为14天
1731 unionid 否 可进行临时会话的客户unionid,该参数仅在is_temp为true时有效,如不指定则不进行限制
1732 is_exclusive 否 是否开启同一外部企业客户只能添加同一个员工,默认为否,开启后,同一个企业的客户会优先添加到同一个跟进人
1733 conclusions 否 结束语,会话结束时自动发送给客户,可参考“结束语定义”,仅在is_temp为true时有效
1734
1735 =head3 权限说明
1736
1737 注意,每个联系方式最多配置100个使用成员(包含部门展开后的成员)
1738 当设置为临时会话模式时(即is_temp为true),联系人仅支持配置为单人,暂不支持多人
1739 使用unionid需要调用方(企业或服务商)的企业微信“客户联系”中已绑定微信开发者账户
1740
1741 =head3 RETURN 返回结果
1742
1743 {
1744 "errcode": 0,
1745 "errmsg": "ok",
1746 "config_id":"42b34949e138eb6e027c123cba77fAAA",
1747 "qr_code":"http://p.qpic.cn/wwhead/duc2TvpEgSdicZ9RrdUtBkv2UiaA/0"
1748 }
1749
1750 =head4 RETURN 参数说明
1751
1752 参数 说明
1753 errcode 返回码
1754 errmsg 对返回码的文本描述内容
1755 config_id 新增联系方式的配置id
1756 qr_code 联系我二维码链接,仅在scene为2时返回
1757
1758 =cut
1759
1760 sub add_contact_way {
1761 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1762 my $access_token = $_[0];
1763 my $json = $_[1];
1764 my $ua = LWP::UserAgent->new;
1765 $ua->timeout(30);
1766 $ua->env_proxy;
1767
1768 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_contact_way?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1769 if ($response->is_success) {
1770 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1771 }
1772
1773 }
1774 return 0;
1775 }
1776
1777 =head2 get_contact_way(access_token, hash);
1778
1779 获取企业已配置的「联系我」方式
1780
1781 =head2 SYNOPSIS
1782
1783 L<https://developer.work.weixin.qq.com/document/path/92228#获取企业已配置的「联系我」方式>
1784
1785 =head3 请求说明:
1786
1787 获取企业配置的「联系我」二维码和「联系我」小程序按钮。
1788
1789 =head4 请求包结构体为:
1790
1791 {
1792 "config_id":"42b34949e138eb6e027c123cba77fad7"
1793 }
1794
1795 =head4 参数说明:
1796
1797 参数 必须 说明
1798 access_token 是 调用接口凭证
1799 config_id 是 联系方式的配置id
1800
1801 =head3 权限说明
1802
1803 =head3 RETURN 返回结果
1804
1805 {
1806 "errcode": 0,
1807 "errmsg": "ok",
1808 "contact_way":
1809 {
1810 "config_id":"42b34949e138eb6e027c123cba77fAAA",
1811 "type":1,
1812 "scene":1,
1813 "style":2,
1814 "remark":"test remark",
1815 "skip_verify":true,
1816 "state":"teststate",
1817 "qr_code":"http://p.qpic.cn/wwhead/duc2TvpEgSdicZ9RrdUtBkv2UiaA/0",
1818 "user" : ["zhangsan", "lisi", "wangwu"],
1819 "party" : [2, 3],
1820 "is_temp":true,
1821 "expires_in":86400,
1822 "chat_expires_in":86400,
1823 "unionid":"oxTWIuGaIt6gTKsQRLau2M0AAAA",
1824 "conclusions":
1825 {
1826 "text":
1827 {
1828 "content":"文本消息内容"
1829 },
1830 "image":
1831 {
1832 "pic_url": "http://p.qpic.cn/pic_wework/XXXXX"
1833 },
1834 "link":
1835 {
1836 "title": "消息标题",
1837 "picurl": "https://example.pic.com/path",
1838 "desc": "消息描述",
1839 "url": "https://example.link.com/path"
1840 },
1841 "miniprogram":
1842 {
1843 "title": "消息标题",
1844 "pic_media_id": "MEDIA_ID",
1845 "appid": "wx8bd80126147dfAAA",
1846 "page": "/path/index"
1847 }
1848 }
1849 }
1850 }
1851
1852 =head4 RETURN 参数说明
1853
1854 参数 说明
1855 errcode 返回码
1856 errmsg 对返回码的文本描述内容
1857 config_id 新增联系方式的配置id
1858 type 联系方式类型,1-单人,2-多人
1859 scene 场景,1-在小程序中联系,2-通过二维码联系
1860 is_temp 是否临时会话模式,默认为false,true表示使用临时会话模式
1861 remark 联系方式的备注信息,用于助记
1862 skip_verify 外部客户添加时是否无需验证
1863 state 企业自定义的state参数,用于区分不同的添加渠道,在调用“获取外部联系人详情”时会返回该参数值
1864 style 小程序中联系按钮的样式,仅在scene为1时返回,详见附录
1865 qr_code 联系二维码的URL,仅在scene为2时返回
1866 user 使用该联系方式的用户userID列表
1867 party 使用该联系方式的部门id列表
1868 expires_in 临时会话二维码有效期,以秒为单位
1869 chat_expires_in 临时会话有效期,以秒为单位
1870 unionid 可进行临时会话的客户unionid
1871 conclusions 结束语,可参考“结束语定义”
1872
1873 =cut
1874
1875 sub get_contact_way {
1876 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1877 my $access_token = $_[0];
1878 my $json = $_[1];
1879 my $ua = LWP::UserAgent->new;
1880 $ua->timeout(30);
1881 $ua->env_proxy;
1882
1883 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_contact_way?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1884 if ($response->is_success) {
1885 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1886 }
1887
1888 }
1889 return 0;
1890 }
1891
1892 =head2 list_contact_way(access_token, hash);
1893
1894 获取企业已配置的「联系我」列表
1895
1896 =head2 SYNOPSIS
1897
1898 L<https://developer.work.weixin.qq.com/document/path/92228#获取企业已配置的「联系我」列表>
1899
1900 =head3 请求说明:
1901
1902 获取企业配置的「联系我」二维码和「联系我」小程序插件列表。不包含临时会话。
1903 注意,该接口仅可获取2021年7月10日以后创建的「联系我」
1904
1905 =head4 请求包结构体为:
1906
1907 {
1908 "start_time":1622476800,
1909 "end_time":1625068800,
1910 "cursor":"CURSOR",
1911 "limit":1000
1912 }
1913
1914 =head4 参数说明:
1915
1916 参数 必须 说明
1917 access_token 是 调用接口凭证
1918 start_time 否 「联系我」创建起始时间戳, 默认为90天前
1919 end_time 否 「联系我」创建结束时间戳, 默认为当前时间
1920 cursor 否 分页查询使用的游标,为上次请求返回的 next_cursor
1921 limit 否 每次查询的分页大小,默认为100条,最多支持1000条
1922
1923 =head3 权限说明
1924
1925 =head3 RETURN 返回结果
1926
1927 {
1928 "errcode": 0,
1929 "errmsg": "ok",
1930 "contact_way":
1931 [
1932 {
1933 "config_id":"534b63270045c9ABiKEE814ef56d91c62f"
1934 },
1935 {
1936 "config_id":"87bBiKEE811c62f63270041c62f5c9A4ef"
1937 }
1938 ],
1939 "next_cursor":"NEXT_CURSOR"
1940 }
1941
1942 =head4 RETURN 参数说明
1943
1944 参数 说明
1945 errcode 返回码
1946 errmsg 对返回码的文本描述内容
1947 contact_way.config_id 联系方式的配置id
1948 next_cursor 分页参数,用于查询下一个分页的数据,为空时表示没有更多的分页
1949
1950 =cut
1951
1952 sub list_contact_way {
1953 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
1954 my $access_token = $_[0];
1955 my $json = $_[1];
1956 my $ua = LWP::UserAgent->new;
1957 $ua->timeout(30);
1958 $ua->env_proxy;
1959
1960 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list_contact_way?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
1961 if ($response->is_success) {
1962 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
1963 }
1964
1965 }
1966 return 0;
1967 }
1968
1969 =head2 update_contact_way(access_token, hash);
1970
1971 更新企业已配置的「联系我」方式
1972
1973 =head2 SYNOPSIS
1974
1975 L<https://developer.work.weixin.qq.com/document/path/92228#更新企业已配置的「联系我」方式>
1976
1977 =head3 请求说明:
1978
1979 更新企业配置的「联系我」二维码和「联系我」小程序按钮中的信息,如使用人员和备注等。
1980
1981 =head4 请求包结构体为:
1982
1983 {
1984 "config_id":"42b34949e138eb6e027c123cba77fAAA",
1985 "remark":"渠道客户",
1986 "skip_verify":true,
1987 "style":1,
1988 "state":"teststate",
1989 "user" : ["zhangsan", "lisi", "wangwu"],
1990 "party" : [2, 3],
1991 "expires_in":86400,
1992 "chat_expires_in":86400,
1993 "unionid":"oxTWIuGaIt6gTKsQRLau2M0AAAA",
1994 "conclusions":
1995 {
1996 "text":
1997 {
1998 "content":"文本消息内容"
1999 },
2000 "image":
2001 {
2002 "media_id": "MEDIA_ID"
2003 },
2004 "link":
2005 {
2006 "title": "消息标题",
2007 "picurl": "https://example.pic.com/path",
2008 "desc": "消息描述",
2009 "url": "https://example.link.com/path"
2010 },
2011 "miniprogram":
2012 {
2013 "title": "消息标题",
2014 "pic_media_id": "MEDIA_ID",
2015 "appid": "wx8bd80126147dfAAA",
2016 "page": "/path/index"
2017 }
2018 }
2019 }
2020
2021 =head4 参数说明:
2022
2023 参数 必须 说明
2024 access_token 是 调用接口凭证
2025 config_id 是 企业联系方式的配置id
2026 remark 否 联系方式的备注信息,不超过30个字符,将覆盖之前的备注
2027 skip_verify 否 外部客户添加时是否无需验证
2028 style 否 样式,只针对“在小程序中联系”的配置生效
2029 state 否 企业自定义的state参数,用于区分不同的添加渠道,在调用“获取外部联系人详情”时会返回该参数值
2030 user 否 使用该联系方式的用户列表,将覆盖原有用户列表
2031 party 否 使用该联系方式的部门列表,将覆盖原有部门列表,只在配置的type为2时有效
2032 expires_in 否 临时会话二维码有效期,以秒为单位,该参数仅在临时会话模式下有效
2033 chat_expires_in 否 临时会话有效期,以秒为单位,该参数仅在临时会话模式下有效
2034 unionid 否 可进行临时会话的客户unionid,该参数仅在临时会话模式有效,如不指定则不进行限制
2035 conclusions 否 结束语,会话结束时自动发送给客户,可参考“结束语定义”,仅临时会话模式(is_temp为true)可设置
2036
2037 注意:已失效的临时会话联系方式无法进行编辑
2038 当临时会话模式时(即is_temp为true),联系人仅支持配置为单人,暂不支持多人
2039
2040 =head3 权限说明
2041
2042 =head3 RETURN 返回结果
2043
2044 {
2045 "errcode": 0,
2046 "errmsg": "ok"
2047 }
2048
2049 =head4 RETURN 参数说明
2050
2051 参数 说明
2052 errcode 返回码
2053 errmsg 对返回码的文本描述内容
2054
2055 =cut
2056
2057 sub update_contact_way {
2058 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2059 my $access_token = $_[0];
2060 my $json = $_[1];
2061 my $ua = LWP::UserAgent->new;
2062 $ua->timeout(30);
2063 $ua->env_proxy;
2064
2065 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_contact_way?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2066 if ($response->is_success) {
2067 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2068 }
2069
2070 }
2071 return 0;
2072 }
2073
2074 =head2 del_contact_way(access_token, hash);
2075
2076 删除企业已配置的「联系我」方式
2077
2078 =head2 SYNOPSIS
2079
2080 L<https://developer.work.weixin.qq.com/document/path/92228#删除企业已配置的「联系我」方式>
2081
2082 =head3 请求说明:
2083
2084 删除一个已配置的「联系我」二维码或者「联系我」小程序按钮。
2085
2086 =head4 请求包结构体为:
2087
2088 {
2089 "config_id":"42b34949e138eb6e027c123cba77fAAA"
2090 }
2091
2092 =head4 参数说明:
2093
2094 参数 必须 说明
2095 access_token 是 调用接口凭证
2096 config_id 是 企业联系方式的配置id
2097
2098 =head3 权限说明
2099
2100 =head3 RETURN 返回结果
2101
2102 {
2103 "errcode": 0,
2104 "errmsg": "ok"
2105 }
2106
2107 =head4 RETURN 参数说明
2108
2109 参数 说明
2110 errcode 返回码
2111 errmsg 对返回码的文本描述内容
2112
2113 =cut
2114
2115 sub del_contact_way {
2116 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2117 my $access_token = $_[0];
2118 my $json = $_[1];
2119 my $ua = LWP::UserAgent->new;
2120 $ua->timeout(30);
2121 $ua->env_proxy;
2122
2123 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_contact_way?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2124 if ($response->is_success) {
2125 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2126 }
2127
2128 }
2129 return 0;
2130 }
2131
2132 =head2 close_temp_chat(access_token, hash);
2133
2134 结束临时会话
2135
2136 =head2 SYNOPSIS
2137
2138 L<https://developer.work.weixin.qq.com/document/path/92228#结束临时会话>
2139
2140 =head3 请求说明:
2141
2142 将指定的企业成员和客户之前的临时会话断开,断开前会自动下发已配置的结束语。
2143
2144 =head4 请求包结构体为:
2145
2146 {
2147 "userid":"zhangyisheng",
2148 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACHAAA"
2149 }
2150
2151 =head4 参数说明:
2152
2153 参数 必须 说明
2154 access_token 是 调用接口凭证
2155 userid 是 企业成员的userid
2156 external_userid 是 客户的外部联系人userid
2157
2158 注意:请保证传入的企业成员和客户之间有仍然有效的临时会话, 通过其他方式的添加外部联系人无法通过此接口关闭会话。
2159
2160 =head3 权限说明
2161
2162 =head3 RETURN 返回结果
2163
2164 {
2165 "errcode": 0,
2166 "errmsg": "ok"
2167 }
2168
2169 =head4 RETURN 参数说明
2170
2171 参数 说明
2172 errcode 返回码
2173 errmsg 对返回码的文本描述内容
2174
2175 =head3 结束语定义
2176
2177 =head4 字段内容:
2178
2179 "conclusions":
2180 {
2181 "text":
2182 {
2183 "content":"文本消息内容"
2184 },
2185 "image":
2186 {
2187 "media_id": "MEDIA_ID",
2188 "pic_url": "http://p.qpic.cn/pic_wework/XXXXX"
2189 },
2190 "link":
2191 {
2192 "title": "消息标题",
2193 "picurl": "https://example.pic.com/path",
2194 "desc": "消息描述",
2195 "url": "https://example.link.com/path"
2196 },
2197 "miniprogram":
2198 {
2199 "title": "消息标题",
2200 "pic_media_id": "MEDIA_ID",
2201 "appid": "wx8bd80126147dfAAA",
2202 "page": "/path/index"
2203 }
2204 }
2205 }
2206
2207 =head4 参数说明
2208
2209 参数 说明
2210 text.content 消息文本内容,最长为4000字节
2211 image.media_id 图片的media_id
2212 image.pic_url 图片的url
2213 link.title 图文消息标题,最长为128字节
2214 link.picurl 图文消息封面的url
2215 link.desc 图文消息的描述,最长为512字节
2216 link.url 图文消息的链接
2217 miniprogram.title 小程序消息标题,最长为64字节
2218 miniprogram.pic_media_id 小程序消息封面的mediaid,封面图建议尺寸为520*416
2219 miniprogram.appid 小程序appid,必须是关联到企业的小程序应用
2220 miniprogram.page 小程序page路径
2221
2222 text、image、link和miniprogram四者不能同时为空;
2223 text与另外三者可以同时发送,此时将会以两条消息的形式触达客户;
2224 image、link和miniprogram只能有一个,如果三者同时填,则按image、link、miniprogram的优先顺序取参,也就是说,如果image与link同时传值,则只有image生效;
2225 media_id可以通过素材管理接口获得;
2226 构造结束语使用image消息时,只能填写meida_id字段,获取含有image结构的联系我方式时,返回pic_url字段。
2227
2228 =cut
2229
2230 sub close_temp_chat {
2231 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2232 my $access_token = $_[0];
2233 my $json = $_[1];
2234 my $ua = LWP::UserAgent->new;
2235 $ua->timeout(30);
2236 $ua->env_proxy;
2237
2238 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/close_temp_chat?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2239 if ($response->is_success) {
2240 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2241 }
2242
2243 }
2244 return 0;
2245 }
2246
2247 =head2 客户朋友圈
2248
2249 企业发表内容到客户的朋友圈
2250 最后更新:2023/12/20
2251
2252 =head2 SYNOPSIS
2253
2254 L<https://developer.work.weixin.qq.com/document/path/95094>
2255
2256 =head2 add_moment_task(access_token, hash);
2257
2258 创建发表任务
2259
2260 =head2 SYNOPSIS
2261
2262 L<https://developer.work.weixin.qq.com/document/path/95094#创建发表任务>
2263
2264 =head3 请求说明:
2265
2266 企业和第三方应用可通过该接口创建客户朋友圈的发表任务。
2267
2268 =head4 请求包结构体为:
2269
2270 {
2271 "text": {
2272 "content": "文本消息内容"
2273 },
2274 "attachments": [
2275 {
2276 "msgtype": "image",
2277 "image": {
2278 "media_id": "MEDIA_ID"
2279 }
2280 },
2281 {
2282 "msgtype": "video",
2283 "video": {
2284 "media_id": "MEDIA_ID"
2285 }
2286 },
2287 {
2288 "msgtype": "link",
2289 "link": {
2290 "title": "消息标题",
2291 "url": "https://example.link.com/path",
2292 "media_id": "MEDIA_ID"
2293 }
2294 }
2295 ],
2296 "visible_range":{
2297 "sender_list":{
2298 "user_list":["zhangshan","lisi"],
2299 "department_list":[2,3]
2300 },
2301 "external_contact_list":{
2302 "tag_list":[ "etXXXXXXXXXX", "etYYYYYYYYYY"]
2303 }
2304 }
2305 }
2306
2307 =head4 参数说明:
2308
2309 参数 必须 说明
2310 access_token 调用接口凭证
2311 visible_range 否 指定的发表范围;若未指定,则表示执行者为应用可见范围内所有成员
2312 sender_list 否 发表任务的执行者列表,详见下文的“可见范围说明”
2313 sender_list.user_list 否 发表任务的执行者用户列表,最多支持10万个
2314 sender_list.department_list 否 发表任务的执行者部门列表
2315 external_contact_list 否 可见到该朋友圈的客户列表,详见下文的“可见范围说明”
2316 external_contact_list.tag_list 否 可见到该朋友圈的客户标签列表
2317 text 否 文本消息
2318 text.content 否 消息文本内容,不能与附件同时为空,最多支持传入2000个字符,若超出长度报错'invalid text size'
2319 attachments 否 附件,不能与text.content同时为空,最多支持9个图片类型,或者1个视频,或者1个链接。类型只能三选一,若传了不同类型,报错'invalid attachments msgtype'
2320 msgtype 是 附件类型,可选image、link或者video
2321 image 否 图片消息附件。普通图片:建议不超过 1440 x 1080。图片不超过10M。最多支持传入9个;超过9个报错'invalid attachments size'
2322 image.media_id 是 图片的素材id。可通过上传附件资源接口获得
2323 link 否 图文消息附件。只支持1个;若超过1个报错'invalid attachments size'
2324 link.title 否 图文消息标题,最多64个字节
2325 link.url 是 图文消息链接
2326 link.media_id 是 图片链接封面,普通图片:建议不超过 1440 x 1080,可通过上传附件资源接口获得
2327 video 否 视频消息附件,建议不超过 1280 x 720,帧率 30 FPS,视频码率 1.67 Mbps,最长不超过30S,最大不超过10MB。只支持1个;若超过1个报错'invalid attachments size'
2328 video.media_id 是 视频的素材id,未填写报错"invalid msg"。可通过上传附件资源接口获得
2329
2330 =head3 可见范围说明
2331
2332 visible_range,分以下几种情况:
2333
2334 若只指定sender_list,则可见的客户范围为该部分执行者的客户,目前执行者支持传userid与部门id列表,注意不在应用可见范围内的执行者会被忽略。
2335 若只指定external_contact_list,即指定了可见该朋友圈的目标客户,此时会将该发表任务推给这些目标客户的应用可见范围内的跟进人。
2336 若同时指定sender_list以及external_contact_list,会将该发表任务推送给sender_list指定的且在应用可见范围内的执行者,执行者发表后仅external_contact_list指定的客户可见。
2337 若未指定visible_range,则可见客户的范围为该应用可见范围内执行者的客户,执行者为应用可见范围内所有成员。
2338
2339 注:若指定external_contact_list列表,则该条朋友圈为部分可见;否则为公开
2340
2341 =head3 权限说明
2342
2343 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
2344 自建应用调用,只会返回应用可见范围内用户的发送情况。
2345 第三方应用或代开发自建应用调用需要企业授权客户朋友圈下发表到成员客户的朋友圈的权限
2346 企业每分钟创建朋友圈的频率:10条/分钟
2347 企业每个月允许通过api创建的朋友圈次数限制:10万
2348
2349 =head3 RETURN 返回结果
2350
2351 {
2352 "errcode":0,
2353 "errmsg":"ok",
2354 "jobid":"xxxx"
2355 }
2356
2357 =head4 RETURN 参数说明
2358
2359 参数 说明
2360 errcode 返回码
2361 errmsg 对返回码的文本描述内容
2362 jobid 异步任务id,最大长度为64字节,24小时有效;可使用获取发表朋友圈任务结果查询任务状态
2363
2364 =cut
2365
2366 sub add_moment_task {
2367 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2368 my $access_token = $_[0];
2369 my $json = $_[1];
2370 my $ua = LWP::UserAgent->new;
2371 $ua->timeout(30);
2372 $ua->env_proxy;
2373
2374 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_moment_task?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2375 if ($response->is_success) {
2376 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2377 }
2378
2379 }
2380 return 0;
2381 }
2382
2383 =head2 get_moment_task_result(access_token, hash);
2384
2385 获取任务创建结果
2386
2387 =head2 SYNOPSIS
2388
2389 L<https://developer.work.weixin.qq.com/document/path/95094#获取任务创建结果>
2390
2391 =head3 请求说明:
2392
2393 由于发表任务的创建是异步执行的,应用需要再调用该接口以获取创建的结果。
2394
2395 =head4 参数说明:
2396
2397 参数 必须 说明
2398 access_token 调用接口凭证
2399 jobid 是 异步任务id,最大长度为64字节,由创建发表内容到客户朋友圈任务接口获取
2400
2401 =head3 权限说明
2402
2403 只能查询已经提交过的历史任务。
2404
2405 =head3 RETURN 返回结果
2406
2407 {
2408 "errcode": 0,
2409 "errmsg": "ok",
2410 "status": 1,
2411 "type": "add_moment_task",
2412 "result": {
2413 "errcode":0,
2414 "errmsg":"ok"
2415 "moment_id":"xxxx",
2416 "invalid_sender_list":{
2417 "user_list":["zhangshan","lisi"],
2418 "department_list":[2,3]
2419 },
2420 "invalid_external_contact_list":{
2421 "tag_list":["xxx"]
2422 }
2423 }
2424 }
2425
2426 =head4 RETURN 参数说明
2427
2428 参数 说明
2429 errcode 返回码
2430 errmsg 对返回码的文本描述内容
2431 status 任务状态,整型,1表示开始创建任务,2表示正在创建任务中,3表示创建任务已完成
2432 type 操作类型,字节串,此处固定为add_moment_task
2433 result 详细的处理结果。当任务完成后此字段有效
2434 result.errcode 返回码
2435 result.errmsg 对返回码的文本描述内容
2436 result.moment_id 朋友圈id,可通过获取客户朋友圈企业发表的列表接口获取朋友圈企业发表的列表
2437 result.invalid_sender_list 不合法的执行者列表,包括不存在的id以及不在应用可见范围内的部门或者成员
2438
2439 =cut
2440
2441 sub get_moment_task_result {
2442 if ( @_ && $_[0] && $_[1] ) {
2443 my $access_token = $_[0];
2444 my $jobid = $_[1];
2445 my $ua = LWP::UserAgent->new;
2446 $ua->timeout(30);
2447 $ua->env_proxy;
2448
2449 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_task_result?access_token=$access_token&jobid=$jobid");
2450 if ($response->is_success) {
2451 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2452 }
2453
2454 }
2455 return 0;
2456 }
2457
2458 =head2 cancel_moment_task(access_token, hash);
2459
2460 停止发表企业朋友圈
2461 最后更新:2023/12/01
2462
2463 =head2 SYNOPSIS
2464
2465 L<https://developer.work.weixin.qq.com/document/path/97612>
2466
2467 =head3 请求说明:
2468
2469 企业和第三方应用可调用此接口,停止尚未发送的企业朋友圈发送任务。
2470
2471 =head4 请求包结构体为:
2472
2473 {
2474 "moment_id":"momXXXXXXXXXX"
2475 }
2476
2477 =head4 参数说明:
2478
2479 参数 必须 说明
2480 access_token 调用接口凭证
2481 moment_id 是 朋友圈id,可通过获取客户朋友圈企业发表的列表接口获取朋友圈企业发表的列表
2482
2483 =head3 权限说明
2484
2485 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
2486 第三方应用或代开发自建应用调用需要企业授权客户朋友圈下发表到成员客户的朋友圈的权限
2487
2488 =head3 RETURN 返回结果
2489
2490 {
2491 "errcode":0,
2492 "errmsg":"ok"
2493 }
2494
2495 =head4 RETURN 参数说明
2496
2497 参数 说明
2498 errcode 返回码
2499 errmsg 对返回码的文本描述内容
2500
2501 注意,此接口无法撤回已经发表到客户朋友圈的信息。
2502
2503 =cut
2504
2505 sub cancel_moment_task {
2506 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2507 my $access_token = $_[0];
2508 my $json = $_[1];
2509 my $ua = LWP::UserAgent->new;
2510 $ua->timeout(30);
2511 $ua->env_proxy;
2512
2513 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/cancel_moment_task?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2514 if ($response->is_success) {
2515 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2516 }
2517
2518 }
2519 return 0;
2520 }
2521
2522 =head2 客户朋友圈
2523
2524 获取客户朋友圈全部的发表记录
2525 最后更新:2023/12/01
2526
2527 =head2 SYNOPSIS
2528
2529 L<https://developer.work.weixin.qq.com/document/path/93333>
2530
2531 =head2 get_moment_list(access_token, hash);
2532
2533 获取企业全部的发表列表
2534
2535 =head2 SYNOPSIS
2536
2537 L<https://developer.work.weixin.qq.com/document/path/93333#获取企业全部的发表列表>
2538
2539 =head3 请求说明:
2540
2541 企业和第三方应用可通过该接口获取企业全部的发表内容。企业和第三方应用可通过该接口创建客户朋友圈的发表任务。
2542
2543 =head4 请求包结构体为:
2544
2545 {
2546 "start_time":1605000000,
2547 "end_time":1605172726,
2548 "creator":"zhangsan",
2549 "filter_type":1,
2550 "cursor":"CURSOR",
2551 "limit":10
2552 }
2553
2554 =head4 参数说明:
2555
2556 参数 必须 说明
2557 access_token 是 调用接口凭证
2558 start_time 是 朋友圈记录开始时间。Unix时间戳
2559 end_time 是 朋友圈记录结束时间。Unix时间戳
2560 creator 否 朋友圈创建人的userid
2561 filter_type 否 朋友圈类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型
2562 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
2563 limit 否 返回的最大记录数,整型,最大值20,默认值20,超过最大值时取默认值
2564
2565 =head3 补充说明:
2566
2567 朋友圈记录的起止时间间隔不能超过30天
2568 在朋友圈发表列表中,按时间只能取到(start_time, end_time)范围内的数据
2569 web管理端会展示企业成员所有已经发表的朋友圈(包括已经删除朋友圈),而API接口将不会返回已经删除的朋友圈记录
2570
2571 =head3 权限说明
2572
2573 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
2574 自建应用调用,只会返回应用可见范围内用户的发送情况。
2575 第三方应用调用需要企业授权客户朋友圈下获取企业全部的发表记录的权限
2576
2577 =head3 RETURN 返回结果
2578
2579 {
2580 "errcode":0,
2581 "errmsg":"ok",
2582 "next_cursor":"CURSOR",
2583 "moment_list":[
2584 {
2585 "moment_id":"momxxx",
2586 "creator":"xxxx",
2587 "create_time":1605000000,
2588 "create_type":1,
2589 "visible_type":1,
2590 "text":{
2591 "content":"test"
2592 },
2593 "image":[
2594 {"media_id":"WWCISP_xxxxx"}
2595 ],
2596 "video":{
2597 "media_id":"WWCISP_xxxxx",
2598 "thumb_media_id":"WWCISP_xxxxx"
2599 },
2600 "link":{
2601 "title":"腾讯网-QQ.COM",
2602 "url":"https://www.qq.com"
2603 },
2604 "location":{
2605 "latitude":"23.10647",
2606 "longitude":"113.32446",
2607 "name":"广州市 · 广州塔"
2608 }
2609 }
2610 ]
2611 }
2612
2613 =head4 RETURN 参数说明
2614
2615 参数 说明
2616 errcode 返回码
2617 errmsg 对返回码的文本描述内容
2618 next_cursor 分页游标,下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
2619 moment_list 朋友圈列表
2620 moment_list.moment_id 朋友圈id
2621 moment_list.creator 朋友圈创建者userid,企业发表内容到客户的朋友圈接口创建的朋友圈不再返回该字段
2622 moment_list.create_time 创建时间
2623 moment_list.create_type 朋友圈创建来源。0:企业 1:个人
2624 moment_list.visible_type 可见范围类型。0:部分可见 1:公开
2625 moment_list.text.content 文本消息结构
2626 moment_list.image.media_id 图片的media_id列表,可以通过获取临时素材下载资源
2627 moment_list.video.media_id 视频media_id,可以通过获取临时素材下载资源
2628 moment_list.video.thumb_media_id 视频封面media_id,可以通过获取临时素材下载资源
2629 moment_list.link.title 网页链接标题
2630 moment_list.link.url 网页链接url
2631 moment_list.location.latitude 地理位置纬度
2632 moment_list.location.longitude 地理位置经度
2633 moment_list.location.name 地理位置名称
2634
2635 =cut
2636
2637 sub get_moment_list {
2638 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2639 my $access_token = $_[0];
2640 my $json = $_[1];
2641 my $ua = LWP::UserAgent->new;
2642 $ua->timeout(30);
2643 $ua->env_proxy;
2644
2645 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2646 if ($response->is_success) {
2647 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2648 }
2649
2650 }
2651 return 0;
2652 }
2653
2654 =head2 get_moment_task(access_token, hash);
2655
2656 获取客户朋友圈企业发表的列表
2657
2658 =head2 SYNOPSIS
2659
2660 L<https://developer.work.weixin.qq.com/document/path/93333#获取客户朋友圈企业发表的列表>
2661
2662 =head3 请求说明:
2663
2664 企业和第三方应用可通过该接口获取企业发表的朋友圈成员执行情况
2665
2666 =head4 请求包结构体为:
2667
2668 {
2669 "moment_id":"momxxx",
2670 "cursor":"CURSOR",
2671 "limit":10
2672 }
2673
2674 =head4 参数说明:
2675
2676 参数 必须 说明
2677 access_token 是 调用接口凭证
2678 moment_id 是 朋友圈id,仅支持企业发表的朋友圈id
2679 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
2680 limit 否 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
2681
2682 =head3 权限说明
2683
2684 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
2685 自建应用调用,只会返回应用可见范围内用户的发送情况。
2686 第三方应用调用需要企业授权客户朋友圈下获取企业全部的发表记录的权限
2687
2688 =head3 RETURN 返回结果
2689
2690 {
2691 "errcode":0,
2692 "errmsg":"ok",
2693 "next_cursor":"CURSOR",
2694 "task_list":[
2695 {
2696 "userid":"zhangsan",
2697 "publish_status":1
2698 }
2699 ]
2700 }
2701
2702 =head4 RETURN 参数说明
2703
2704 参数 说明
2705 errcode 返回码
2706 errmsg 对返回码的文本描述内容
2707 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
2708 task_list 发表任务列表
2709 task_list.userid 发表成员用户userid
2710 task_list.publish_status 成员发表状态。0:未发表 1:已发表
2711
2712 =cut
2713
2714 sub get_moment_task {
2715 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2716 my $access_token = $_[0];
2717 my $json = $_[1];
2718 my $ua = LWP::UserAgent->new;
2719 $ua->timeout(30);
2720 $ua->env_proxy;
2721
2722 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_task?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2723 if ($response->is_success) {
2724 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2725 }
2726
2727 }
2728 return 0;
2729 }
2730
2731 =head2 get_moment_customer_list(access_token, hash);
2732
2733 获取客户朋友圈发表时选择的可见范围
2734
2735 =head2 SYNOPSIS
2736
2737 L<https://developer.work.weixin.qq.com/document/path/93333#获取客户朋友圈发表时选择的可见范围>
2738
2739 =head3 请求说明:
2740
2741 企业和第三方应用可通过该接口获取客户朋友圈创建时,选择的客户可见范围
2742
2743 =head4 请求包结构体为:
2744
2745 {
2746 "moment_id":"momxxx",
2747 "userid":"xxx",
2748 "cursor":"CURSOR",
2749 "limit":10
2750 }
2751
2752 =head4 参数说明:
2753
2754 参数 必须 说明
2755 access_token 是 调用接口凭证
2756 moment_id 是 朋友圈id
2757 userid 是 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的列表获取已发表成员userid,如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
2758 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
2759 limit 否 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
2760
2761 =head3 权限说明
2762
2763 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
2764 自建应用调用,只会返回应用可见范围内用户的发送情况。
2765 第三方应用调用需要企业授权客户朋友圈下获取企业全部的发表记录的权限
2766
2767 =head3 RETURN 返回结果
2768
2769 {
2770 "errcode":0,
2771 "errmsg":"ok",
2772 "next_cursor":"CURSOR",
2773 "customer_list":[
2774 {
2775 "userid":"xxx",
2776 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACCCC "
2777 }
2778 ]
2779 }
2780
2781 =head4 RETURN 参数说明
2782
2783 参数 说明
2784 errcode 返回码
2785 errmsg 对返回码的文本描述内容
2786 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
2787 customer_list 成员可见客户列表
2788 customer_list.userid 发表成员用户userid
2789 customer_list.external_userid 发送成功的外部联系人userid
2790
2791 =cut
2792
2793 sub get_moment_customer_list {
2794 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2795 my $access_token = $_[0];
2796 my $json = $_[1];
2797 my $ua = LWP::UserAgent->new;
2798 $ua->timeout(30);
2799 $ua->env_proxy;
2800
2801 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_customer_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2802 if ($response->is_success) {
2803 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2804 }
2805
2806 }
2807 return 0;
2808 }
2809
2810 =head2 get_moment_send_result(access_token, hash);
2811
2812 获取客户朋友圈发表后的可见客户列表
2813
2814 =head2 SYNOPSIS
2815
2816 L<https://developer.work.weixin.qq.com/document/path/93333#获取客户朋友圈发表后的可见客户列表>
2817
2818 =head3 请求说明:
2819
2820 企业和第三方应用可通过该接口获取客户朋友圈发表后,可在微信朋友圈中查看的客户列表
2821
2822 =head4 请求包结构体为:
2823
2824 {
2825 "moment_id":"momxxx",
2826 "userid":"xxx",
2827 "cursor":"CURSOR",
2828 "limit":100
2829 }
2830
2831 =head4 参数说明:
2832
2833 参数 必须 说明
2834 access_token 是 调用接口凭证
2835 moment_id 是 朋友圈id
2836 userid 是 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的列表获取已发表成员userid,如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
2837 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
2838 limit 否 返回的最大记录数,整型,最大值5000,默认值3000,超过最大值时取默认值
2839
2840 =head3 权限说明
2841
2842 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
2843 自建应用调用,只会返回应用可见范围内用户的发送情况。
2844 第三方应用调用需要企业授权客户朋友圈下获取企业全部的发表记录的权限
2845
2846 =head3 RETURN 返回结果
2847
2848 {
2849 "errcode":0,
2850 "errmsg":"ok",
2851 "next_cursor":"CURSOR",
2852 "customer_list":[
2853 {
2854 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACCCC"
2855 }
2856 ]
2857 }
2858
2859 =head4 RETURN 参数说明
2860
2861 参数 说明
2862 errcode 返回码
2863 errmsg 对返回码的文本描述内容
2864 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
2865 customer_list 成员发送成功客户列表
2866 customer_list.external_userid 成员发送成功的外部联系人userid
2867
2868 =cut
2869
2870 sub get_moment_send_result {
2871 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2872 my $access_token = $_[0];
2873 my $json = $_[1];
2874 my $ua = LWP::UserAgent->new;
2875 $ua->timeout(30);
2876 $ua->env_proxy;
2877
2878 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_send_result?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2879 if ($response->is_success) {
2880 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2881 }
2882
2883 }
2884 return 0;
2885 }
2886
2887 =head2 get_moment_comments(access_token, hash);
2888
2889 获取客户朋友圈的互动数据
2890
2891 =head2 SYNOPSIS
2892
2893 L<https://developer.work.weixin.qq.com/document/path/93333#获取客户朋友圈的互动数据>
2894
2895 =head3 请求说明:
2896
2897 企业和第三方应用可通过此接口获取客户朋友圈的互动数据。
2898
2899 =head4 请求包结构体为:
2900
2901 {
2902 "moment_id":"momxxx",
2903 "userid":"xxx"
2904 }
2905
2906 =head4 参数说明:
2907
2908 参数 必须 说明
2909 access_token 是 调用接口凭证
2910 moment_id 是 朋友圈id
2911 userid 是 企业发表成员userid,如果是企业创建的朋友圈,可以通过获取客户朋友圈企业发表的列表获取已发表成员userid,如果是个人创建的朋友圈,创建人userid就是企业发表成员userid
2912
2913 =head3 权限说明
2914
2915 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
2916 自建应用调用,只会返回应用可见范围内用户的发送情况。
2917 第三方应用调用需要企业授权客户朋友圈下获取企业全部的发表记录的权限
2918
2919 =head3 RETURN 返回结果
2920
2921 {
2922 "errcode":0,
2923 "errmsg":"ok",
2924 "comment_list":[
2925 {
2926 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA ",
2927 "create_time":1605172726
2928 },
2929 {
2930 "userid":"zhangshan ",
2931 "create_time":1605172729
2932 }
2933 ],
2934 "like_list":[
2935 {
2936 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACBBBB ",
2937 "create_time":1605172726
2938 },
2939 {
2940 "userid":"zhangshan ",
2941 "create_time":1605172720
2942 }
2943 ]
2944 }
2945
2946 =head4 RETURN 参数说明
2947
2948 参数 说明
2949 errcode 返回码
2950 errmsg 对返回码的文本描述内容
2951 comment_list 评论列表
2952 comment_list.external_userid 评论的外部联系人userid
2953 comment_list.userid 评论的企业成员userid,userid与external_userid不会同时出现
2954 comment_list.create_time 评论时间
2955 like_list 点赞列表
2956 like_list.external_userid 点赞的外部联系人userid
2957 like_list.userid 点赞的企业成员userid,userid与external_userid不会同时出现
2958 like_list.create_time 点赞时间
2959
2960 =cut
2961
2962 sub get_moment_comments {
2963 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
2964 my $access_token = $_[0];
2965 my $json = $_[1];
2966 my $ua = LWP::UserAgent->new;
2967 $ua->timeout(30);
2968 $ua->env_proxy;
2969
2970 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_comments?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
2971 if ($response->is_success) {
2972 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
2973 }
2974
2975 }
2976 return 0;
2977 }
2978
2979 =head2 customer_acquisition_quota(access_token);
2980
2981 获客助手额度管理与使用统计
2982 最后更新:2023/08/08
2983
2984 查询剩余使用量
2985
2986 =head2 SYNOPSIS
2987
2988 L<https://developer.work.weixin.qq.com/document/path/97375#查询剩余使用量>
2989
2990 =head3 请求说明:
2991
2992 企业可通过此接口查询当前剩余的使用量。
2993
2994 =head4 参数说明:
2995
2996 参数 必须 说明
2997 access_token 是 调用接口凭证
2998
2999 =head4 权限说明:
3000
3001 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?);
3002 第三方或代开发应用需具有“企业客户权限->获客助手”权限
3003 不支持客户联系系统应用调用
3004
3005 =head3 RETURN 返回结果:
3006
3007 {
3008 "errcode": 0,
3009 "errmsg": "ok",
3010 "total":1000,
3011 "balance":500,
3012 "quota_list":
3013 [
3014 {
3015 "expire_date":1689350400,
3016 "balance":200
3017 },
3018 {
3019 "expire_date":1692028800,
3020 "balance":300
3021 }
3022 ]
3023 }
3024
3025 =head4 RETURN 参数说明
3026
3027 参数 说明
3028 errcode 返回码
3029 errmsg 对返回码的文本描述内容
3030 total 历史累计使用量
3031 balance 剩余使用量
3032 quota_list.expire_date 额度过期时间戳,为过期日的零点,实际过期时间取决于额度的购买时间
3033 quota_list.balance 即将过期额度数量
3034
3035 =cut
3036
3037 sub customer_acquisition_quota {
3038 if ( @_ && $_[0] ) {
3039 my $access_token = $_[0];
3040 my $ua = LWP::UserAgent->new;
3041 $ua->timeout(30);
3042 $ua->env_proxy;
3043
3044 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition_quota?access_token=$access_token");
3045 if ($response->is_success) {
3046 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3047 }
3048
3049 }
3050 return 0;
3051 }
3052
3053 =head2 add_msg_template(access_token, hash);
3054
3055 创建企业群发
3056 最后更新:2023/12/01
3057
3058 =head2 SYNOPSIS
3059
3060 L<https://developer.work.weixin.qq.com/document/path/92135>
3061
3062 =head3 请求说明:
3063
3064 企业跟第三方应用可通过此接口添加企业群发消息的任务并通知成员发送给相关客户或客户群。(注:企业微信终端需升级到2.7.5版本及以上)
3065 注意:调用该接口并不会直接发送消息给客户/客户群,需要成员确认后才会执行发送(客服人员的企业微信需要升级到2.7.5及以上版本)
3066 旧接口创建企业群发已经废弃,接口升级后支持发送视频文件,并且支持最多同时发送9个附件。
3067 仅会推送给最后跟客户进行聊天互动的企业成员。
3068 每位客户/每个客户群每天可接收1条群发消息,可以是企业统一创建发送的,也可以是成员自己创建发送的;超过接收上限的客户/客户群将无法再收到群发消息。
3069
3070 =head4 请求包结构体为:
3071
3072 {
3073 "chat_type": "single",
3074 "external_userid": [
3075 "woAJ2GCAAAXtWyujaWJHDDGi0mACAAAA",
3076 "wmqfasd1e1927831123109rBAAAA"
3077 ],
3078 "chat_id_list":["wr2GCAAAXtWyujaWJHDDGasdadAAA"],
3079 "tag_filter":
3080 {
3081 "group_list":
3082 [
3083 {
3084 "tag_list":["ete19278asuMT123109rBAAAA","ete19MT12278109UYteaBAAAA"]
3085 },
3086 {
3087 "tag_list":["eteIlKKHSDfuMT18Kg9rBAAAA"]
3088 }
3089 ]
3090 },
3091 "sender": "zhangsan",
3092 "allow_select":true,
3093 "text": {
3094 "content": "文本消息内容"
3095 },
3096 "attachments": [{
3097 "msgtype": "image",
3098 "image": {
3099 "media_id": "MEDIA_ID",
3100 "pic_url": "http://p.qpic.cn/pic_wework/3474110808/7a6344sdadfwehe42060/0"
3101 }
3102 }, {
3103 "msgtype": "link",
3104 "link": {
3105 "title": "消息标题",
3106 "picurl": "https://example.pic.com/path",
3107 "desc": "消息描述",
3108 "url": "https://example.link.com/path"
3109 }
3110 }, {
3111 "msgtype": "miniprogram",
3112 "miniprogram": {
3113 "title": "消息标题",
3114 "pic_media_id": "MEDIA_ID",
3115 "appid": "wx8bd80126147dfAAA",
3116 "page": "/path/index.html"
3117 }
3118 }, {
3119 "msgtype": "video",
3120 "video": {
3121 "media_id": "MEDIA_ID"
3122 }
3123 }, {
3124 "msgtype": "file",
3125 "file": {
3126 "media_id": "MEDIA_ID"
3127 }
3128 } ]
3129 }
3130
3131 =head4 参数说明:
3132
3133 参数 必须 说明
3134 access_token 是 调用接口凭证
3135 chat_type 否 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
3136 external_userid 否 客户的externaluserid列表,仅在chat_type为single时有效,最多可一次指定1万个客户
3137 chat_id_list 否 客户群id列表,仅在chat_type为group时有效,最多可一次指定2000个客户群。指定群id之后,收到任务的群主无须再选择客户群,仅对4.1.10及以上版本的企业微信终端生效
3138 tag_filter.group_list.tag_list 否 要进行群发的客户标签列表,同组标签之间按或关系进行筛选,不同组标签按且关系筛选,每组最多指定100个标签,支持规则组标签
3139 sender 否 发送企业群发消息的成员userid,当类型为发送给客户群时必填
3140 allow_select 否 是否允许成员在待发送客户列表中重新进行选择,默认为false,仅支持客户群发场景
3141 text.content 否 消息文本内容,最多4000个字节
3142 attachments 否 附件,最多支持添加9个附件
3143 attachments.msgtype 是 附件类型,可选image、link、miniprogram或者video
3144 image.media_id 否 图片的media_id,可以通过素材管理接口获得
3145 image.pic_url 否 图片的链接,仅可使用上传图片接口得到的链接
3146 link.title 是 图文消息标题,最长128个字节
3147 link.picurl 否 图文消息封面的url,最长2048个字节
3148 link.desc 否 图文消息的描述,最多512个字节
3149 link.url 是 图文消息的链接,最长2048个字节
3150 miniprogram.title 是 小程序消息标题,最多64个字节
3151 miniprogram.pic_media_id 是 小程序消息封面的mediaid,封面图建议尺寸为520*416
3152 miniprogram.appid 是 小程序appid(可以在微信公众平台上查询),必须是关联到企业的小程序应用
3153 miniprogram.page 是 小程序page路径
3154 video.media_id 是 视频的media_id,可以通过素材管理接口获得
3155 file.media_id 是 文件的media_id,可以通过素材管理接口获得
3156
3157 对于客户群发,sender,external_userid,tag_filter不可同时为空,如果指定了external_userid,则tag_filter不生效
3158 text和attachments不能同时为空
3159 attachments中每个附件信息必须与msgtype一致,例如,msgtype指定为image,则需要填写image.pic_url或者image.media_id,否则会报错。
3160 media_id和pic_url只需填写一个,两者同时填写时使用media_id,二者不可同时为空
3161
3162 =head3 权限说明
3163
3164 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3165 自建应用只能给应用可见范围内的成员进行推送。
3166 第三方应用需具有“企业客户权限->客户联系->群发消息给客户和客户群”权限。
3167 当只提供sender参数时,相当于选取了这个成员所有的客户。
3168 注意:2019-8-1之后,取消了 “无法向未回复消息的客户发送企业群发消息” 的限制。
3169
3170 =head3 RETURN 返回结果
3171
3172 {
3173 "errcode": 0,
3174 "errmsg": "ok",
3175 "fail_list":["wmqfasd1e1927831123109rBAAAA"],
3176 "msgid":"msgGCAAAXtWyujaWJHDDGi0mAAAA"
3177 }
3178
3179 =head4 RETURN 参数说明
3180
3181 参数 说明
3182 errcode 返回码
3183 errmsg 对返回码的文本描述内容
3184 fail_list 无效或无法发送的external_userid列表
3185 msgid 企业群发消息的id,可用于获取群发消息发送结果
3186
3187 =cut
3188
3189 sub add_msg_template {
3190 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3191 my $access_token = $_[0];
3192 my $json = $_[1];
3193 my $ua = LWP::UserAgent->new;
3194 $ua->timeout(30);
3195 $ua->env_proxy;
3196
3197 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_msg_template?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3198 if ($response->is_success) {
3199 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3200 }
3201
3202 }
3203 return 0;
3204 }
3205
3206 =head2 remind_groupmsg_send(access_token, hash);
3207
3208 提醒成员群发
3209 最后更新:2023/12/01
3210
3211 =head2 SYNOPSIS
3212
3213 L<https://developer.work.weixin.qq.com/document/path/97610>
3214
3215 =head3 请求说明:
3216
3217 企业和第三方应用可调用此接口,重新触发群发通知,提醒成员完成群发任务,24小时内每个群发最多触发三次提醒。
3218
3219 =head4 请求包结构体为:
3220
3221 {
3222 "msgid": "msgGCAAAXtWyujaWJHDDGi0mACAAAA",
3223 }
3224
3225 =head4 参数说明:
3226
3227 参数 必须 说明
3228 access_token 是 调用接口凭证
3229 msgid 是 群发消息的id,通过获取群发记录列表接口返回
3230
3231 =head3 权限说明
3232
3233 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3234 自建应用调用,只会返回应用可见范围内用户的发送情况。
3235 第三方应用调用需要企业授权客户联系下群发消息给客户和客户群的权限
3236
3237 =head3 RETURN 返回结果
3238
3239 {
3240 "errcode": 0,
3241 "errmsg": "ok"
3242 }
3243
3244 =head4 RETURN 参数说明
3245
3246 参数 说明
3247 errcode 返回码
3248 errmsg 对返回码的文本描述内容
3249
3250 =cut
3251
3252 sub remind_groupmsg_send {
3253 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3254 my $access_token = $_[0];
3255 my $json = $_[1];
3256 my $ua = LWP::UserAgent->new;
3257 $ua->timeout(30);
3258 $ua->env_proxy;
3259
3260 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remind_groupmsg_send?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3261 if ($response->is_success) {
3262 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3263 }
3264
3265 }
3266 return 0;
3267 }
3268
3269 =head2 cancel_groupmsg_send(access_token, hash);
3270
3271 停止企业群发
3272 最后更新:2023/12/01
3273
3274 =head2 SYNOPSIS
3275
3276 L<https://developer.work.weixin.qq.com/document/path/97611>
3277
3278 =head3 请求说明:
3279
3280 企业和第三方应用可调用此接口,停止无需成员继续发送的企业群发
3281
3282 =head4 请求包结构体为:
3283
3284 {
3285 "msgid": "msgGCAAAXtWyujaWJHDDGi0mACAAAA",
3286 }
3287
3288 =head4 参数说明:
3289
3290 参数 必须 说明
3291 access_token 是 调用接口凭证
3292 msgid 是 群发消息的id,通过获取群发记录列表接口返回
3293
3294 =head3 权限说明
3295
3296 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3297 自建应用调用,只会返回应用可见范围内用户的发送情况。
3298 第三方应用调用需要企业授权客户联系下群发消息给客户和客户群的权限
3299
3300 =head3 RETURN 返回结果
3301
3302 {
3303 "errcode": 0,
3304 "errmsg": "ok"
3305 }
3306
3307 =head4 RETURN 参数说明
3308
3309 参数 说明
3310 errcode 返回码
3311 errmsg 对返回码的文本描述内容
3312
3313 注意,此接口无法撤回已经群发给客户的消息。
3314
3315 =cut
3316
3317 sub cancel_groupmsg_send {
3318 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3319 my $access_token = $_[0];
3320 my $json = $_[1];
3321 my $ua = LWP::UserAgent->new;
3322 $ua->timeout(30);
3323 $ua->env_proxy;
3324
3325 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/cancel_groupmsg_send?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3326 if ($response->is_success) {
3327 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3328 }
3329
3330 }
3331 return 0;
3332 }
3333
3334 =head2 获取企业的全部群发记录
3335
3336 最后更新:2022/11/03
3337
3338 =head2 SYNOPSIS
3339
3340 L<https://developer.work.weixin.qq.com/document/path/93338>
3341
3342 =head3 概述
3343
3344 企业跟第三方应用可通过该接口获取群发给客户的消息和群发到客户群的消息
3345
3346 群发助手和客户群群发有以下两种类型
3347 企业发表
3348 管理员或者业务负责人创建内容,成员确认后,即可发送给客户或者客户群
3349 个人发表
3350 成员自己创建的内容,可直接发送给客户或客户群
3351
3352 =head4 接口调用权限说明
3353
3354 允许使用“客户联系”secret调用
3355 允许自建应用:使用配置到“可调用应用”列表中的应用secret所获取的accesstoken来调用(accesstoken如何获取?)
3356 允许第三方应用:第三方应用需授权企业客户权限下群发消息给客户和客户群的权限
3357 第三方应用必须在服务商管理端申请“企业客户权限->客户联系->群发消息给客户和客户群”权限。
3358 对于历史已安装的企业,之前未授权该权限的,需要管理员去企业微信web管理端“应用管理->应用详情页->授权信息”中同意授权变更后才允许调用。
3359
3360 =head2 get_groupmsg_list_v2(access_token, hash);
3361
3362 获取企业的全部群发记录-获取群发记录列表
3363
3364 =head2 SYNOPSIS
3365
3366 L<https://developer.work.weixin.qq.com/document/path/93338#获取群发记录列表>
3367
3368 =head3 请求说明:
3369
3370 企业和第三方应用可通过此接口获取企业与成员的群发记录。
3371
3372 =head4 请求包结构体为:
3373
3374 {
3375 "chat_type":"single",
3376 "start_time":1605171726,
3377 "end_time":1605172726,
3378 "creator":"zhangshan",
3379 "filter_type":1,
3380 "limit":50,
3381 "cursor":"CURSOR"
3382 }
3383
3384 =head4 参数说明:
3385
3386 参数 必须 说明
3387 access_token 是 调用接口凭证
3388 chat_type 是 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
3389 start_time 是 群发任务记录开始时间
3390 end_time 是 群发任务记录结束时间
3391 creator 否 群发任务创建人企业账号id
3392 filter_type 否 创建人类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型
3393 limit 否 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
3394 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
3395
3396 =head4 补充说明:
3397
3398 群发任务记录的起止时间间隔不能超过1个月
3399 3.1.6版本之前不支持多附件,请参考获取群发记录列表接口获取群发记录列表
3400
3401 =head3 权限说明
3402
3403 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3404 自建应用调用,只会返回应用可见范围内用户的发送情况。
3405 第三方应用调用需要企业授权客户联系下群发消息给客户和客户群的权限
3406
3407 =head3 RETURN 返回结果
3408
3409 {
3410 "errcode":0,
3411 "errmsg":"ok",
3412 "next_cursor":"CURSOR",
3413 "group_msg_list":[
3414 {
3415 "msgid":"msgGCAAAXtWyujaWJHDDGi0mAAAA",
3416 "creator":"xxxx",
3417 "create_time":"xxxx",
3418 "create_type":1,
3419 "text": {
3420 "content":"文本消息内容"
3421 },
3422 "attachments": [
3423 {
3424 "msgtype": "image",
3425 "image": {
3426 "media_id": "MEDIA_ID",
3427 "pic_url": "http://p.qpic.cn/pic_wework/3474110808/7a6344sdadfwehe42060/0"
3428 }
3429 },
3430 {
3431 "msgtype": "link",
3432 "link": {
3433 "title": "消息标题",
3434 "picurl": "https://example.pic.com/path",
3435 "desc": "消息描述",
3436 "url": "https://example.link.com/path"
3437 }
3438 },
3439 {
3440 "msgtype": "miniprogram",
3441 "miniprogram": {
3442 "title": "消息标题",
3443 "pic_media_id": "MEDIA_ID",
3444 "appid": "wx8bd80126147dfAAA",
3445 "page": "/path/index.html"
3446 }
3447 },
3448 {
3449 "msgtype": "video",
3450 "video": {
3451 "media_id": "MEDIA_ID"
3452 }
3453 },
3454 {
3455 "msgtype": "file",
3456 "file": {
3457 "media_id": "MEDIA_ID"
3458 }
3459 }
3460 ]
3461 }
3462 ]
3463 }
3464
3465 =head4 RETURN 参数说明
3466
3467 参数 说明
3468 errcode 返回码
3469 errmsg 对返回码的文本描述内容
3470 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
3471 group_msg_list 群发记录列表
3472 group_msg_list.msgid 企业群发消息的id,可用于获取企业群发成员执行结果
3473 group_msg_list.creator 群发消息创建者userid,API接口创建的群发消息不返回该字段
3474 group_msg_list.create_time 创建时间
3475 group_msg_list.create_type 群发消息创建来源。0:企业 1:个人
3476 group_msg_list.text.content 消息文本内容,最多4000个字节
3477 group_msg_list.attachments.msgtype 值必须是image
3478 group_msg_list.attachments.image.media_id 图片的media_id,可以通过获取临时素材下载资源
3479 group_msg_list.attachments.image.pic_url 图片的url,与图片的media_id不能共存优先吐出media_id
3480 group_msg_list.attachments.msgtype 值必须是link
3481 group_msg_list.attachments.link.title 图文消息标题
3482 group_msg_list.attachments.link.picurl 图文消息封面的url
3483 group_msg_list.attachments.link.desc 图文消息的描述,最多512个字节
3484 group_msg_list.attachments.link.url 图文消息的链接
3485 group_msg_list.attachments.msgtype 值必须是miniprogram
3486 group_msg_list.attachments.miniprogram.title 小程序消息标题,最多64个字节
3487 group_msg_list.attachments.miniprogram.appid 小程序appid,必须是关联到企业的小程序应用
3488 group_msg_list.attachments.miniprogram.page 小程序page路径
3489 group_msg_list.attachments.msgtype 值必须是video
3490 group_msg_list.attachments.video.media_id 视频的media_id,可以通过获取临时素材下载资源
3491 group_msg_list.attachments.msgtype 值必须是file
3492 group_msg_list.attachments.file.media_id 文件的media_id,可以通过获取临时素材下载资源
3493
3494 =cut
3495
3496 sub get_groupmsg_list_v2 {
3497 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3498 my $access_token = $_[0];
3499 my $json = $_[1];
3500 my $ua = LWP::UserAgent->new;
3501 $ua->timeout(30);
3502 $ua->env_proxy;
3503
3504 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_list_v2?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3505 if ($response->is_success) {
3506 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3507 }
3508
3509 }
3510 return 0;
3511 }
3512
3513 =head2 get_groupmsg_task(access_token, hash);
3514
3515 获取企业的全部群发记录-获取群发成员发送任务列表
3516
3517 =head2 SYNOPSIS
3518
3519 L<https://developer.work.weixin.qq.com/document/path/93338#获取群发成员发送任务列表>
3520
3521 =head3 请求说明:
3522
3523 =head4 请求包结构体为:
3524
3525 {
3526 "msgid": "msgGCAAAXtWyujaWJHDDGi0mACAAAA",
3527 "limit":50,
3528 "cursor":"CURSOR"
3529 }
3530
3531 =head4 参数说明:
3532
3533 参数 必须 说明
3534 access_token 是 调用接口凭证
3535 msgid 是 群发消息的id,通过获取群发记录列表接口返回
3536 limit 否 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
3537 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
3538
3539 =head3 权限说明
3540
3541 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3542 自建应用调用,只会返回应用可见范围内用户的发送情况。
3543 第三方应用调用需要企业授权客户联系下群发消息给客户和客户群的权限
3544
3545 =head3 RETURN 返回结果
3546
3547 {
3548 "errcode": 0,
3549 "errmsg": "ok",
3550 "next_cursor":"CURSOR",
3551 "task_list": [
3552 {
3553 "userid": "zhangsan",
3554 "status": 1,
3555 "send_time": 1552536375
3556 }
3557 ]
3558 }
3559
3560 =head4 RETURN 参数说明
3561
3562 参数 说明
3563 errcode 返回码
3564 errmsg 对返回码的文本描述内容
3565 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
3566 task_list 群发成员发送任务列表
3567 task_list.userid 企业服务人员的userid
3568 task_list.status 发送状态:0-未发送 2-已发送
3569 task_list.send_time 发送时间,未发送时不返回
3570
3571 2020-11-17日之前创建的消息无发送任务列表,请通过获取企业群发成员执行结果接口获取群发结果
3572
3573 =cut
3574
3575 sub get_groupmsg_task {
3576 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3577 my $access_token = $_[0];
3578 my $json = $_[1];
3579 my $ua = LWP::UserAgent->new;
3580 $ua->timeout(30);
3581 $ua->env_proxy;
3582
3583 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_task?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3584 if ($response->is_success) {
3585 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3586 }
3587
3588 }
3589 return 0;
3590 }
3591
3592 =head2 get_groupmsg_send_result(access_token, hash);
3593
3594 获取企业的全部群发记录-获取企业群发成员执行结果
3595
3596 =head2 SYNOPSIS
3597
3598 L<https://developer.work.weixin.qq.com/document/path/93338#获取企业群发成员执行结果>
3599
3600 =head3 请求说明:
3601
3602 =head4 请求包结构体为:
3603
3604 {
3605 "msgid": "msgGCAAAXtWyujaWJHDDGi0mACAAAA",
3606 "userid":"zhangsan ",
3607 "limit":50,
3608 "cursor":"CURSOR"
3609 }
3610
3611 =head4 参数说明:
3612
3613 参数 必须 说明
3614 access_token 是 调用接口凭证
3615 msgid 是 群发消息的id,通过获取群发记录列表接口返回
3616 userid 是 发送成员userid,通过[获取群发成员发送任务列表](#获取群发成员发送任务列表 )接口返回
3617 limit 否 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
3618 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
3619
3620 =head3 权限说明
3621
3622 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3623 自建应用调用,只会返回应用可见范围内用户的发送情况。
3624 第三方应用调用需要企业授权客户联系下群发消息给客户和客户群的权限
3625
3626 =head3 RETURN 返回结果
3627
3628 {
3629 "errcode": 0,
3630 "errmsg": "ok",
3631 "next_cursor":"CURSOR",
3632 "send_list": [
3633 {
3634 "external_userid": "wmqfasd1e19278asdasAAAA",
3635 "chat_id":"wrOgQhDgAAMYQiS5ol9G7gK9JVAAAA",
3636 "userid": "zhangsan",
3637 "status": 1,
3638 "send_time": 1552536375
3639 }
3640 ]
3641 }
3642
3643 =head4 RETURN 参数说明
3644
3645 参数 说明
3646 errcode 返回码
3647 errmsg 对返回码的文本描述内容
3648 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
3649 send_list 群成员发送结果列表
3650 send_list.external_userid 外部联系人userid,群发消息到企业的客户群不返回该字段
3651 send_list.chat_id 外部客户群id,群发消息到客户不返回该字段
3652 send_list.userid 企业服务人员的userid
3653 send_list.status 发送状态:0-未发送 1-已发送 2-因客户不是好友导致发送失败 3-因客户已经收到其他群发消息导致发送失败
3654 send_list.send_time 发送时间,发送状态为1时返回
3655
3656 若为客户群群发,由于用户还未选择群,所以不返回未发送记录,只返回已发送记录
3657 2020-11-17日之前创建的消息请通过获取企业群发成员执行结果接口获取群发结果
3658
3659 =cut
3660
3661 sub get_groupmsg_send_result {
3662 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3663 my $access_token = $_[0];
3664 my $json = $_[1];
3665 my $ua = LWP::UserAgent->new;
3666 $ua->timeout(30);
3667 $ua->env_proxy;
3668
3669 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_send_result?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3670 if ($response->is_success) {
3671 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3672 }
3673
3674 }
3675 return 0;
3676 }
3677
3678 =head2 send_welcome_msg(access_token, hash);
3679
3680 发送新客户欢迎语
3681 最后更新:2023/12/01
3682
3683 =head2 SYNOPSIS
3684
3685 L<https://developer.work.weixin.qq.com/document/path/92137>
3686
3687 =head3 请求说明:
3688
3689 企业微信在向企业推送添加外部联系人事件时,会额外返回一个welcome_code,企业以此为凭据调用接口,即可通过成员向新添加的客户发送个性化的欢迎语。调用此接口前,请明确以下信息:
3690
3691 说明
3692 1.为了保证用户体验以及避免滥用,企业仅可在收到相关事件后20秒内调用,且只可调用一次。
3693 2.如果企业已经在管理端为相关成员配置了可用的欢迎语,则推送添加外部联系人事件时不会返回welcome_code。
3694 3.如果欢迎语已成功下发给客户,应用再调用该接口时,将返回41051(externaluser has started chatting)。
3695 4.长期未登录企业微信的成员无法发送欢迎语。
3696 5.每次添加新客户时可能有多个企业自建应用/第三方应用收到带有welcome_code的回调事件,当多个应用同时调用发送欢迎语接口时,仅最先调用接口的应用可以成功,其他应用返回41096(welcome msg is being distributed)错误。请注意,返回41096错误码表示当前已有其他应用正在发送欢迎语,不代表欢迎语已经下发成功,存在下发失败的可能性,故调用方可以重试;如果返回了41051,则代表欢迎语已成功下发,无需重试。为了保证用户体验,请根据实际业务需求,合理配置应用可见范围。
3697
3698 提示
3699 旧接口发送新客户欢迎语已经废弃,接口升级后支持发送视频文件,并且最多支持同时发送9个附件。
3700
3701 =head4 请求包结构体为:
3702
3703 {
3704 "welcome_code": "CALLBACK_CODE",
3705 "text": {
3706 "content": "文本消息内容"
3707 },
3708 "attachments": [{
3709 "msgtype": "image",
3710 "image": {
3711 "media_id": "MEDIA_ID",
3712 "pic_url": "http://p.qpic.cn/pic_wework/3474110808/7a6344sdadfwehe42060/0"
3713 }
3714 }, {
3715 "msgtype": "link",
3716 "link": {
3717 "title": "消息标题",
3718 "picurl": "https://example.pic.com/path",
3719 "desc": "消息描述",
3720 "url": "https://example.link.com/path"
3721 }
3722 }, {
3723 "msgtype": "miniprogram",
3724 "miniprogram": {
3725 "title": "消息标题",
3726 "pic_media_id": "MEDIA_ID",
3727 "appid": "wx8bd80126147dfAAA",
3728 "page": "/path/index.html"
3729 }
3730 }, {
3731 "msgtype": "video",
3732 "video": {
3733 "media_id": "MEDIA_ID"
3734 }
3735 },{
3736 "msgtype":"file",
3737 "file":
3738 {
3739 "media_id":"MEDIA_ID"
3740 }
3741 }]
3742 }
3743
3744 =head4 参数说明:
3745
3746 参数 必须 说明
3747 access_token 是 调用接口凭证
3748 welcome_code 是 通过添加外部联系人事件推送给企业的发送欢迎语的凭证,有效期为20秒
3749 text.content 否 消息文本内容,最长为4000字节
3750 attachments 否 附件,最多可添加9个附件
3751 attachments.msgtype 是 附件类型,可选image、link、miniprogram或者video
3752 image.media_id 否 图片的media_id,可以通过素材管理接口获得
3753 image.pic_url 否 图片的链接,仅可使用上传图片接口得到的链接
3754 link.title 是 图文消息标题,最长为128字节
3755 link.picurl 否 图文消息封面的url
3756 link.desc 否 图文消息的描述,最长为512字节
3757 link.url 是 图文消息的链接
3758 miniprogram.title 是 小程序消息标题,最长为64字节
3759 miniprogram.pic_media_id 是 小程序消息封面的mediaid,封面图建议尺寸为520*416
3760 miniprogram.appid 是 小程序appid,必须是关联到企业的小程序应用
3761 miniprogram.page 是 小程序page路径
3762 video.media_id 是 视频的media_id,可以通过素材管理接口获得
3763 file.media_id 是 文件的media_id, 可以通过素材管理接口获得
3764
3765 * text和attachments不能同时为空;
3766 text与附件信息可以同时发送,此时将会以多条消息的形式触达客户
3767 attachments中每个附件信息必须与msgtype一致,例如,msgtype指定为image,则需要填写image.pic_url或者image.media_id,否则会报错。
3768 media_id和pic_url只需填写一个,两者同时填写时使用media_id,二者不可同时为空。
3769
3770 =head3 权限说明
3771
3772 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3773 第三方应用需要拥有“企业客户权限->客户联系->给客户发送欢迎语”权限
3774 企业成员需在应用的可见范围内
3775
3776 =head3 RETURN 返回结果
3777
3778 {
3779 "errcode": 0,
3780 "errmsg": "ok"
3781 }
3782
3783 =head4 RETURN 参数说明
3784
3785 参数 说明
3786 errcode 返回码
3787 errmsg 对返回码的文本描述内容
3788
3789 =cut
3790
3791 sub send_welcome_msg {
3792 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3793 my $access_token = $_[0];
3794 my $json = $_[1];
3795 my $ua = LWP::UserAgent->new;
3796 $ua->timeout(30);
3797 $ua->env_proxy;
3798
3799 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3800 if ($response->is_success) {
3801 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3802 }
3803
3804 }
3805 return 0;
3806 }
3807
3808 =head2 get_user_behavior_data(access_token, hash);
3809
3810 获取「联系客户统计」数据
3811 最后更新:2023/12/01
3812
3813 =head2 SYNOPSIS
3814
3815 L<https://developer.work.weixin.qq.com/document/path/92132>
3816
3817 =head3 请求说明:
3818
3819 企业可通过此接口获取成员联系客户的数据,包括发起申请数、新增客户数、聊天数、发送消息数和删除/拉黑成员的客户数等指标。
3820
3821 =head4 请求包结构体为:
3822
3823 {
3824 "userid": [
3825 "zhangsan",
3826 "lisi"
3827 ],
3828 "partyid":
3829 [
3830 1001,
3831 1002
3832 ],
3833 "start_time":1536508800,
3834 "end_time":1536595200
3835 }
3836
3837 =head4 参数说明:
3838
3839 参数 必须 说明
3840 access_token 是 调用接口凭证
3841 userid 否 成员ID列表,最多100个
3842 partyid 否 部门ID列表,最多100个
3843 start_time 是 数据起始时间
3844 end_time 是 数据结束时间
3845
3846 userid和partyid不可同时为空;
3847 此接口提供的数据以天为维度,查询的时间范围为[start_time,end_time],即前后均为闭区间,支持的最大查询跨度为30天;
3848 用户最多可获取最近180天内的数据;
3849 当传入的时间不为0点时间戳时,会向下取整,如传入1554296400(Wed Apr 3 21:00:00 CST 2019)会被自动转换为1554220800(Wed Apr 3 00:00:00 CST 2019);
3850 如传入多个userid,则表示获取这些成员总体的联系客户数据。
3851
3852 =head3 权限说明
3853
3854 企业需要使用配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
3855 第三方应用使用,需具有“企业客户权限->客户联系->获取成员联系客户的数据统计”权限。
3856 第三方/自建应用调用时传入的userid和partyid要在应用的可见范围内;
3857
3858 =head3 RETURN 返回结果
3859
3860 {
3861 "errcode": 0,
3862 "errmsg": "ok",
3863 "behavior_data":
3864 [
3865 {
3866 "stat_time":1536508800,
3867 "chat_cnt":100,
3868 "message_cnt":80,
3869 "reply_percentage":60.25,
3870 "avg_reply_time":1,
3871 "negative_feedback_cnt":0,
3872 "new_apply_cnt":6,
3873 "new_contact_cnt":5
3874 },
3875 {
3876 "stat_time":1536595200,
3877 "chat_cnt":20,
3878 "message_cnt":40,
3879 "reply_percentage":100,
3880 "avg_reply_time":1,
3881 "negative_feedback_cnt":0,
3882 "new_apply_cnt":6,
3883 "new_contact_cnt":5
3884 }
3885 ]
3886 }
3887
3888 =head4 RETURN 参数说明
3889
3890 参数 说明
3891 errcode 返回码
3892 errmsg 对返回码的文本描述内容
3893 behavior_data.stat_time 数据日期,为当日0点的时间戳
3894 behavior_data.new_apply_cnt 发起申请数,成员通过「搜索手机号」、「扫一扫」、「从微信好友中添加」、「从群聊中添加」、「添加共享、分配给我的客户」、「添加单向、双向删除好友关系的好友」、「从新的联系人推荐中添加」等渠道主动向客户发起的好友申请数量。
3895 behavior_data.new_contact_cnt 新增客户数,成员新添加的客户数量。
3896 behavior_data.chat_cnt 聊天总数, 成员有主动发送过消息的单聊总数。
3897 behavior_data.message_cnt 发送消息数,成员在单聊中发送的消息总数。
3898 behavior_data.reply_percentage 已回复聊天占比,浮点型,客户主动发起聊天后,成员在一个自然日内有回复过消息的聊天数/客户主动发起的聊天数比例,不包括群聊,仅在确有聊天时返回。
3899 behavior_data.avg_reply_time 平均首次回复时长,单位为分钟,即客户主动发起聊天后,成员在一个自然日内首次回复的时长间隔为首次回复时长,所有聊天的首次回复总时长/已回复的聊天总数即为平均首次回复时长,不包括群聊,仅在确有聊天时返回。
3900 behavior_data.negative_feedback_cnt 删除/拉黑成员的客户数,即将成员删除或加入黑名单的客户数。
3901
3902 =cut
3903
3904 sub get_user_behavior_data {
3905 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3906 my $access_token = $_[0];
3907 my $json = $_[1];
3908 my $ua = LWP::UserAgent->new;
3909 $ua->timeout(30);
3910 $ua->env_proxy;
3911
3912 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_user_behavior_data?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
3913 if ($response->is_success) {
3914 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
3915 }
3916
3917 }
3918 return 0;
3919 }
3920
3921 =head2 管理商品图册
3922
3923 最后更新:2023/12/16
3924
3925 =head3 请求说明:
3926
3927 企业和第三方应用可以通过此接口增加商品
3928
3929 =head4 权限说明
3930
3931 调用接口的应用需要满足如下的权限:
3932
3933 应用类型 权限要求
3934 自建应用 配置到「客户联系 可调用接口的应用」中
3935 代开发应用 具有「管理商品图册」权限
3936 第三方应用 具有「管理商品图册」权限
3937
3938 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
3939
3940 =head2 add_product_album(access_token, hash);
3941
3942 管理商品图册-创建商品图册
3943
3944 =head2 SYNOPSIS
3945
3946 L<https://developer.work.weixin.qq.com/document/path/95096#创建商品图册>
3947
3948 =head4 请求包结构体为:
3949
3950 {
3951 "description":"世界上最好的商品",
3952 "price":30000,
3953 "product_sn":"xxxxxxxx",
3954 "attachments":[
3955 {
3956 "type": "image",
3957 "image": {
3958 "media_id": "MEDIA_ID"
3959 }
3960 }
3961 ]
3962 }
3963
3964 =head4 参数说明:
3965
3966 参数 必须 说明
3967 access_token 是 调用接口凭证
3968 description 是 商品的名称、特色等;不超过300个字
3969 price 是 商品的价格,单位为分;最大不超过5万元
3970 product_sn 否 商品编码;不超过128个字节;只能输入数字和字母
3971 attachments 是 附件类型,仅支持image,最多不超过9个附件
3972 image.media_id 否 图片的media_id,仅支持通过上传附件资源接口获得的资源
3973
3974 =head3 权限说明
3975
3976 =head3 RETURN 返回结果
3977
3978 {
3979 "errcode":0,
3980 "errmsg":"ok",
3981 "product_id" : "xxxxxxxxxx"
3982 }
3983
3984 =head4 RETURN 参数说明
3985
3986 参数 说明
3987 errcode 返回码
3988 errmsg 对返回码的文本描述内容
3989 product_id 商品id
3990
3991 =cut
3992
3993 sub add_product_album {
3994 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
3995 my $access_token = $_[0];
3996 my $json = $_[1];
3997 my $ua = LWP::UserAgent->new;
3998 $ua->timeout(30);
3999 $ua->env_proxy;
4000
4001 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_product_album?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4002 if ($response->is_success) {
4003 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4004 }
4005
4006 }
4007 return 0;
4008 }
4009
4010 =head2 get_product_album(access_token, hash);
4011
4012 管理商品图册-获取商品图册
4013
4014 =head2 SYNOPSIS
4015
4016 L<https://developer.work.weixin.qq.com/document/path/95096#获取商品图册>
4017
4018 =head3 请求说明:
4019
4020 企业和第三方应用可以通过此接口获取商品信息
4021
4022 =head4 请求包结构体为:
4023
4024 {
4025 "product_id" : "xxxxxxxxxx"
4026 }
4027
4028 =head4 参数说明:
4029
4030 参数 必须 说明
4031 access_token 是 调用接口凭证
4032 product_id 是 商品id
4033
4034 =head3 权限说明
4035
4036 可获取企业内所有企业级的商品图册
4037
4038 =head3 RETURN 返回结果
4039
4040 {
4041 "errcode":0,
4042 "errmsg":"ok",
4043 "product": {
4044 "product_id" : "xxxxxxxxxx",
4045 "description":"世界上最好的商品",
4046 "price":30000,
4047 "create_time":1600000000,
4048 "product_sn":"xxxxxxxx",
4049 "attachments":[
4050 {
4051 "type": "image",
4052 "image": {
4053 "media_id": "MEDIA_ID"
4054 }
4055 }
4056 ]
4057 }
4058 }
4059
4060 =head4 RETURN 参数说明
4061
4062 参数 说明
4063 errcode 返回码
4064 errmsg 对返回码的文本描述内容
4065 product 商品详情
4066 product_id 商品id
4067 product_sn 商品编码
4068 description 商品的名称、特色等
4069 price 商品的价格,单位为分
4070 create_time 商品图册创建时间
4071 attachments 附件类型
4072 attachments.type 附件类型,目前仅支持image
4073 image.media_id 图片的media_id,可以通过获取临时素材下载资源
4074
4075 =cut
4076
4077 sub get_product_album {
4078 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4079 my $access_token = $_[0];
4080 my $json = $_[1];
4081 my $ua = LWP::UserAgent->new;
4082 $ua->timeout(30);
4083 $ua->env_proxy;
4084
4085 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_product_album?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4086 if ($response->is_success) {
4087 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4088 }
4089
4090 }
4091 return 0;
4092 }
4093
4094 =head2 get_product_album_list(access_token, hash);
4095
4096 管理商品图册-获取商品图册列表
4097
4098 =head2 SYNOPSIS
4099
4100 L<https://developer.work.weixin.qq.com/document/path/95096#获取商品图册列表>
4101
4102 =head3 请求说明:
4103
4104 企业和第三方应用可以通过此接口导出商品
4105
4106 =head4 请求包结构体为:
4107
4108 {
4109 "limit":50,
4110 "cursor":"CURSOR"
4111 }
4112
4113 =head4 参数说明:
4114
4115 参数 必须 说明
4116 access_token 是 调用接口凭证
4117 limit 否 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
4118 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
4119
4120 =head3 权限说明
4121
4122 自建应用调用,只会返回应用可见范围内用户的情况。
4123
4124 =head3 RETURN 返回结果
4125
4126 {
4127 "errcode":0,
4128 "errmsg":"ok",
4129 "next_cursor":"CURSOR",
4130 "product_list":[
4131 {
4132 "product_id" : "xxxxxxxxxx",
4133 "description":"世界上最好的商品",
4134 "price":30000,
4135 "product_sn":"xxxxxxxx",
4136 "attachments":[
4137 {
4138 "type": "image",
4139 "image": {
4140 "media_id": "MEDIA_ID"
4141 }
4142 }
4143 ]
4144 }
4145 ]
4146 }
4147
4148 =head4 RETURN 参数说明
4149
4150 参数 说明
4151 errcode 返回码
4152 errmsg 对返回码的文本描述内容
4153 next_cursor 用于分页查询的游标,字符串类型,用于下一次调用
4154 product_list 商品列表
4155 product_list.product_id 商品id
4156 product_list.product_sn 商品编码
4157 product_list.description 商品的名称、特色等
4158 product_list.price 商品的价格,单位为分
4159 product_list.attachments 附件类型
4160 product_list.attachments.type 附件类型,目前仅支持image
4161 product_list.image.media_id 图片的media_id,可以通过获取临时素材下载资源
4162
4163 =cut
4164
4165 sub get_product_album_list {
4166 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4167 my $access_token = $_[0];
4168 my $json = $_[1];
4169 my $ua = LWP::UserAgent->new;
4170 $ua->timeout(30);
4171 $ua->env_proxy;
4172
4173 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_product_album_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4174 if ($response->is_success) {
4175 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4176 }
4177
4178 }
4179 return 0;
4180 }
4181
4182 =head2 update_product_album(access_token, hash);
4183
4184 管理商品图册-编辑商品图册
4185
4186 =head2 SYNOPSIS
4187
4188 L<https://developer.work.weixin.qq.com/document/path/95096#编辑商品图册>
4189
4190 =head3 请求说明:
4191
4192 企业和第三方应用可以通过此接口修改商品信息
4193
4194 =head4 请求包结构体为:
4195
4196 {
4197 "product_id" : "xxxxxxxxxx",
4198 "description":"世界上最好的商品",
4199 "price":30000,
4200 "product_sn":"xxxxxx",
4201 "attachments":[
4202 {
4203 "type": "image",
4204 "image": {
4205 "media_id": "MEDIA_ID"
4206 }
4207 }
4208 ]
4209 }
4210
4211 =head4 参数说明:
4212
4213 参数 必须 说明
4214 access_token 是 调用接口凭证
4215 product_id 是 商品id
4216 description 是 商品的名称、特色等;不超过300个字
4217 price 是 商品的价格,单位为分;最大不超过5万元
4218 product_sn 否 商品编码;不超过128个字节;只能输入数字和字母
4219 attachments 否 附件类型,仅支持image
4220 attachments.type 附件类型,目前仅支持image
4221 image.media_id 否 图片的media_id,仅支持通过上传附件资源接口的资源
4222
4223 注:除product_id外,需要更新的字段才填,不需更新的字段可不填。
4224
4225 =head3 权限说明
4226
4227 应用只修改应用自己创建的商品图册
4228
4229 =head3 RETURN 返回结果
4230
4231 {
4232 "errcode":0,
4233 "errmsg":"ok"
4234 }
4235
4236 =head4 RETURN 参数说明
4237
4238 参数 说明
4239 errcode 返回码
4240 errmsg 对返回码的文本描述内容
4241
4242 =cut
4243
4244 sub update_product_album {
4245 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4246 my $access_token = $_[0];
4247 my $json = $_[1];
4248 my $ua = LWP::UserAgent->new;
4249 $ua->timeout(30);
4250 $ua->env_proxy;
4251
4252 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_product_album?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4253 if ($response->is_success) {
4254 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4255 }
4256
4257 }
4258 return 0;
4259 }
4260
4261 =head2 delete_product_album(access_token, hash);
4262
4263 管理商品图册-删除商品图册
4264
4265 =head2 SYNOPSIS
4266
4267 L<https://developer.work.weixin.qq.com/document/path/95096#删除商品图册>
4268
4269 =head3 请求说明:
4270
4271 企业和第三方应用可以通过此接口删除商品信息
4272
4273 =head4 请求包结构体为:
4274
4275 {
4276 "product_id" : "xxxxxxxxxx"
4277 }
4278
4279 =head4 参数说明:
4280
4281 参数 必须 说明
4282 access_token 是 调用接口凭证
4283 product_id 是 商品id
4284
4285 =head3 权限说明
4286
4287 应用只可删除应用自己创建的商品图册
4288
4289 =head3 RETURN 返回结果
4290
4291 {
4292 "errcode":0,
4293 "errmsg":"ok"
4294 }
4295
4296 =head4 RETURN 参数说明
4297
4298 参数 说明
4299 errcode 返回码
4300 errmsg 对返回码的文本描述内容
4301
4302 =cut
4303
4304 sub delete_product_album {
4305 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4306 my $access_token = $_[0];
4307 my $json = $_[1];
4308 my $ua = LWP::UserAgent->new;
4309 $ua->timeout(30);
4310 $ua->env_proxy;
4311
4312 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/delete_product_album?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4313 if ($response->is_success) {
4314 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4315 }
4316
4317 }
4318 return 0;
4319 }
4320
4321 =head2 管理聊天敏感词
4322
4323 最后更新:2023/12/01
4324
4325 =head3 请求说明:
4326
4327 企业与第三方应用可通过该接口管理聊天敏感词
4328
4329 =head4 权限说明
4330
4331 调用接口的应用需要满足如下的权限:
4332
4333 应用类型 权限要求
4334 自建应用 配置到「客户联系 可调用接口的应用」中
4335 代开发应用 具有「管理敏感词」权限
4336 第三方应用 具有「管理敏感词」权限
4337
4338 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
4339
4340 =head2 add_intercept_rule(access_token, hash);
4341
4342 管理聊天敏感词-新建敏感词规则
4343
4344 =head2 SYNOPSIS
4345
4346 L<https://developer.work.weixin.qq.com/document/path/95097#新建敏感词规则>
4347
4348 =head3 请求说明:
4349
4350 企业和第三方应用可以通过此接口新建敏感词规则
4351
4352 =head4 请求包结构体为:
4353
4354 {
4355 "rule_name":"rulename",
4356 "word_list":[
4357 "敏感词1","敏感词2"
4358 ],
4359 "semantics_list":[1,2,3],
4360 "intercept_type":1,
4361 "applicable_range":{
4362 "user_list":["zhangshan"],
4363 "department_list":[2,3]
4364 }
4365 }
4366
4367 =head4 参数说明:
4368
4369 参数 必须 说明
4370 access_token 是 调用接口凭证
4371 rule_name 是 规则名称,长度1~20个utf8字符
4372 word_list 是 敏感词列表,敏感词长度1~32个utf8字符,列表大小不能超过300个
4373 semantics_list 否 额外的拦截语义规则,1:手机号、2:邮箱地:、3:红包
4374 intercept_type 是 拦截方式,1:警告并拦截发送;2:仅发警告
4375 applicable_range 是 敏感词适用范围,userid与department不能同时为不填
4376 applicable_range.user_list 否 可使用的userid列表。必须为应用可见范围内的成员;最多支持传1000个节点
4377 applicable_range.department_list 否 可使用的部门列表,必须为应用可见范围内的部门;最多支持传1000个节点
4378
4379 注:企业敏感词规则条数上限为100个。
4380
4381 =head3 权限说明
4382
4383 =head3 RETURN 返回结果
4384
4385 {
4386 "errcode":0,
4387 "errmsg":"ok",
4388 "rule_id" : "xxx"
4389 }
4390
4391 =head4 RETURN 参数说明
4392
4393 参数 说明
4394 errcode 返回码
4395 errmsg 对返回码的文本描述内容
4396 rule_id 规则id
4397
4398 =cut
4399
4400 sub add_intercept_rule {
4401 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4402 my $access_token = $_[0];
4403 my $json = $_[1];
4404 my $ua = LWP::UserAgent->new;
4405 $ua->timeout(30);
4406 $ua->env_proxy;
4407
4408 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_intercept_rule?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4409 if ($response->is_success) {
4410 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4411 }
4412
4413 }
4414 return 0;
4415 }
4416
4417 =head2 get_intercept_rule_list(access_token, hash);
4418
4419 管理聊天敏感词-获取敏感词规则列表
4420
4421 =head2 SYNOPSIS
4422
4423 L<https://developer.work.weixin.qq.com/document/path/95097#获取敏感词规则列表>
4424
4425 =head3 请求说明:
4426
4427 企业和第三方应用可以通过此接口获取敏感词规则列表
4428
4429 =head4 参数说明:
4430
4431 参数 必须 说明
4432 access_token 是 调用接口凭证
4433
4434 =head3 权限说明
4435
4436 可获取企业所有敏感词规则
4437
4438 =head3 RETURN 返回结果
4439
4440 {
4441 "errcode":0,
4442 "errmsg":"ok",
4443 "rule_list":[
4444 {
4445 "rule_id":"xxxx",
4446 "rule_name":"rulename",
4447 "create_time":1600000000
4448 }
4449 ]
4450 }
4451
4452 =head4 RETURN 参数说明
4453
4454 参数 说明
4455 errcode 返回码
4456 errmsg 对返回码的文本描述内容
4457 rule_id 规则id
4458 rule_name 规则名称,长度上限20个字符
4459 create_time 创建时间
4460
4461 =cut
4462
4463 sub get_intercept_rule_list {
4464 if ( @_ && $_[0] ) {
4465 my $access_token = $_[0];
4466 my $ua = LWP::UserAgent->new;
4467 $ua->timeout(30);
4468 $ua->env_proxy;
4469
4470 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_intercept_rule_list?access_token=$access_token");
4471 if ($response->is_success) {
4472 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4473 }
4474
4475 }
4476 return 0;
4477 }
4478
4479 =head2 get_intercept_rule(access_token, hash);
4480
4481 管理聊天敏感词-获取敏感词规则详情
4482
4483 =head2 SYNOPSIS
4484
4485 L<https://developer.work.weixin.qq.com/document/path/95097#获取敏感词规则详情>
4486
4487 =head3 请求说明:
4488
4489 企业和第三方应用可以通过此接口获取敏感词规则详情
4490
4491 =head4 请求包结构体为:
4492
4493 {
4494 "rule_id":"xxx"
4495 }
4496
4497 =head4 参数说明:
4498
4499 参数 必须 说明
4500 access_token 是 调用接口凭证
4501 rule_id 是 规则id
4502
4503 =head3 权限说明
4504
4505 使用范围只返回应用可见范围内的成员跟部门
4506
4507 =head3 RETURN 返回结果
4508
4509 {
4510 "errcode":0,
4511 "errmsg":"ok",
4512 "rule":{
4513 "rule_id":1,
4514 "rule_name":"rulename",
4515 "word_list":[
4516 "敏感词1","敏感词2"
4517 ],
4518 "extra_rule":{
4519 "semantics_list":[1,2,3],
4520 },
4521 "intercept_type":1,
4522 "applicable_range":{
4523 "user_list":["zhangshan"],
4524 "department_list":[2,3]
4525 }
4526 }
4527
4528 }
4529
4530 =head4 RETURN 参数说明
4531
4532 参数 说明
4533 errcode 返回码
4534 errmsg 对返回码的文本描述内容
4535 rule_id 规则id
4536 rule_name 规则名称,长度上限20个字符
4537 word_list 敏感词列表,敏感词不能超过30个字符,列表大小不能超过300个
4538 extra_rule 额外的规则
4539 semantics_list 额外的拦截语义规则,1:手机号、2:邮箱地:、3:红包
4540 intercept_type 拦截方式,1:警告并拦截发送;2:仅发警告
4541 applicable_range 敏感词适用范围
4542 applicable_range.user_list 可使用的userid列表,只返回应用可见范围内的用户
4543 applicable_range.department_list 可使用的部门列表,只返回应用可见范围内的部门
4544 create_time 创建时间
4545
4546 =cut
4547
4548 sub get_intercept_rule {
4549 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4550 my $access_token = $_[0];
4551 my $json = $_[1];
4552 my $ua = LWP::UserAgent->new;
4553 $ua->timeout(30);
4554 $ua->env_proxy;
4555
4556 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_intercept_rule?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4557 if ($response->is_success) {
4558 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4559 }
4560
4561 }
4562 return 0;
4563 }
4564
4565 =head2 update_intercept_rule(access_token, hash);
4566
4567 管理聊天敏感词-修改敏感词规则
4568
4569 =head2 SYNOPSIS
4570
4571 L<https://developer.work.weixin.qq.com/document/path/95097#修改敏感词规则>
4572
4573 =head3 请求说明:
4574
4575 企业和第三方应用可以通过此接口修改敏感词规则
4576
4577 =head4 请求包结构体为:
4578
4579 {
4580 "rule_id":"xxxx",
4581 "rule_name":"rulename",
4582 "word_list":[
4583 "敏感词1","敏感词2"
4584 ],
4585 "extra_rule":{
4586 "semantics_list":[1,2,3],
4587 },
4588 "intercept_type":1,
4589 "add_applicable_range":{
4590 "user_list":["zhangshan"],
4591 "department_list":[2,3]
4592 },
4593 "remove_applicable_range":{
4594 "user_list":["zhangshan"],
4595 "department_list":[2,3]
4596 }
4597 }
4598
4599 =head4 参数说明:
4600
4601 参数 必须 说明
4602 access_token 是 调用接口凭证
4603 rule_id 是 规则id
4604 rule_name 否 规则名称,长度1~20个utf8字符
4605 word_list 否 敏感词列表,敏感词长度1~32个utf8字符,列表大小不能超过300个;若为空忽略该字段
4606 extra_rule 否 额外的规则
4607 semantics_list 否 额外的拦截语义规则,1:手机号、2:邮箱地:、3:红包;若为空表示清楚所有的语义规则
4608 intercept_type 否 拦截方式,1:警告并拦截发送;2:仅发警告
4609 add_applicable_range 否 需要新增的使用范围
4610 add_applicable_range.user_list 否 可使用的userid列表,必须为应用可见范围内的成员;每次最多支持传1000个节点;该规则最多可包含的userid总数上限为10000个。若超过建议设置部门id
4611 add_applicable_range.department_list 否 可使用的部门列表,必须为应用可见范围内的部门;最多支持传1000个节点
4612 remove_applicable_range 否 需要删除的使用范围
4613 remove_applicable_range.user_list 否 可使用的userid列表,必须为应用可见范围内的成员;最多支持传1000个节点
4614 remove_applicable_range.department_list 否 可使用的部门列表,必须为应用可见范围内的部门;最多支持传1000个节点
4615
4616 注:除rule_id外,需要更新的字段才填,不需更新的字段可不填。
4617
4618 =head3 权限说明
4619
4620 应用只可修改应用自己创建的敏感词规则
4621
4622 =head3 RETURN 返回结果
4623
4624 {
4625 "errcode":0,
4626 "errmsg":"ok"
4627 }
4628
4629 =head4 RETURN 参数说明
4630
4631 参数 说明
4632 errcode 返回码
4633 errmsg 对返回码的文本描述内容
4634
4635 =cut
4636
4637 sub update_intercept_rule {
4638 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4639 my $access_token = $_[0];
4640 my $json = $_[1];
4641 my $ua = LWP::UserAgent->new;
4642 $ua->timeout(30);
4643 $ua->env_proxy;
4644
4645 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_intercept_rule?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4646 if ($response->is_success) {
4647 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4648 }
4649
4650 }
4651 return 0;
4652 }
4653
4654 =head2 del_intercept_rule(access_token, hash);
4655
4656 管理聊天敏感词-删除敏感词规则
4657
4658 =head2 SYNOPSIS
4659
4660 L<https://developer.work.weixin.qq.com/document/path/95097#删除敏感词规则>
4661
4662 =head3 请求说明:
4663
4664 企业和第三方应用可以通过此接口修改敏感词规则
4665
4666 =head4 请求包结构体为:
4667
4668 {
4669 "rule_id":"xxx"
4670 }
4671
4672 =head4 参数说明:
4673
4674 参数 必须 说明
4675 access_token 是 调用接口凭证
4676 rule_id 是 规则id
4677
4678 =head3 权限说明
4679
4680 应用只可删除应用自己创建的敏感词规则
4681
4682 =head3 RETURN 返回结果
4683
4684 {
4685 "errcode":0,
4686 "errmsg":"ok"
4687 }
4688
4689 =head4 RETURN 参数说明
4690
4691 参数 说明
4692 errcode 返回码
4693 errmsg 对返回码的文本描述内容
4694
4695 =cut
4696
4697 sub del_intercept_rule {
4698 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4699 my $access_token = $_[0];
4700 my $json = $_[1];
4701 my $ua = LWP::UserAgent->new;
4702 $ua->timeout(30);
4703 $ua->env_proxy;
4704
4705 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_intercept_rule?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4706 if ($response->is_success) {
4707 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4708 }
4709
4710 }
4711 return 0;
4712 }
4713
4714 =head2 contact_list(access_token, hash);
4715
4716 获取已服务的外部联系人
4717 最后更新:2023/11/30
4718
4719 =head2 SYNOPSIS
4720
4721 L<https://developer.work.weixin.qq.com/document/path/99434>
4722
4723 =head3 请求说明:
4724
4725 企业可通过此接口获取所有已服务的外部联系人,及其添加人和加入的群聊。外部联系人分为客户和其他外部联系人,如果是客户,接口将返回外部联系人临时ID和externaluserid;如果是其他外部联系人,接口将只返回外部联系人临时ID。
4726
4727 企业可通过外部联系人临时ID排除重复数据,外部联系人临时ID有效期为4小时。
4728
4729 =head4 请求包结构体为:
4730
4731 {
4732 "cursor":"CURSOR",
4733 "limit":1000
4734 }
4735
4736 =head4 参数说明:
4737
4738 参数 必须 说明
4739 access_token 是 调用接口凭证
4740 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
4741 limit 否 返回的最大记录数,整型,默认为1000
4742
4743 注意
4744 cursor具有有效期,请勿缓存后使用
4745
4746 =head3 权限说明
4747
4748 调用的应用需要满足如下的权限
4749
4750 应用类型 权限要求
4751 自建应用 配置到「客户联系 可调用接口的应用」中
4752 代开发应用 暂不支持
4753 第三方应用 暂不支持
4754 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
4755
4756 =head3 RETURN 返回结果
4757
4758 {
4759 "errcode": 0,
4760 "errmsg": "ok",
4761 "info_list":
4762 [
4763 {
4764 "is_customer":false,
4765 "name":"***开",
4766 "tmp_openid":"TMP_ID",
4767 "follow_userid":"USER_ID",
4768 "chat_name":"外联群1",
4769 "add_time":1694418699
4770 },
4771 {
4772 "is_customer":true,
4773 "tmp_openid":"TMP_ID",
4774 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACHAAA",
4775 "follow_userid":"USER_ID",
4776 "add_time":1694418699
4777 },
4778 {
4779 "is_customer":true,
4780 "tmp_openid":"TMP_ID",
4781 "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACHAAA",
4782 "chat_id":"CHATID",
4783 "add_time":1694418699
4784 },
4785 {
4786 "is_customer":false,
4787 "tmp_openid":"TMP_ID",
4788 "name":"***开",
4789 "follow_userid":"USER_ID",
4790 "add_time":1694418699
4791 }
4792 ],
4793 "next_cursor":"NEXT_CURSOR"
4794 }
4795
4796 =head4 RETURN 参数说明
4797
4798 参数 说明
4799 errcode 返回码
4800 errmsg 对返回码的文本描述内容
4801 info_list.is_customer 是否被成员标记为客户
4802 info_list.tmp_openid 外部联系人临时ID
4803 info_list.external_userid 外部联系人的externaluserid(如果是客户才返回)
4804 info_list.name 脱敏后的外部联系人昵称(如果是其他外部联系人才返回)
4805 info_list.follow_userid 添加此外部联系人的企业成员或外部联系人所在群聊的群主userid
4806 info_list.chat_id 外部联系人所在的群聊ID(如果群聊被成员标记为客户群才返回)
4807 info_list.chat_name 外部联系人所在群聊的群名(如果群聊未被成员标记为客户群才返回)
4808 info_list.add_time 外部联系人首次添加/进群的时间
4809 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空,有效期为4小时
4810
4811 提示
4812 外部联系人临时id是一个外部联系人的唯一标识,企业可根据此id对外部联系人进行去重统计。但外部联系人临时id仅在一轮遍历查询(从首个分页查询开始到最后一个分页查询完毕)中唯一;每次请求首个数据分页(cursor为空)时,返回的外部联系人临时id和next_cursor将发生变化。
4813
4814 =cut
4815
4816 sub contact_list {
4817 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
4818 my $access_token = $_[0];
4819 my $json = $_[1];
4820 my $ua = LWP::UserAgent->new;
4821 $ua->timeout(30);
4822 $ua->env_proxy;
4823
4824 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/contact_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
4825 if ($response->is_success) {
4826 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
4827 }
4828
4829 }
4830 return 0;
4831 }
4832
4833 1;
4834 __END__