work/security/trustdevice.pm untested

filter: Statementstmt 0.0% 0 / 81 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 177 CC 13 SCAR 22.5
CC
13
Cov
0%
import
12.0
list
12.0
get_by_user
12.0
CRAP 9.5
1 package QQ::weixin::work::security::trustdevice;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::security::trustdevice
8
9 =head1 DESCRIPTION
10
11 设备管理
12 最后更新:2023/12/01
13
14 =cut
15
16 use strict;
17 use base qw(QQ::weixin::work::security);
18 use Encode;
19 use LWP::UserAgent;
20 use JSON;
21 use utf8;
22
23 our $VERSION = '0.10';
24 our @EXPORT = qw/ import list get_by_user delete approve reject /;
25
26 =head1 FUNCTION
27
28 =head2 import(access_token, hash);
29
30 导入可信企业设备
31
32 =head2 SYNOPSIS
33
34 L<https://developer.work.weixin.qq.com/document/path/98920>
35
36 =head3 请求说明:
37
38 启用了 “设备管理”的企业可以通过相关接口导入可信企业设备,获取/删除可信企业设备、可信个人设备、未知设备,并对未知设备的归属申请进行确认或驳回。
39
40 =head4 请求包结构体为:
41
42 {
43 "device_list":
44 [
45 {
46 "system":"Windows",
47 "mac_addr":
48 [
49 "50:81:40:29:33:CA",
50 "36:27:51:DF:6E:80"
51 ],
52 "motherboard_uuid":"MB_UUID",
53 "harddisk_uuid":
54 [
55 "HD_UUID1",
56 "HD_UUID2"
57 ],
58 "domain":"WINDOWS_DOMAIN",
59 "pc_name":"PC_001",
60 },
61 {
62 "system":"Mac",
63 "seq_no":"SEQ_NO",
64 "mac_addr":
65 [
66 "81:40:50:29:33:DB"
67 ]
68 }
69 ]
70 }
71
72 =head4 参数说明:
73
74 参数 必须 说明
75 access_token 是 调用接口凭证
76 device_list.system string 是 设备的类型,Windows或Mac
77 device_list.mac_addr string 是 设备MAC地址,当system为Windows时必填,Mac选填,每个设备最多100个
78 device_list.motherboard_uuid string 否 主板UUID,当system为Windows可选填此参数
79 device_list.harddisk_uuid string 否 硬盘序列号,当system为Windows时可选填此参数,每个设备最多100个
80 device_list.domain string 否 Windows域名,当system为Windows时可选填此参数
81 device_list.pc_name string 否 Windows计算机名,当system为Windows时可选填此参数
82 device_list.seq_no string 是 Mac序列号,当system为Mac时必填
83
84 =head4 权限说明
85
86 调用设备管理相关接口的应用需要满足如下的权限:
87
88 应用类型 权限要求
89 自建应用 配置到「安全与管理 - 设备管理 - 可调用接口的应用」中
90 代开发应用 暂不支持
91 第三方应用 暂不支持
92
93 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
94
95 =head4 调用说明
96
97 每次调用最多导入100条可信企业设备记录
98
99 =head3 RETURN 返回结果:
100
101 {
102 "errcode": 0,
103 "errmsg": "ok",
104 "result":
105 [
106 {
107 "device_index":1,
108 "device_code":"49nNtYq",
109 "status":1
110 },
111 {
112 "device_index":2,
113 "status":2
114 },
115 {
116 "device_index":3,
117 "status":3
118 }
119 ]
120 }
121
122 =head4 RETURN 参数说明:
123
124 参数 说明
125 errcode int32 错误码
126 errmsg string 错误码说明
127 result.device_index int32 导入设备记录的标识,对应请求中设备的顺序,从1开始
128 result.device_code string 设备的唯一标识,仅导入成功的记录返回
129 result.status int32 导入结果,1-成功 2-重复导入 3-不支持的设备 4-数据格式错误
130
131 =cut
132
133 sub import {
134 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
135 my $access_token = $_[0];
136 my $json = $_[1];
137 my $ua = LWP::UserAgent->new;
138 $ua->timeout(30);
139 $ua->env_proxy;
140
141 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/security/trustdevice/import?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
142 if ($response->is_success) {
143 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
144 }
145
146 }
147 return 0;
148 }
149
150 =head2 list(access_token, hash);
151
152 获取设备信息
153
154 =head2 SYNOPSIS
155
156 L<https://developer.work.weixin.qq.com/document/path/98920>
157
158 =head3 请求说明:
159
160 启用了 “设备管理”的企业可以通过相关接口导入可信企业设备,获取/删除可信企业设备、可信个人设备、未知设备,并对未知设备的归属申请进行确认或驳回。
161
162 =head4 请求包结构体为:
163
164 {
165 "cursor":"CURSOR",
166 "limit":100,
167 "type":1
168 }
169
170 =head4 参数说明:
171
172 参数 必须 说明
173 access_token 是 调用接口凭证
174 cursor string 否 分页cursor,用于获取分页数据
175 type int32 是 查询设备类型,1-可信企业设备 2-未知设备 3-可信个人设备
176 limit int32 否 查询返回的最大记录数,最高不超过100,默认为100
177
178 =head4 权限说明
179
180 调用设备管理相关接口的应用需要满足如下的权限:
181
182 应用类型 权限要求
183 自建应用 配置到「安全与管理 - 设备管理 - 可调用接口的应用」中
184 代开发应用 暂不支持
185 第三方应用 暂不支持
186
187 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
188
189 =head4 调用说明
190
191 每次调用最多导入100条可信企业设备记录
192
193 =head3 RETURN 返回结果:
194
195 {
196 "errcode": 0,
197 "errmsg": "ok",
198 "device_list":
199 [
200 {
201 "device_code":"49nNtYq",
202 "system":"Windows",
203 "mac_addr":
204 [
205 "50:81:40:29:33:CA"
206 ],
207 "motherboard_uuid":"MB_UUID",
208 "harddisk_uuid":
209 [
210 "HD_UUID1"
211 ],
212 "domain":"WINDOWS_DOMAIN",
213 "pc_name":"PC_001",
214 "last_login_time":1681722163,
215 "last_login_userid":"lisi",
216 "confirm_timestamp":1681722163,
217 "confirm_userid":"lisi",
218 "approved_userid":"zhangsan",
219 "source":3,
220 "status":5
221 },
222 {
223 "device_code":"rjDTnOh",
224 "system":"Mac",
225 "seq_no":"SEQ_NO1",
226 "mac_addr":
227 [
228 "50:81:40:29:33:CA"
229 ],
230 "source":1,
231 "status":5
232 }
233 ],
234 "next_cursor":"CURSOR"
235 }
236
237 =head4 RETURN 参数说明:
238
239 参数 说明
240 errcode int32 错误码
241 errmsg string 错误码说明
242 device.device_code string 设备编码
243 device_list.system string 设备的类型,Windows或Mac
244 device_list.mac_addr string 设备MAC地址
245 device_list.motherboard_uuid string 主板UUID
246 device_list.harddisk_uuid string 硬盘UUID
247 device_list.domain string Windows域
248 device_list.pc_name string 计算机名
249 device_list.seq_no string Mac序列号
250 device_list.last_login_time int32 设备最后登录时间戳
251 device_list.last_login_userid string 设备最后登录成员userid
252 device_list.confirm_timestamp int32 设备归属/确认时间戳
253 device_list.confirm_userid string 设备归属/确认成员userid
254 device_list.approved_userid string 通过申报的管理员userid
255 device_list.source int32 设备来源 0-未知 1-成员确认 2-管理员导入 3-成员自主申报
256 device_list.status int32 设备状态 1-已导入未登录 2-待邀请 3-待管理员确认为企业设备 4-待管理员确认为个人设备 5-已确认为可信企业设备 6-已确认为可信个人设备
257 next_cursor string 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
258
259 注意,当获取未确认为可信企业设备的记录时,即获取status为2、4、6时,mac地址,序列号,主板UUID等将会返回脱敏数据。
260
261 =cut
262
263 sub list {
264 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
265 my $access_token = $_[0];
266 my $json = $_[1];
267 my $ua = LWP::UserAgent->new;
268 $ua->timeout(30);
269 $ua->env_proxy;
270
271 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/security/trustdevice/list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
272 if ($response->is_success) {
273 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
274 }
275
276 }
277 return 0;
278 }
279
280 =head2 get_by_user(access_token, hash);
281
282 获取成员使用设备
283
284 =head2 SYNOPSIS
285
286 L<https://developer.work.weixin.qq.com/document/path/98920>
287
288 =head3 请求说明:
289
290 启用了 “设备管理”的企业可以通过相关接口导入可信企业设备,获取/删除可信企业设备、可信个人设备、未知设备,并对未知设备的归属申请进行确认或驳回。
291
292 =head4 请求包结构体为:
293
294 {
295 "last_login_userid":"zhangsan",
296 "type":1
297 }
298
299 =head4 参数说明:
300
301 参数 必须 说明
302 access_token 是 调用接口凭证
303 last_login_userid string 是 最后登录的成员userid
304 type int32 是 查询设备类型,1-可信企业设备 2-未知设备 3-可信个人设备
305
306 =head4 权限说明
307
308 调用设备管理相关接口的应用需要满足如下的权限:
309
310 应用类型 权限要求
311 自建应用 配置到「安全与管理 - 设备管理 - 可调用接口的应用」中
312 代开发应用 暂不支持
313 第三方应用 暂不支持
314
315 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
316
317 =head4 调用说明
318
319 每次调用最多导入100条可信企业设备记录
320
321 =head3 RETURN 返回结果:
322
323 {
324 "errcode": 0,
325 "errmsg": "ok",
326 "device_list":
327 [
328 {
329 "device_code":"49nNtYq",
330 "system":"Windows",
331 "mac_addr":
332 [
333 "50:81:40:29:33:CA"
334 ],
335 "motherboard_uuid":"MB_UUID",
336 "harddisk_uuid":
337 [
338 "HD_UUID1"
339 ],
340 "domain":"WINDOWS_DOMAIN",
341 "pc_name":"PC_001",
342 "last_login_time":1681722163,
343 "last_login_userid":"lisi",
344 "confirm_timestamp":1681722163,
345 "confirm_userid":"lisi",
346 "approved_userid":"zhangsan",
347 "source":3,
348 "status":5
349 },
350 {
351 "device_code":"rjDTnOh",
352 "system":"Mac",
353 "seq_no":"SEQ_NO1",
354 "mac_addr":
355 [
356 "50:81:40:29:33:CA"
357 ],
358 "source":1,
359 "status":5
360 }
361 ]
362 }
363
364 =head4 RETURN 参数说明:
365
366 参数 说明
367 errcode int32 错误码
368 errmsg string 错误码说明
369 device_list.device_code string 设备编码
370 device_list.system string 设备的类型,Windows或Mac
371 device_list.mac_addr string 设备MAC地址
372 device_list.motherboard_uuid string 主板UUID
373 device_list.harddisk_uuid string 硬盘UUID
374 device_list.domain string windows域
375 device_list.pc_name string 计算机名
376 device_list.seq_no string Mac序列号
377 device_list.last_login_time int32 设备最后登录时间戳
378 device_list.last_login_userid string 设备最后登录成员userid
379 device_list.confirm_timestamp int32 设备归属/确认时间戳
380 device_list.confirm_userid string 设备归属/确认成员userid
381 device_list.approved_userid string 通过申报的管理员userid
382 device_list.source int32 设备来源 0-未知 1-成员确认 2-管理员导入 3-成员自主申报
383 device_list.status int32 设备状态 1-已导入未登录 2-待邀请 3-待管理员确认为企业设备 4-待管理员确认未个人设备 5-已确认为可信企业设备 6-已确认为可信个人设备
384
385 注意,当获取未确认为可信企业设备的记录时,即获取status为2、4、6时,mac地址,序列号,主板UUID等将会返回脱敏数据。
386
387 =cut
388
389 sub get_by_user {
390 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
391 my $access_token = $_[0];
392 my $json = $_[1];
393 my $ua = LWP::UserAgent->new;
394 $ua->timeout(30);
395 $ua->env_proxy;
396
397 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/security/trustdevice/get_by_user?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
398 if ($response->is_success) {
399 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
400 }
401
402 }
403 return 0;
404 }
405
406 =head2 delete(access_token, hash);
407
408 删除设备信息
409
410 =head2 SYNOPSIS
411
412 L<https://developer.work.weixin.qq.com/document/path/98920>
413
414 =head3 请求说明:
415
416 启用了 “设备管理”的企业可以通过相关接口导入可信企业设备,获取/删除可信企业设备、可信个人设备、未知设备,并对未知设备的归属申请进行确认或驳回。
417
418 =head4 请求包结构体为:
419
420 {
421 "type":1,
422 "device_code_list":
423 [
424 "49nNtYq",
425 "rjDTnOh"
426 ]
427 }
428
429 =head4 参数说明:
430
431 参数 必须 说明
432 access_token 是 调用接口凭证
433 type int32 是 删除设备类型,1-可信企业设备 2-未知设备 3-可信个人设备
434 device_code_list string 是 设备编码列表
435
436 =head4 权限说明
437
438 调用设备管理相关接口的应用需要满足如下的权限:
439
440 应用类型 权限要求
441 自建应用 配置到「安全与管理 - 设备管理 - 可调用接口的应用」中
442 代开发应用 暂不支持
443 第三方应用 暂不支持
444
445 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
446
447 =head4 调用说明
448
449 每次调用可删除100个设备
450
451 =head3 RETURN 返回结果:
452
453 {
454 "errcode": 0,
455 "errmsg": "ok"
456 }
457
458 =head4 RETURN 参数说明:
459
460 参数 说明
461 errcode int32 错误码
462 errmsg string 错误码说明
463
464 =cut
465
466 sub delete {
467 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
468 my $access_token = $_[0];
469 my $json = $_[1];
470 my $ua = LWP::UserAgent->new;
471 $ua->timeout(30);
472 $ua->env_proxy;
473
474 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/security/trustdevice/delete?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
475 if ($response->is_success) {
476 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
477 }
478
479 }
480 return 0;
481 }
482
483 =head2 approve(access_token, hash);
484
485 确认为可信设备
486
487 =head2 SYNOPSIS
488
489 L<https://developer.work.weixin.qq.com/document/path/98920>
490
491 =head3 请求说明:
492
493 启用了 “设备管理”的企业可以通过相关接口导入可信企业设备,获取/删除可信企业设备、可信个人设备、未知设备,并对未知设备的归属申请进行确认或驳回。
494
495 =head4 请求包结构体为:
496
497 {
498 "device_code_list":
499 [
500 "49nNtYq",
501 "rjDTnOh"
502 ]
503 }
504
505 =head4 参数说明:
506
507 参数 必须 说明
508 access_token 是 应用调用凭证
509 device_code_list string 是 设备编码列表, 仅可确认待管理员通过状态,即status为3或4的设备
510
511 =head4 权限说明
512
513 调用设备管理相关接口的应用需要满足如下的权限:
514
515 应用类型 权限要求
516 自建应用 配置到「安全与管理 - 设备管理 - 可调用接口的应用」中
517 代开发应用 暂不支持
518 第三方应用 暂不支持
519
520 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
521
522 =head4 调用说明
523
524 每次调用最多可以确认100个设备
525
526 =head3 RETURN 返回结果:
527
528 {
529 "errcode": 0,
530 "errmsg": "ok",
531 "success_list":["49nNtYq"],
532 "fail_list":["rjDTnOh"]
533 }
534
535 =head4 RETURN 参数说明:
536
537 参数 说明
538 errcode int32 错误码
539 errmsg string 错误码说明
540 success_list string 确认成功设备code列表
541 fail_list string 确认失败设备code列表
542
543 =cut
544
545 sub approve {
546 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
547 my $access_token = $_[0];
548 my $json = $_[1];
549 my $ua = LWP::UserAgent->new;
550 $ua->timeout(30);
551 $ua->env_proxy;
552
553 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/security/trustdevice/approve?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
554 if ($response->is_success) {
555 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
556 }
557
558 }
559 return 0;
560 }
561
562 =head2 reject(access_token, hash);
563
564 驳回可信设备申请
565
566 =head2 SYNOPSIS
567
568 L<https://developer.work.weixin.qq.com/document/path/98920>
569
570 =head3 请求说明:
571
572 启用了 “设备管理”的企业可以通过相关接口导入可信企业设备,获取/删除可信企业设备、可信个人设备、未知设备,并对未知设备的归属申请进行确认或驳回。
573
574 =head4 请求包结构体为:
575
576 {
577 "device_code_list":
578 [
579 "49nNtYq",
580 "rjDTnOh"
581 ]
582 }
583
584 =head4 参数说明:
585
586 参数 必须 说明
587 access_token 是 应用调用凭证
588 device_code_list string 是 设备编码列表,仅可驳回待管理员通过状态,即status为3或4的设备
589
590 =head4 权限说明
591
592 调用设备管理相关接口的应用需要满足如下的权限:
593
594 应用类型 权限要求
595 自建应用 配置到「安全与管理 - 设备管理 - 可调用接口的应用」中
596 代开发应用 暂不支持
597 第三方应用 暂不支持
598
599 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
600
601 =head4 调用说明
602
603 每次调用最多可以拒绝100个设备
604
605 =head3 RETURN 返回结果:
606
607 {
608 "errcode": 0,
609 "errmsg": "ok",
610 "success_list":["49nNtYq"],
611 "fail_list":["rjDTnOh"]
612 }
613
614 =head4 RETURN 参数说明:
615
616 参数 说明
617 errcode int32 错误码
618 errmsg string 错误码说明
619 success_list string 驳回成功设备code列表
620 fail_list string 驳回失败设备code列表
621
622 =cut
623
624 sub reject {
625 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
626 my $access_token = $_[0];
627 my $json = $_[1];
628 my $ua = LWP::UserAgent->new;
629 $ua->timeout(30);
630 $ua->env_proxy;
631
632 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/security/trustdevice/reject?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
633 if ($response->is_success) {
634 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
635 }
636
637 }
638 return 0;
639 }
640
641 1;
642 __END__