File Coverage

blib/lib/Webqq/Client/Method/_prepare_for_login.pm
Criterion Covered Total %
statement 6 25 24.0
branch 0 6 0.0
condition n/a
subroutine 2 3 66.6
pod n/a
total 8 34 23.5


line stmt bran cond sub pod time code
1 1     1   5 use URI::Escape qw(uri_escape);
  1         1  
  1         54  
2 1     1   4 use Webqq::Client::Util qw(console);
  1         1  
  1         210  
3             sub Webqq::Client::_prepare_for_login{
4 0     0     my $self = shift;
5 0           console "初始化 $self->{type} 客户端参数...\n";
6 0           my $ua = $self->{ua};
7 0           my $webqq_api_url = '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            
9 0           my $smartqq_api_url = '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';
10            
11 0 0         my $api_url = $self->{type} eq 'webqq'? $webqq_api_url
12             : $smartqq_api_url
13             ;
14 0 0         my @headers = $self->{type} eq 'webqq'? (Referer=>'http://web2.qq.com/webqq.html')
15             : (Referer=>'http://w.qq.com/')
16             ;
17 0           my @global_param = qw(
18             g_pt_version
19             g_login_sig
20             g_style
21             g_mibao_css
22             g_daid
23             g_appid
24             );
25              
26 0           my $regex_pattern = 'var\s*(' . join("|",@global_param) . ')\s*=\s*encodeURIComponent\("(.*?)"\)';
27 0           for(my $i=1;$i<=$self->{ua_retry_times};$i++){
28 0           my $response = $ua->get($api_url,@headers);
29 0 0         if($response->is_success){
30 0           my $content = $response->content();
31 0           my %kv = map {uri_escape($_)} $content=~/$regex_pattern/g ;
  0            
32 0           for(keys %kv){
33 0           $self->{qq_param}{$_} = $kv{$_};
34             }
35 0           return 1;
36             }
37             }
38 0           return 0;
39             }
40             1;