File Coverage

blib/lib/Mojo/Webqq/Client/Remote/_get_img_verify_code.pm
Criterion Covered Total %
statement 6 46 13.0
branch 0 18 0.0
condition n/a
subroutine 2 3 66.6
pod n/a
total 8 67 11.9


line stmt bran cond sub pod time code
1 1     1   8 use Encode ();
  1         2  
  1         28  
2 1     1   5 use Encode::Locale;
  1         2  
  1         460  
3             sub Mojo::Webqq::Client::_get_img_verify_code{
4 0     0     my $self = shift;
5 0 0         return 1 if $self->login_type ne "login";
6 0 0         return 1 if not $self->is_need_img_verifycode ;
7 0           $self->verifycode(undef);
8 0           my $api_url = 'https://ssl.captcha.qq.com/getimage';
9 0           my $headers ={Referer => 'https://ui.ptlogin2.qq.com/cgi-bin/login?daid=164&target=self&style=16&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'};
10 0           my @query_string = (
11             aid => 501004106,
12             r => rand(),
13             uin => $self->uid,
14             cap_cd => $self->cap_cd,
15             );
16              
17 0           my $content = $self->http_get($self->gen_url($api_url,@query_string),$headers);
18 0 0         unless(defined $content){
19 0           $self->error("验证码下载失败");
20 0           return 0;
21             }
22 0           $self->clean_verifycode();
23 0           eval{
24 0 0         die "未定义验证码保存路径\n" if not defined $self->verifycode_path;
25 0 0         open(my $fh,">",$self->verifycode_path) or die "$!\n";
26 0           binmode $fh;
27 0           print $fh $content;
28 0           close $fh;
29             };
30 0 0         if($@){
31 0           $self->error("验证码写入文件失败: $@");
32 0           return 0;
33             }
34 0 0         if($self->has_subscribers("input_img_verifycode")){
    0          
35 0           $self->emit(input_img_verifycode => $self->verifycode_path);
36 0 0         if(defined $self->verifycode){return 1;}
  0            
37 0           else{$self->fatal("无法从回调函数中获取有效的验证码");$self->stop();return 0;}
  0            
  0            
38             }
39             elsif(-t STDIN){
40 0           my $filename_for_console = Encode::encode("utf8",Encode::decode(locale_fs,$self->verifycode_path));
41 0           my $info = $self->log->format->(time,"info","请输入图片验证码 [ $filename_for_console ]: ");
42 0           chomp($info);
43 0           $self->log->append($info);
44 0           my $verifycode = ;
45 0           chomp($verifycode);
46 0           $self->verifycode($verifycode);
47 0           return 1;
48             }
49             else{
50 0           $self->fatal("未连接到终端,无法获取验证码\n");
51 0           $self->stop();
52 0           return 0;
53             }
54 0           return 0;
55             }
56             1;