exmail.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 48 CC 3 SCAR 17.5
CC
3
Cov
0%
gettoken
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.8
1 package QQ::exmail;
2
3 =pod
4
5 =encoding utf8
6
7 =head1 Name
8
9 QQ::exmail
10
11 =head1 DESCRIPTION
12
13 腾讯企业邮->接口文档
14
15 L<https://exmail.qq.com/qy_mng_logic/doc#10001>
16
17 =head1 SYNOPSIS
18
19 腾讯企业邮开放平台旨在为企业拓展、定制邮箱的功能。我们为开发者提供了五大开放接口:通讯录管理、新邮件提醒、单点登录、系统日志、功能设置。希望帮助企业提升开发效率、降低开发成本和难度,从而提升生产和管理之间的协作效率。
20
21 企业开发流程如下:
22
23 1.获取企业邮的CorpID和CorpSecret:企业邮管理员通过启用应用,获取CorpID和CorpSecret
24
25 2.开发对接相关接口:开发测试应用,对接企业邮接口
26
27 =cut
28
29 use strict;
30 use Encode;
31 use LWP::UserAgent;
32 use JSON;
33 use utf8;
34
35 our $VERSION = '1.10';
36 our @EXPORT = qw/ gettoken /;
37
38 =head1 FUNCTION
39
40 =head2 gettoken(corpid,corpsecrect);
41
42 获取ACCESS_TOKEN
43
44 =head3 SYNOPSIS
45
46 L<https://exmail.qq.com/qy_mng_logic/doc#10003>
47
48 =head3 参数说明
49
50 参数 必须 说明
51 corpid 是 企业id
52 corpsecret 是 应用的凭证密钥
53
54 =head3 权限说明
55
56 每个应用有不同的secret,代表了对应用的不同权限
57
58 =head3 RETURN 返回结果
59
60 {
61 "access_token": "accesstoken000001",
62 "expires_in": 7200
63 }
64
65 =head4 RETURN 参数说明
66
67 参数 说明
68 access_token 获取到的凭证。长度为64至512个字节
69 expires_in 凭证的有效时间(秒)
70
71 =head4 RETURN 出错返回示例
72
73 {
74 "errcode": 40001,
75 "errmsg": "invalid credential"
76 }
77
78 =cut
79
80 sub gettoken {
81 if ( @_ && $_[0] && $_[1] ) {
82 my $corpid = $_[0];
83 my $corpsecret = $_[1];
84 my $ua = LWP::UserAgent->new;
85 $ua->timeout(30);
86 $ua->env_proxy;
87
88 my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$corpsecret");
89 if ($response->is_success) {
90 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
91 }
92
93 }
94 return 0;
95 }
96
97
98 1;
99 __END__