work/corpgroup/corp.pm untested

filter: Statementstmt 0.0% 0 / 100 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 222 CC 17 SCAR 23.0
CC
17
Cov
0%
list_app_share_info
12.0
gettoken
12.0
get_chain_list
12.0
CRAP 10.0
1 package QQ::weixin::work::corpgroup::corp;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::corpgroup::corp
8
9 =head1 DESCRIPTION
10
11 =cut
12
13 use strict;
14 use base qw(QQ::weixin::work::corpgroup);
15 use Encode;
16 use LWP::UserAgent;
17 use JSON;
18 use utf8;
19
20 our $VERSION = '0.10';
21 our @EXPORT = qw/ list_app_share_info gettoken get_chain_list
22 get_chain_group get_chain_corpinfo_list get_chain_corpinfo
23 remove_corp get_chain_user_custom_id /;
24
25 =head1 FUNCTION
26
27 =head2 list_app_share_info(access_token, hash);
28
29 获取应用共享信息
30 最后更新:2022/08/25
31
32 =head2 SYNOPSIS
33
34 L<https://developer.work.weixin.qq.com/document/path/93403>
35 L<https://developer.work.weixin.qq.com/document/path/95813>
36
37 =head3 请求说明:
38
39 局校互联中的局端或者上下游中的上游企业通过该接口可以获取某个应用分享给的所有企业列表。
40 特别注意,对于有敏感权限的应用,需要下级/下游企业确认后才能共享成功,若下级/下游企业未确认,则不会存在于该接口的返回列表
41
42 =head4 请求包结构体为:
43
44 {
45 "agentid":1111,
46 "business_type":1,
47 "corpid":"wwcorp",
48 "limit":100,
49 "cursor":"xxxxxx"
50 }
51
52 =head4 参数说明:
53
54 参数 必须 说明
55 access_token 是 调用接口凭证
56 business_type 否 填0则为企业互联/局校互联,填1则表示上下游企业
57 agentid 是 上级/上游企业应用agentid
58 corpid 否 下级/下游企业corpid,若指定该参数则表示拉取该下级/下游企业的应用共享信息
59 limit 否 返回的最大记录数,整型,最大值100,默认情况或者值为0表示下拉取全量数据,建议分页拉取或者通过指定corpid参数拉取。
60 cursor 否 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
61
62 =head3 权限说明
63
64 自建应用和第三方应用
65
66 =head3 RETURN 返回结果
67
68 {
69 "errcode": 0,
70 "errmsg": "ok",
71 "ending":0
72 "corp_list":[
73 {
74 "corpid": "wwcorpid1",
75 "corp_name": "测试企业1"
76 "agentid": 1111
77 },
78 {
79 "corpid": "wwcorpid2",
80 "corp_name": "测试企业2",
81 "agentid": 1112
82 }
83 ],
84 "next_cursor": "next_cursor1111"
85 }
86
87 =head3 RETURN 参数说明
88
89 参数 说明
90 errcode 返回码
91 errmsg 对返回码的文本描述内容
92 ending 1表示拉取完毕,0表示数据没有拉取完
93 next_cursor 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
94 corp_list 应用共享信息
95 corp_list.corpid 下级/下游企业corpid
96 corp_list.corp_name 下级/下游企业名称
97 corp_list.agentid 下级/下游企业应用id
98
99 =cut
100
101 sub list_app_share_info {
102 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
103 my $access_token = $_[0];
104 my $json = $_[1];
105 my $ua = LWP::UserAgent->new;
106 $ua->timeout(30);
107 $ua->env_proxy;
108
109 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/list_app_share_info?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
110 if ($response->is_success) {
111 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
112 }
113
114 }
115 return 0;
116 }
117
118 =head2 gettoken(access_token, hash);
119
120 获取下级/下游企业的access_token
121 最后更新:2022/09/29
122
123 =head2 SYNOPSIS
124
125 L<https://developer.work.weixin.qq.com/document/path/93359>
126 L<https://developer.work.weixin.qq.com/document/path/95816>
127
128 =head3 请求说明:
129
130 获取应用可见范围内下级/下游企业的access_token,该access_token可用于调用下级/下游企业通讯录的只读接口。
131
132 =head4 请求包结构体为:
133
134 {
135 "corpid": "wwabc",
136 "business_type":1,
137 "agentid": 1111
138 }
139
140 =head4 参数说明:
141
142 参数 必须 说明
143 access_token 是 调用接口凭证
144 corpid 是 已授权的下级/下游企业corpid
145 agentid 是 已授权的下级/下游企业应用ID
146 business_type 否 填0则为企业互联/局校互联,填1则表示上下游企业
147
148 =head3 权限说明
149
150 自建应用和代开发应用
151
152 =head3 RETURN 返回结果
153
154 {
155 "errcode": 0,
156 "errmsg": "ok",
157 "access_token": "accesstoken000001",
158 "expires_in": 7200
159 }
160
161 =head3 RETURN 参数说明
162
163 参数 说明
164 errcode 返回码
165 errmsg 对返回码的文本描述内容
166 access_token 获取到的下级/下游企业调用凭证,最长为512字节
167 expires_in 凭证的有效时间(秒)
168
169 =cut
170
171 sub gettoken {
172 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
173 my $access_token = $_[0];
174 my $json = $_[1];
175 my $ua = LWP::UserAgent->new;
176 $ua->timeout(30);
177 $ua->env_proxy;
178
179 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/gettoken?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
180 if ($response->is_success) {
181 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
182 }
183
184 }
185 return 0;
186 }
187
188 =head2 get_chain_list(access_token);
189
190 获取上下游列表
191 最后更新:2023/11/29
192
193 =head2 SYNOPSIS
194
195 L<https://developer.work.weixin.qq.com/document/path/95820>
196
197 =head3 请求说明:
198
199 =head4 参数说明:
200
201 参数 必须 说明
202 access_token 是 调用接口凭证。上游企业应用access_token
203
204 =head4 权限说明:
205
206 自建应用/代开发应用可调用,仅返回应用可见范围内的上下游列表
207 「上下游- 可调用接口的应用」调用,返回全部的上下游列表
208
209 =head3 RETURN 返回结果
210
211 {
212 "errcode": 0,
213 "errmsg": "ok",
214 "chains": [
215 {
216 "chain_id": "chainid1",
217 "chain_name": "能源供应链"
218 },
219 {
220 "chain_id": "chainid2",
221 "chain_name": "原材料供应链"
222 }
223 ]
224 }
225
226 =head4 RETURN 参数说明
227
228 参数 说明
229 errcode 返回码
230 errmsg 对返回码的文本描述内容
231 chains 企业上下游列表
232 chains.chain_id 上下游id
233 chains.chain_name 上下游名称
234
235 =cut
236
237 sub get_chain_list {
238 if ( @_ && $_[0] ) {
239 my $access_token = $_[0];
240 my $ua = LWP::UserAgent->new;
241 $ua->timeout(30);
242 $ua->env_proxy;
243
244 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/get_chain_list?access_token=$access_token");
245 if ($response->is_success) {
246 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
247 }
248
249 }
250 return 0;
251 }
252
253 =head2 get_chain_group(access_token, hash);
254
255 获取上下游通讯录分组
256 最后更新:2023/11/29
257
258 =head2 SYNOPSIS
259
260 L<https://developer.work.weixin.qq.com/document/path/95820>
261
262 =head3 请求说明:
263
264 自建应用/代开发应用可通过该接口获取企业上下游通讯录分组详情
265
266 =head4 请求包结构体为:
267
268 {
269 "chain_id":"Chxxxxxx",
270 "groupid":1
271 }
272
273 =head4 参数说明:
274
275 参数 必须 说明
276 access_token 是 调用接口凭证。上游企业应用access_token
277 chain_id 是 上下游id
278 groupid 否 分组id。填写此参数返回指定分组,不填则返回全部分组
279
280 =head4 权限说明:
281
282 自建应用/代开发应用可调用,仅可指定或返回应用可见范围内的分组列表
283 上下游- 可调用接口的应用」调用,可指定或返回全部的分组列表
284
285 =head3 RETURN 返回结果
286
287 {
288 "errcode": 0,
289 "errmsg": "ok",
290 "groups": [
291 {
292 "groupid": 2,
293 "group_name": "一级经销商",
294 "parentid": 1,
295 "order": 1
296 },
297 {
298 "groupid": 3,
299 "group_name": "二级经销商",
300 "parentid": 2,
301 "order": 3
302 }
303 ]
304 }
305
306 =head4 RETURN 参数说明
307
308 参数 说明
309 errcode 返回码
310 errmsg 对返回码的文本描述内容
311 groups 分组列表数据。
312 groups.groupid 分组id
313 groups.group_name 分组名称
314 groups.parentid 父分组id。根分组id为1
315 groups.order 父部门中的次序值。order值大的排序靠前。值范围是[0, 2^32)
316
317 =cut
318
319 sub get_chain_group {
320 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
321 my $access_token = $_[0];
322 my $json = $_[1];
323 my $ua = LWP::UserAgent->new;
324 $ua->timeout(30);
325 $ua->env_proxy;
326
327 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/get_chain_group?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
328 if ($response->is_success) {
329 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
330 }
331
332 }
333 return 0;
334 }
335
336 =head2 get_chain_corpinfo_list(access_token, hash);
337
338 获取企业上下游通讯录分组下的企业详情列表
339 最后更新:2023/11/29
340
341 =head2 SYNOPSIS
342
343 L<https://developer.work.weixin.qq.com/document/path/95820>
344
345 =head3 请求说明:
346
347 自建应用/代开发应用可通过该接口获取企业上下游通讯录的某个分组下的企业列表
348
349 =head4 请求包结构体为:
350
351 {
352 "chain_id":"Chxxxxxx",
353 "groupid":1,
354 "need_pending":false,
355 "cursor": "",
356 "limit": 0
357 }
358
359 =head4 参数说明:
360
361 参数 必须 说明
362 access_token 是 调用接口凭证。上游企业应用access_token
363 chain_id 是 上下游id
364 groupid 否 分组id。如果不填,表示根目录
365 need_pending 否 是否需要返回未加入的企业。默认不返回
366 cursor 否 开启分页使用,传入返回值next_cursor
367 limit 否 >0开启分页功能。
368
369 如需获取该分组及其子分组的所有企业详情,需先获取该分组下的所有子分组,然后再获取子分组下的企业,逐层递归获取。
370
371 =head4 权限说明:
372
373 自建应用/代开发应用可调用,仅返回应用可见范围内的企业列表
374 上下游- 可调用接口的应用」应用调用,返回全部的企业列表
375
376 =head3 RETURN 返回结果
377
378 {
379 "errcode": 0,
380 "errmsg": "ok",
381 "has_more": false,
382 "next_cursor": "xxx",
383 "group_corps": [
384 {
385 "groupid": 2,
386 "corpid": "wwxxxx",
387 "corp_name":"美馨粮油公司",
388 "custom_id":"custom_id",
389 "invite_userid":"zhangsan",
390 "pending_corpid":"wwxxxx",
391 "is_joined":1
392 }
393 ]
394 }
395
396 =head4 RETURN 参数说明
397
398 参数 说明
399 errcode 返回码
400 errmsg 对返回码的文本描述内容
401 group_corps 分组列表数据。
402 group_corps.groupid 企业所属上下游的分组id
403 group_corps.corpid 企业id,最多64个字节,已加入的企业返回
404 group_corps.corp_name 企业名称
405 group_corps.custom_id 上下游企业自定义id,返回批量导入上下游联系人时指定的企业自定义id,如未指定则该字段为空
406 group_corps.invite_userid 该上下游的邀请人的userid,仅 上下游- 可调用接口的应用」应用调用时返回,切成员需在应用的可见范围内
407 group_corps.pending_corpid 未加入企业id,未加入的企业返回
408 group_corps.is_joined 企业是否已加入
409 next_cursor 下次请求时应传入的cursor
410 has_more 开启分页时告知是否还有更多记录
411
412 =cut
413
414 sub get_chain_corpinfo_list {
415 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
416 my $access_token = $_[0];
417 my $json = $_[1];
418 my $ua = LWP::UserAgent->new;
419 $ua->timeout(30);
420 $ua->env_proxy;
421
422 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/get_chain_corpinfo_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
423 if ($response->is_success) {
424 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
425 }
426
427 }
428 return 0;
429 }
430
431 =head2 get_chain_corpinfo(access_token, hash);
432
433 获取企业上下游通讯录下的企业信息
434 最后更新:2023/11/29
435
436 =head2 SYNOPSIS
437
438 L<https://developer.work.weixin.qq.com/document/path/95820>
439
440 =head3 请求说明:
441
442 自建应用/代开发应用可通过该接口获取企业上下游通讯录的某个企业的自定义id和所属分组的分组id
443
444 =head4 请求包结构体为:
445
446 {
447 "chain_id":"Chxxxxxx",
448 "corpid":"xxxxx",
449 "pending_corpid":"xxxxx"
450 }
451
452 =head4 参数说明:
453
454 参数 必须 说明
455 access_token 是 调用接口凭证。上游企业应用access_token
456 chain_id 是 上下游id
457 corpid 否 已加入企业id
458 pending_corpid 否 待加入企业id(corpid和pending_corpid至少填一个,同时填corpid生效
459
460 =head4 权限说明:
461
462 自建应用/代开发应用可调用,仅可指定应用可见范围内的企业
463 上下游- 可调用接口的应用」应用调用,可指定上下游内的所有企业
464
465 =head3 RETURN 返回结果
466
467 {
468 "errcode": 0,
469 "errmsg": "ok",
470 "corp_name":"美馨粮油公司",
471 "qualification_status":1,
472 "custom_id": "xxxxx",
473 "groupid": 1,
474 "is_joined": false
475 }
476
477 =head4 RETURN 参数说明
478
479 参数 说明
480 errcode 返回码
481 errmsg 对返回码的文本描述内容
482 corp_name 企业名称
483 qualification_status 企业是否验证或认证,1表示未验证,2表示已验证,3表示已认证,已加入的企业返回
484 custom_id 上下游企业自定义id,返回批量导入上下游联系人时指定的企业自定义id,如未指定则该字段为空
485 groupid 企业所属上下游的分组id
486 is_joined 企业是否已加入
487
488 =cut
489
490 sub get_chain_corpinfo {
491 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
492 my $access_token = $_[0];
493 my $json = $_[1];
494 my $ua = LWP::UserAgent->new;
495 $ua->timeout(30);
496 $ua->env_proxy;
497
498 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/get_chain_corpinfo?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
499 if ($response->is_success) {
500 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
501 }
502
503 }
504 return 0;
505 }
506
507 =head2 remove_corp(access_token, hash);
508
509 移除企业
510 最后更新:2023/11/30
511
512 =head2 SYNOPSIS
513
514 L<https://developer.work.weixin.qq.com/document/path/95822>
515
516 =head3 请求说明:
517
518 上级/上游企业通过该接口移除下游企业
519
520 =head4 请求包结构体为:
521
522 {
523 "chain_id":"xxxx",
524 "corpid":"xxxxx",
525 "pending_corpid":"xxxx"
526 }
527
528 =head4 参数说明:
529
530 参数 必须 说明
531 access_token 是 调用接口凭证。上游企业应用access_token
532 chain_id 是 上下游id
533 corpid 否 需要移除的下游企业corpid
534 pending_corpid 否 需要移除的未加入下游企业corpid,corpid和pending_corpid至少填一个,都填corpid生效
535
536 =head4 权限说明:
537
538 仅已验证的企业可调用
539 调用的应用需要满足如下的权限
540 应用类型 权限要求
541 自建应用 配置到「上下游- 可调用接口的应用」中
542
543 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
544 并发限制:1
545
546 =head3 RETURN 返回结果
547
548 {
549 "errcode": 0,
550 "errmsg": "ok"
551 }
552
553 =head4 RETURN 参数说明
554
555 参数 说明
556 errcode 返回码
557 errmsg 对返回码的文本描述内容
558
559 =cut
560
561 sub remove_corp {
562 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
563 my $access_token = $_[0];
564 my $json = $_[1];
565 my $ua = LWP::UserAgent->new;
566 $ua->timeout(30);
567 $ua->env_proxy;
568
569 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/remove_corp?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
570 if ($response->is_success) {
571 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
572 }
573
574 }
575 return 0;
576 }
577
578 =head2 get_chain_user_custom_id(access_token, hash);
579
580 查询成员自定义id
581 最后更新:2023/11/29
582
583 =head2 SYNOPSIS
584
585 L<https://developer.work.weixin.qq.com/document/path/97441>
586
587 =head3 请求说明:
588
589 上级企业自建应用/代开发应用通过本接口查询成员自定义 id
590
591 =head4 请求包结构体为:
592
593 {
594 "chain_id":"Chxxxxxx",
595 "corpid":"xxxxx",
596 "userid":"xxxxx"
597 }
598
599 =head4 参数说明:
600
601 参数 必须 说明
602 access_token 是 调用接口凭证。上游企业应用access_token
603 chain_id 是 上下游id
604 corpid 否 已加入企业id
605 userid 是 企业内的成员
606
607 =head4 权限说明:
608
609 自建应用、代开发应用和「上下游- 可调用接口的应用」可调用,仅可指定应用可见范围内的企业
610
611 =head3 RETURN 返回结果
612
613 {
614 "errcode": 0,
615 "errmsg": "ok",
616 "user_custom_id":"1234"
617 }
618
619 =head4 RETURN 参数说明
620
621 参数 说明
622 errcode 返回码
623 errmsg 对返回码的文本描述内容
624 user_custom_id 成员自定义 id
625
626 =cut
627
628 sub get_chain_user_custom_id {
629 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
630 my $access_token = $_[0];
631 my $json = $_[1];
632 my $ua = LWP::UserAgent->new;
633 $ua->timeout(30);
634 $ua->env_proxy;
635
636 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/corpgroup/corp/get_chain_user_custom_id?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
637 if ($response->is_success) {
638 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
639 }
640
641 }
642 return 0;
643 }
644
645 1;
646 __END__