work/media/get.pm untested

filter: Statementstmt 0.0% 0 / 35 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 / 56 CC 3 SCAR 16.7
CC
3
Cov
0%
jssdk
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
1 package QQ::weixin::work::media::get;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::media::get
8
9 =head1 DESCRIPTION
10
11 =cut
12
13 use strict;
14 use base qw(QQ::weixin::work::media);
15 use Encode;
16 use LWP::UserAgent;
17 use JSON;
18 use utf8;
19
20 our $VERSION = '0.10';
21 our @EXPORT = qw/ jssdk /;
22
23 =head1 FUNCTION
24
25 =head2 jssdk(access_token, media_id);
26
27 获取高清语音素材
28 最后更新:2017/11/30
29
30 =head2 SYNOPSIS
31
32 L<https://developer.work.weixin.qq.com/document/path/90255>
33
34 =head3 请求说明:
35
36 可以使用本接口获取从JSSDK的uploadVoice接口上传的临时语音素材,格式为speex,16K采样率。该音频比上文的临时素材获取接口(格式为amr,8K采样率)更加清晰,适合用作语音识别等对音质要求较高的业务。
37
38 =head4 参数说明:
39
40 参数 必须 说明
41 access_token 是 调用接口凭证
42 media_id 是 媒体文件id,见上传临时素材,以及异步上传临时素材(超过20M需使用Range分块下载,且分块大小不超过20M,否则返回错误码830002)
43
44 =head4 权限说明:
45
46 仅企业微信2.4及以上版本支持。
47 完全公开,media_id在同一企业内所有应用之间可以共享。
48
49 =head3 RETURN 返回结果:
50
51 正确时返回(和普通的http下载相同,请根据http头做相应的处理):
52
53 HTTP/1.1 200 OK
54 Connection: close
55 Content-Type: voice/speex
56 Content-disposition: attachment; filename="XXX"
57 Date: Sun, 06 Jan 2013 10:20:18 GMT
58 Cache-Control: no-cache, must-revalidate
59 Content-Length: 339721
60
61 Xxxx
62
63 错误时返回(这里省略了HTTP首部):
64
65 {
66 "errcode": 40007,
67 "errmsg": "invalid media_id"
68 }
69
70 =head4 RETURN 参数说明:
71
72 参数 说明
73 errcode 出错返回码
74 errmsg 对返回码的文本描述内容
75
76 =cut
77
78 sub jssdk {
79 if ( @_ && $_[0] && $_[1] ) {
80 my $access_token = $_[0];
81 my $media_id = $_[1];
82 my $ua = LWP::UserAgent->new;
83 $ua->timeout(30);
84 $ua->env_proxy;
85
86 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=$access_token&media_id=$media_id");
87 if ($response->is_success) {
88 my $reply;
89 $reply->{"content-type"} = $response->content_type;
90 $reply->{filename} = $response->filename;
91 $reply->{data} = $response->decoded_content;
92 return $reply;
93 # return $response->decoded_content;
94 }
95
96 }
97 return 0;
98 }
99
100 1;
101 __END__