File Coverage

blib/lib/Mojo/Webqq/Client/Remote/_get_qrlogin_pic.pm
Criterion Covered Total %
statement 6 30 20.0
branch 0 10 0.0
condition n/a
subroutine 2 3 66.6
pod n/a
total 8 43 18.6


line stmt bran cond sub pod time code
1 1     1   7 use Encode ();
  1         4  
  1         25  
2 1     1   7 use Encode::Locale;
  1         2  
  1         321  
3             sub Mojo::Webqq::Client::_get_qrlogin_pic {
4 0     0     my $self = shift;
5 0 0         return 1 if $self->login_type ne "qrlogin";
6 0           $self->info("正在获取登录二维码...");
7 0           my $api = 'https://ssl.ptlogin2.qq.com/ptqrshow';
8 0           my @query_string = (
9             appid => 501004106,
10             e => 2,
11             l => 'M',
12             s => 3,
13             d => 72,
14             v => 4,
15             t => rand(),
16             daid => 164,
17             pt_3rd_aid => 0,
18             );
19 0           my $url = $self->gen_url($api,@query_string);
20 0           my $data = $self->http_get($url,{Referer=>'https://xui.ptlogin2.qq.com/cgi-bin/xlogin?daid=164&target=self&style=40&pt_disable_pwd=1&mibao_css=m_webqq&appid=501004106&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2F' . $self->domain . '%2Fproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20131024001',ua_debug_res_body=>0});
21 0 0         if( not defined $data){
22 0           $self->error("登录二维码下载失败");
23 0           return 0;
24             }
25 0           $self->clean_qrcode();
26 0           eval{
27 0 0         die "未设置二维码保存路径\n" if not defined $self->qrcode_path;
28 0 0         open(my $fh,">",$self->qrcode_path) or die "$!\n";
29 0           binmode $fh;
30 0           print $fh $data;
31 0           close $fh;
32             };
33            
34 0 0         if($@){
35 0           $self->error("二维码写入文件失败: $@");
36 0           return 0;
37             }
38              
39 0           my $filename_for_log = Encode::encode("utf8",Encode::decode(locale_fs,$self->qrcode_path));
40             #$self->info("二维码已下载到本地[ $filename_for_log ]\n二维码原始下载地址[ $url ]");
41 0           $self->info("二维码已下载到本地[ $filename_for_log ]");
42 0           $self->emit(input_qrcode=>$self->qrcode_path,$data);
43 0           return 1;
44             }
45             1;