| 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; |