work/security.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 52 CC 3 SCAR 16.7
CC
3
Cov
0%
get_file_oper_record
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
1 package QQ::weixin::work::security;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::security
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_file_oper_record /;
24
25 =head1 FUNCTION
26
27 =head2 get_file_oper_record(access_token, hash);
28
29 文件防泄漏
30 最后更新:2023/11/30
31
32 =head2 SYNOPSIS
33
34 L<https://developer.work.weixin.qq.com/document/path/98079>
35
36 =head3 请求说明:
37
38 启用了 “文件防泄漏”的企业可以通过本接口查询文件上传、下载、转发等操作记录。
39
40 =head4 请求包结构体为:
41
42 {
43 "start_time": 166666666,
44 "end_time": 166666667,
45 "userid_list": ["zhangsan", "lisi"],
46 "operation": {
47 "type": 103,
48 "source":401
49 },
50 "cursor":"ngLgjieajgieo",
51 "limit":100
52 }
53
54 =head4 参数说明:
55
56 参数 必须 说明
57 access_token 是 调用接口凭证
58 start_time int 是 开始时间
59 end_time int 是 结束时间,开始时间到结束时间的范围不能超过14天
60 userid_list array 否 需要查询的文件操作者的userid,单次最多可以传100个用户
61 operation object 否 参考Operation结构说明
62 cursor string 否 由企业微信后台返回,第一次调用可不填
63 limit int 否 限制返回的条数,最多设置为1000
64
65 =head4 调用说明:
66
67 调用的应用需要满足如下的权限:
68 应用类型 权限要求
69 自建应用 配置到「文件防泄漏 - 可调用接口的应用」中
70 代开发应用 暂不支持
71 第三方应用 暂不支持
72 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
73
74 已产生的操作记录将永久保存
75 应用可见范围外用户相关的数据会被过滤掉,不会返回
76
77 =head3 RETURN 返回结果:
78
79 {
80 "errcode": 0,
81 "errmsg": "ok",
82 "has_more": true,
83 "next_cursor": "gejMjgLjgeigoejg",
84 "record_list": [{
85 "time": 16666666666,
86 "userid": "zhangsan",
87 "operation": {
88 "type": 101,
89 "source": 401
90 },
91 "file_info": "1234567890.jpg"
92 }, {
93 "time": 16666666666,
94 "external_user":{
95 "type":2,
96 "name":"xxx",
97 "corp_name":"十分科技"
98 },
99 "operation": {
100 "type": 10001
101 },
102 "file_info": "通过zhangsan的链接下载了1234567890.jpg",
103 "applicant_name":"张三"
104 },{
105 "time": 16666666666,
106 "userid":"lisi",
107 "operation": {
108 "type": 103,
109 "source":401
110 },
111 "file_info": "通过zhangsan的链接下载了1234567890.jpg",
112 "device_type":1,
113 "device_code":"owM2ovo"
114 }]
115 }
116
117 =head4 RETURN 参数说明:
118
119 参数 说明
120 errcode int32 错误码
121 errmsg string 错误码说明
122 has_more bool 是否还有更多数据
123 next_cursor string 仅has_more值为true时返回该字段,下一次调用将该值填到cursor字段,以实现分页查询
124 record_list.time int 操作时间
125 record_list.userid string 企业用户账号id,当操作者为企业内部用户时返回该字段
126 record_list.external_user object 企业外部人员账号信息,参考ExternalUser结构说明,当操作者为企业外部用户时返回该结构
127 record_list.operation object 参考Operation结构说明
128 record_list.file_info string 文件操作说明
129 record_list.applicant_name string 当记录操作类型为『通过下载申请』或者『拒绝下载申请』时,该字段表示申请人的名字
130 record_list.device_type int 设备类型
131 1-企业可信设备
132 2-个人可信设备
133 仅当操作类型为『下载』时会返回
134 record_list.device_code string 设备编码。仅当操作类型为『下载』时会返回
135
136 =head4 Operation结构说明
137
138 参数 类型 说明
139 type int 操作类型,101:上传;102:新建文件夹;103:下载;104:更新;105:星标;106:移动;107:复制;108:重命名;109:删除;110:恢复;111:彻底删除;112:转发到企业微信;113:通过链接下载;114:获取分享链接;115:修改分享链接;116:关闭分享链接;117:收藏;118:新建文档;119:新建表格;121:打开;124:导出文件;127:添加文件成员;128:修改文件成员权限;129:移除文件成员;130:设置文档水印;131:修改企业内权限;132:修改企业外权限;133:添加快捷入口;134:转发到微信;135:预览;136:权限管理;139:安全设置;140:通过邮件分享;142:离职成员文件转交;10001:通过下载申请;10002:拒绝下载申请;
140 source int 操作来源,在操作类型为“上传”或者“下载”时,可以通过改字段细分操作来源。401:聊天;402:邮件;403:文档;404:微盘;405:日程
141
142 =head4 ExternalUser结构说明
143
144 参数 类型 说明
145 type int 用户类型,1:微信用户;2:企业微信用户
146 name string 用户名
147 corp_name string 当用户为企业微信用户时,返回该字段
148
149 =cut
150
151 sub get_file_oper_record {
152 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
153 my $access_token = $_[0];
154 my $json = $_[1];
155 my $ua = LWP::UserAgent->new;
156 $ua->timeout(30);
157 $ua->env_proxy;
158
159 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/security/get_file_oper_record?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
160 if ($response->is_success) {
161 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
162 }
163
164 }
165 return 0;
166 }
167
168 1;
169 __END__