Weixin/Plugin/UploadQRcode.pm untested

filter: Statementstmt 0.0% 0 / 16 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 28 CC 3 SCAR 22.5
CC
3
Cov
0%
call
12.0
BEGIN
2.0
CRAP 9.5
1 package Mojo::Weixin::Plugin::UploadQRcode;
2 our $CALL_ON_LOAD=1;
3 use strict;
4 sub call{
5 my $client = shift;
6 my $data = shift;
7 $client->on(input_qrcode=>sub{
8 my($client,$qrcode_path,$qrcode_data) = @_;
9 #需要产生随机的云存储路径,防止好像干扰
10 my $json = $client->http_post('https://sm.ms/api/upload',{json=>1},form=>{
11 format=>'json',
12 smfile=>{filename=>$qrcode_path,content=>$qrcode_data},
13 });
14 if(not defined $json){
15 $client->warn("二维码图片上传云存储失败: 响应数据异常");
16 return;
17 }
18 elsif(defined $json and $json->{code} ne 'success' ){
19 $client->warn("二维码图片上传云存储失败: " . $json->{msg});
20 return;
21 }
22 $client->qrcode_upload_url($json->{data}{url});
23 $client->info("二维码已上传云存储[ ". $json->{data}{url} . " ]");
24 });
25 }
26 1;