File Coverage

blib/lib/Webqq/Client/Method/_check_verify_code.pm
Criterion Covered Total %
statement 3 34 8.8
branch 0 14 0.0
condition n/a
subroutine 1 2 50.0
pod n/a
total 4 50 8.0


line stmt bran cond sub pod time code
1 1     1   5 use Webqq::Client::Util qw(console);
  1         2  
  1         446  
2             sub Webqq::Client::_check_verify_code{
3 0     0     console "检查验证码...\n";
4 0           my $self = shift;
5 0           my $ua = $self->{ua};
6 0           my $api_url = 'https://ssl.ptlogin2.qq.com/check';
7 0 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')
8             : (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')
9             ;
10              
11 0 0         my $query_string_ul = $self->{type} eq 'webqq'? 'http%3A%2F%2Fweb2.qq.com%2Floginproxy.html'
12             : 'http%3A%2F%2Fw.qq.com%2Fproxy.html'
13             ;
14 0           my @query_string = (
15             uin => $self->{qq_param}{qq},
16             appid => $self->{qq_param}{g_appid},
17             js_ver => $self->{qq_param}{g_pt_version},
18             js_type => 0,
19             login_sig => $self->{qq_param}{g_login_sig},
20             u1 => $query_string_ul,
21             r => rand(),
22             );
23            
24 0 0         if($self->{type} eq 'smartqq'){
25 0           unshift @query_string,(
26             pt_tea => 1,
27             );
28             }
29            
30 0           my @query_string_pairs;
31 0           push @query_string_pairs , shift(@query_string) . "=" . shift(@query_string) while(@query_string);
32              
33 0           $ua->cookie_jar()->set_cookie(0,"chkuin",$self->{qq_param}{qq},"/","ptlogin2.qq.com",);
34              
35 0           for(my $i=1;$i<=$self->{ua_retry_times};$i++){
36 0           my $response = $ua->get($api_url.'?'.join("&",@query_string_pairs),@headers);
37 0 0         if($response->is_success){
38 0           my $content = $response->content();
39 0 0         print $content,"\n" if $self->{debug};
40 0           my %d = ();
41 0           @d{qw( retcode cap_cd md5_salt verifysession isRandSalt)} = $content=~/'(.*?)'/g ;
42 0           $d{md5_salt} =~ s/\\\\x/\x/g;
43             #$self->{qq_param}{md5_salt} = eval qq{"$d{md5_salt}"};
44 0           $self->{qq_param}{md5_salt} = $d{md5_salt};
45 0           $self->{qq_param}{cap_cd} = $d{cap_cd};
46 0           $self->{qq_param}{verifysession} = $d{verifysession};
47 0           $self->{qq_param}{isRandSalt} = $d{isRandSalt};
48 0 0         if($d{retcode} ==0){
    0          
49 0           console "检查结果: 很幸运,本次登录不需要验证码\n";
50 0           $self->{qq_param}{verifycode} = $d{cap_cd};
51             }
52             elsif($d{retcode} == 1){
53 0           console "检查结果: 需要输入图片验证码\n";
54 0           $self->{qq_param}{is_need_img_verifycode} = 1
55             }
56            
57 0           return 1;
58             }
59             }
60 0           return 0;
61             }
62             1;