Webqq/Client/Method/_get_img_verify_code.pm

filter: Statementstmt 18.4% 7 / 38 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod n/a totaltotal 15.7% 9 / 57 CC 9 SCAR 43.0
CC
9
Cov
13%
_get_img_verify_code
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 73.8
« Webqq/Client/Method/_get_discuss_list_info.pm ↑ Summary Webqq/Client/Method/_get_offpic.pm »
1 1 ▶use File::Temp qw/tempfile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use Webqq::Client::Util qw(console);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶sub Webqq::Client::_get_img_verify_code{
Subroutine _get_img_verify_code: not called CC=9 SCAR=45.0
4 0 my $self = shift;
5 0 ▶ if ($self->{qq_param}{is_need_img_verifycode} == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"qq_param"}{"is_need_img_verifycode"} == 0) 0 0 0
6 0 $self->{qq_param}{img_verifycode_source} = 'NONE';
7 0 return 1 ;
8 }
9 0 my $ua = $self->{ua};
10 0 my $api_url = 'https://ssl.captcha.qq.com/getimage';
11 0 ▶ my @headers = $self->{type} eq 'webqq'? (Referer => 'https://ui.ptlogin2.qq.com/cgi-bin/login?daid=164&target=self&style=5&mibao_css=m_webqq&appid=1003903&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20140612002')
Branch: 1 branch
BranchTrueFalseTotal
$self->{'type'} eq 'webqq' ? : 0 0 0
12 : (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%2Fw.qq.com%2Fproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20131024001')
13 ;
14 my @query_string = (
15 aid => $self->{qq_param}{g_appid},
16 r => rand(),
17 uin => $self->{qq_param}{qq},
18 cap_cd => $self->{qq_param}{cap_cd},
19 0 );
20  
21 0 my @query_string_pairs;
22 0 ▶ push @query_string_pairs , shift(@query_string) . "=" . shift(@query_string) while(@query_string) ;
Branch: 1 branch
BranchTrueFalseTotal
@query_string and do { push @query_string_pairs, shift(@query_string) . '=' . shift(@query_string) } 0 0 0
23
24 0 ▶ for(my $i=1;$i<=$self->{ua_retry_times};$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->{"ua_retry_times"}) 0 0 0
25 0 my $response = $ua->get($api_url.'?'.join("&",@query_string_pairs),@headers);
26 0 ▶ if($response->is_success){
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
27 0 my ($fh, $filename) = tempfile("webqq_img_verfiy_XXXX",SUFFIX =>".jpg",TMPDIR => 1);
28 0 binmode $fh;
29 0 print $fh $response->content();
30 0 close $fh;
31 0 ▶ if(-t STDIN){
Branch: 2 branches
BranchTrueFalseTotal
if (-t STDIN) { } 0 0 0
elsif (ref $self->{'on_input_img_verifycode'} eq 'CODE') { } 0 0 0
32 0 console "请输入图片验证码 [ $filename ]: ";
33 0 chomp($self->{qq_param}{verifycode} = <STDIN>);
34 0 $self->{qq_param}{img_verifycode_source} = 'TTY';
35 }
36 elsif(ref $self->{on_input_img_verifycode} eq 'CODE'){
37 0 my $code = $self->{on_input_img_verifycode}->($filename);
38 0 ▶ if(defined $code){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) { } 0 0 0
39 0 $self->{qq_param}{verifycode} = $code;
40 0 $self->{qq_param}{img_verifycode_source} = 'CALLBACK';
41 }
42 0 else{console "无法从回调函数中获取有效的验证码,客户端终止\n";$self->stop();}
43 }
44 else{
45 0 console "STDIN未连接到tty,无法输入验证码,客户端终止...\n";
46 0 $self->stop();
47 }
48 0 return 1;
49 }
50 }
51 0 return 0;
52 }
53 1 1;
« Webqq/Client/Method/_get_discuss_list_info.pm ↑ Summary Webqq/Client/Method/_get_offpic.pm »