work/agent.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 172 CC 13 SCAR 22.5
CC
13
Cov
0%
get
12.0
list
12.0
set
12.0
CRAP 9.5
1 package QQ::weixin::work::agent;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::agent
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 list set
24 set_workbench_template get_workbench_template set_workbench_data /;
25
26 =head1 FUNCTION
27
28 =head2 get(access_token,agentid);
29
30 获取指定的应用详情
31 最后更新:2023/10/31
32
33 =head2 SYNOPSIS
34
35 L<https://developer.work.weixin.qq.com/document/path/90227#获取指定的应用详情>
36
37 =head3 请求说明:
38
39 =head4 参数说明:
40
41 参数 必须 说明
42 access_token 是 调用接口凭证
43 agentid 是 应用id
44
45 =head4 权限说明:
46
47 企业仅可获取当前凭证对应的应用;第三方仅可获取被授权的应用。
48
49 =head3 RETURN 返回结果:
50
51 {
52 "errcode": 0,
53 "errmsg": "ok",
54 "agentid": 1000005,
55 "name": "HR助手",
56 "square_logo_url": "https://p.qlogo.cn/bizmail/FicwmI50icF8GH9ib7rUAYR5kicLTgP265naVFQKnleqSlRhiaBx7QA9u7Q/0",
57 "description": "HR服务与员工自助平台",
58 "allow_userinfos": {
59 "user": [
60 {"userid": "zhangshan"},
61 {"userid": "lisi"}
62 ]
63 },
64 "allow_partys": {
65 "partyid": [1]
66 },
67 "allow_tags": {
68 "tagid": [1,2,3]
69 },
70 "close": 0,
71 "redirect_domain": "open.work.weixin.qq.com",
72 "report_location_flag": 0,
73 "isreportenter": 0,
74 "home_url": "https://open.work.weixin.qq.com",
75 "customized_publish_status":1
76 }
77
78 =head4 RETURN 参数说明:
79
80 参数 说明
81 errcode 出错返回码,为0表示成功,非0表示调用失败
82 errmsg 返回码提示语
83 agentid 企业应用id
84 name 企业应用名称
85 square_logo_url 企业应用方形头像
86 description 企业应用详情
87 allow_userinfos 企业应用可见范围(人员),其中包括userid
88 allow_partys 企业应用可见范围(部门)
89 allow_tags 企业应用可见范围(标签)
90 close 企业应用是否被停用。0:未被停用;1:被停用
91 redirect_domain 企业应用可信域名
92 report_location_flag 企业应用是否打开地理位置上报 0:不上报;1:进入会话上报;
93 isreportenter 是否上报用户进入应用事件。0:不接收;1:接收
94 home_url 应用主页url
95 customized_publish_status 代开发自建应用返回该字段,表示代开发发布状态。0:待开发(企业已授权,服务商未创建应用);1:开发中(服务商已创建应用,未上线);2:已上线(服务商已上线应用且不存在未上线版本);3:存在未上线版本(服务商已上线应用但存在未上线版本)
96
97 =cut
98
99 sub get {
100 if ( @_ && $_[0] && $_[1] ) {
101 my $access_token = $_[0];
102 my $agentid = $_[1];
103 my $ua = LWP::UserAgent->new;
104 $ua->timeout(30);
105 $ua->env_proxy;
106
107 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/agent/get?access_token=$access_token&agentid=$agentid");
108 if ($response->is_success) {
109 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
110 }
111
112 }
113 return 0;
114 }
115
116 =head2 list(access_token);
117
118 获取access_token对应的应用列表
119 最后更新:2023/10/31
120
121 =head2 SYNOPSIS
122
123 L<https://developer.work.weixin.qq.com/document/path/90227#获取access-token对应的应用列表>
124
125 =head3 请求说明:
126
127 =head4 参数说明:
128
129 参数 必须 说明
130 access_token 是 调用接口凭证
131
132 =head4 权限说明:
133
134 企业仅可获取当前凭证对应的应用;第三方仅可获取被授权的应用。
135
136 =head3 RETURN 返回结果:
137
138 {
139 "errcode":0,
140 "errmsg":"ok" ,
141 "agentlist":[
142 {
143 "agentid": 1000005,
144 "name": "HR助手",
145 "square_logo_url": "https://p.qlogo.cn/bizmail/FicwmI50icF8GH9ib7rUAYR5kicLTgP265naVFQKnleqSlRhiaBx7QA9u7Q/0"
146 }
147 ]
148 }
149
150 =head4 RETURN 参数说明:
151
152 参数 说明
153 errcode 出错返回码,为0表示成功,非0表示调用失败
154 errmsg 返回码提示语
155 agentlist AgentItemArray 当前凭证可访问的应用列表
156
157 AgentItem 结构:
158
159 参数 类型 说明
160 agentid Integer 企业应用id
161 name String 企业应用名称
162 square_logo_url String 企业应用方形头像url
163
164 =cut
165
166 sub list {
167 if ( @_ && $_[0] ) {
168 my $access_token = $_[0];
169 my $ua = LWP::UserAgent->new;
170 $ua->timeout(30);
171 $ua->env_proxy;
172
173 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/agent/get?access_token=$access_token");
174 if ($response->is_success) {
175 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
176 }
177
178 }
179 return 0;
180 }
181
182 =head2 set(access_token, hash);
183
184 设置应用
185 最后更新:2021/06/24
186
187 =head2 SYNOPSIS
188
189 L<https://developer.work.weixin.qq.com/document/path/90228>
190
191 =head3 请求说明:
192
193 =head4 请求包结构体为:
194
195 {
196 "agentid": 1000005,
197 "report_location_flag": 0,
198 "logo_mediaid": "j5Y8X5yocspvBHcgXMSS6z1Cn9RQKREEJr4ecgLHi4YHOYP-plvom-yD9zNI0vEl",
199 "name": "财经助手",
200 "description": "内部财经服务平台",
201 "redirect_domain": "open.work.weixin.qq.com",
202 "isreportenter": 0,
203 "home_url": "https://open.work.weixin.qq.com"
204 }
205
206 =head4 参数说明:
207
208 参数 必须 说明
209 access_token 是 调用接口凭证
210 agentid 是 企业应用的id
211 report_location_flag 否 企业应用是否打开地理位置上报 0:不上报;1:进入会话上报;
212 logo_mediaid 否 企业应用头像的mediaid,通过素材管理接口上传图片获得mediaid,上传后会自动裁剪成方形和圆形两个头像
213 name 否 企业应用名称,长度不超过32个utf8字符
214 description 否 企业应用详情,长度为4至120个utf8字符
215 redirect_domain 否 企业应用可信域名。注意:域名需通过所有权校验,否则jssdk功能将受限,此时返回错误码85005
216 isreportenter 否 是否上报用户进入应用事件。0:不接收;1:接收。
217 home_url 否 应用主页url。url必须以http或者https开头(为了提高安全性,建议使用https)。
218
219 =head3 权限说明
220
221 仅企业可调用,可设置当前凭证对应的应用;第三方不可调用。
222
223 =head3 RETURN 返回结果
224
225 {
226 "errcode": 0,
227 "errmsg": "ok"
228 }
229
230 =head4 RETURN 参数说明
231
232 参数 说明
233 errcode 返回码
234 errmsg 对返回码的文本描述内容
235
236 =cut
237
238 sub set {
239 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
240 my $access_token = $_[0];
241 my $json = $_[1];
242 my $ua = LWP::UserAgent->new;
243 $ua->timeout(30);
244 $ua->env_proxy;
245
246 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
247 if ($response->is_success) {
248 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
249 }
250
251 }
252 return 0;
253 }
254
255 =head2 设置工作台自定义展示
256
257 最后更新:2023/03/27
258
259 =head2 set_workbench_template(access_token, hash);
260
261 设置应用在工作台展示的模版
262
263 =head2 SYNOPSIS
264
265 L<https://developer.work.weixin.qq.com/document/path/92535#设置应用在工作台展示的模版>
266
267 =head3 请求说明:
268
269 该接口指定应用自定义模版类型。同时也支持设置企业默认模版数据。若type指定为 "normal" 则为取消自定义模式,改为普通展示模式
270
271 =head4 请求包结构体为:
272
273 {
274 "agentid":1000005,
275 "type":"image",
276 "image":{
277 "url":"xxxx",
278 "jump_url":"http://www.qq.com",
279 "pagepath":"pages/index"
280 },
281 "replace_user_data":true
282 }
283
284 =head4 参数说明:
285
286 参数 必须 说明
287 access_token 是 调用接口凭证
288 type 是 模版类型,目前支持的自定义类型包括 "keydata"、 "image"、 "list"、 "webview" 。若设置的type为 "normal",则相当于从自定义模式切换为普通宫格或者列表展示模式
289 agentid 是 应用id
290 keydata 否 若type指定为 "keydata",且需要设置企业级别默认数据,则需要设置关键数据型模版数据,数据结构参考“关键数据型”
291 image 否 若type指定为 "image",且需要设置企业级别默认数据,则需要设置图片型模版数据,数据结构参考“图片型”
292 list 否 若type指定为 "list",且需要设置企业级别默认数据,则需要设置列表型模版数据,数据结构参考“列表型”
293 webview 否 若type指定为 "webview",且需要设置企业级别默认数据,则需要设置webview型模版数据,数据结构参考“webview型”
294 replace_user_data 否 是否覆盖用户工作台的数据。设置为true的时候,会覆盖企业所有用户当前设置的数据。若设置为false,则不会覆盖用户当前设置的所有数据。默认为false
295
296 =head3 权限说明
297
298 可设置当前凭证对应的应用;
299
300 =head3 RETURN 返回结果
301
302 {
303 "errcode": 0,
304 "errmsg": "ok"
305 }
306
307 =head4 RETURN 参数说明
308
309 参数 说明
310 errcode 返回码
311 errmsg 对返回码的文本描述内容
312
313 =cut
314
315 sub set_workbench_template {
316 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
317 my $access_token = $_[0];
318 my $json = $_[1];
319 my $ua = LWP::UserAgent->new;
320 $ua->timeout(30);
321 $ua->env_proxy;
322
323 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/agent/set_workbench_template?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
324 if ($response->is_success) {
325 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
326 }
327
328 }
329 return 0;
330 }
331
332 =head2 get_workbench_template(access_token, hash);
333
334 获取应用在工作台展示的模版
335
336 =head2 SYNOPSIS
337
338 L<https://developer.work.weixin.qq.com/document/path/92535#获取应用在工作台展示的模版>
339
340 =head3 请求说明:
341
342 =head4 请求包结构体为:
343
344 {
345 "agentid":1000005
346 }
347
348 =head4 参数说明:
349
350 参数 必须 说明
351 access_token 是 调用接口凭证
352 agentid 是 应用id
353
354 =head3 权限说明
355
356 可设置当前凭证对应的应用;
357
358 =head3 RETURN 返回结果
359
360 {
361 "errcode": 0,
362 "errmsg": "ok"
363 }
364
365 =head4 RETURN 参数说明
366
367 参数 说明
368 errcode 返回码
369 errmsg 对返回码的文本描述内容
370
371 =cut
372
373 sub get_workbench_template {
374 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
375 my $access_token = $_[0];
376 my $json = $_[1];
377 my $ua = LWP::UserAgent->new;
378 $ua->timeout(30);
379 $ua->env_proxy;
380
381 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/agent/get_workbench_template?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
382 if ($response->is_success) {
383 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
384 }
385
386 }
387 return 0;
388 }
389
390 =head2 set_workbench_data(access_token, hash);
391
392 设置应用在用户工作台展示的数据
393
394 =head2 SYNOPSIS
395
396 L<https://developer.work.weixin.qq.com/document/path/92535#设置应用在用户工作台展示的数据>
397
398 =head3 请求说明:
399
400 =head4 请求包结构体为:
401
402 {
403 "agentid":1000005,
404 "userid":"test",
405 "type":"keydata",
406 "keydata":{
407 "items":[
408 {
409 "key":"待审批",
410 "data":"2",
411 "jump_url":"http://www.qq.com",
412 "pagepath":"pages/index"
413 },
414 {
415 "key":"带批阅作业",
416 "data":"4",
417 "jump_url":"http://www.qq.com",
418 "pagepath":"pages/index"
419 },
420 {
421 "key":"成绩录入",
422 "data":"45",
423 "jump_url":"http://www.qq.com",
424 "pagepath":"pages/index"
425 },
426 {
427 "key":"综合评价",
428 "data":"98",
429 "jump_url":"http://www.qq.com",
430 "pagepath":"pages/index"
431 }
432 ]
433 }
434 }
435
436 =head4 参数说明:
437
438 参数 必须 说明
439 access_token 是 调用接口凭证
440 agentid 是 应用id
441 userid 是 需要设置的用户的userid
442 type 是 目前支持 "keydata"、 "image"、 "list" 、"webview"
443 keydata 否 若type指定为 "keydata",则需要设置关键数据型模版数据,数据结构参考“关键数据型”
444 image 否 若type指定为 "image",则需要设置图片型模版数据,数据结构参考“图片型”
445 list 否 若type指定为 "list",则需要设置列表型模版数据,数据结构参考“列表型”
446 webview 否 若type指定为 "webview",则需要设置webview型模版数据,数据结构参考“webview数据型”
447
448 =head3 权限说明
449
450 可设置当前凭证对应的应用;设置的userid必须在应用可见范围
451 每个用户每个应用接口限制10次/分钟
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 set_workbench_data {
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/agent/set_workbench_data?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
486 1;
487 __END__