exmail/mail.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 57 CC 3 SCAR 16.7
CC
3
Cov
0%
newcount
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
1 package QQ::exmail::mail;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::exmail::mail
8
9 =head1 DESCRIPTION
10
11 新邮件提醒
12
13 =cut
14
15 use strict;
16 use base qw(QQ::exmail);
17 use Encode;
18 use LWP::UserAgent;
19 use JSON;
20 use utf8;
21
22 our $VERSION = '1.10';
23 our @EXPORT = qw/ newcount /;
24
25 =head1 FUNCTION
26
27 =head2 newcount(access_token, userid, hash);
28
29 获取邮件未读数
30
31 =head2 SYNOPSIS
32
33 L<https://exmail.qq.com/qy_mng_logic/doc#10033>
34
35 =head3 请求说明:
36
37 =head4 请求包结构体为:
38
39 {
40 "type": 0,
41 "begin_date": "2016-10-01",
42 "end_date": "2016-10-07"
43 }
44
45 =head4 参数说明:
46
47 参数 必须 说明
48 access_token 是 调用接口凭证
49 userid 是 成员UserID
50 begin_date 是 开始日期。格式为2016-10-01
51 end_date 是 结束日期。格式为2016-10-07
52
53 =head3 权限说明
54
55 系统应用须拥有指定成员的查看权限。
56
57 =head3 返回结果
58
59 {
60 "errcode": 0,
61 "errmsg": "ok",
62 "count": 1
63 }
64
65 =head4 参数说明
66
67 参数 说明
68 errcode 返回码
69 errmsg 对返回码的文本描述内容
70 count 未读邮件数
71
72 =cut
73
74 sub newcount {
75 if ( @_ && $_[0] && $_[1] && ref $_[2] eq 'HASH' ) {
76 my $access_token = $_[0];
77 my $userid = $_[1];
78 my $json = $_[2];
79 my $ua = LWP::UserAgent->new;
80 $ua->timeout(30);
81 $ua->env_proxy;
82
83 my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/mail/newcount?access_token=$access_token&userid=$userid",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
84 if ($response->is_success) {
85 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
86 }
87
88 }
89 return 0;
90 }
91
92
93 1;
94 __END__