line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Webqq::Qun::Authorize; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
599
|
use File::Temp qw/tempfile/; |
|
1
|
|
|
|
|
14292
|
|
|
1
|
|
|
|
|
53
|
|
5
|
1
|
|
|
1
|
|
288
|
use Webqq::Util qw(gen_url); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
978
|
use Webqq::Encryption qw(pwd_encrypt pwd_encrypt_js); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub authorize { |
8
|
|
|
|
|
|
|
my $self = shift; |
9
|
|
|
|
|
|
|
$self->{_authorize}{appid} = 715030901; |
10
|
|
|
|
|
|
|
$self->{_authorize}{daid} = 73; |
11
|
|
|
|
|
|
|
$self->{_authorize}{qq} = $self->{qq}; |
12
|
|
|
|
|
|
|
$self->{_authorize}{pwd} = $self->{pwd}; |
13
|
|
|
|
|
|
|
if( |
14
|
|
|
|
|
|
|
$self->_prepare() |
15
|
|
|
|
|
|
|
&& $self->_checkVC() |
16
|
|
|
|
|
|
|
&& $self->_getimage() |
17
|
|
|
|
|
|
|
&& $self->_login() |
18
|
|
|
|
|
|
|
&& $self->_check_sig() |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
){ |
21
|
|
|
|
|
|
|
$self->{is_authorize} = 1; |
22
|
|
|
|
|
|
|
return 1; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
return; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
sub _prepare { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
my $ua = $self->{ua}; |
31
|
|
|
|
|
|
|
my $api = 'http://ui.ptlogin2.qq.com/cgi-bin/login'; |
32
|
|
|
|
|
|
|
my @query_string = ( |
33
|
|
|
|
|
|
|
appid => $self->{_authorize}{appid}, |
34
|
|
|
|
|
|
|
daid => $self->{_authorize}{daid}, |
35
|
|
|
|
|
|
|
pt_no_auth => 1, |
36
|
|
|
|
|
|
|
s_url => 'http%3A%2F%2Fqun.qq.com%2F', |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
my @headers = (Referer => 'http://qun.qq.com/'); |
39
|
|
|
|
|
|
|
my $url = gen_url($api,@query_string); |
40
|
|
|
|
|
|
|
my $res = $ua->get($url,@headers); |
41
|
|
|
|
|
|
|
if($res->is_success){ |
42
|
|
|
|
|
|
|
#my $ptui = $res->content =~ /pt\.ptui\s*=\s*{.*?};/s; |
43
|
|
|
|
|
|
|
my ($login_sig) = $res->content =~/login_sig:\s*"([^"]+)"/; |
44
|
|
|
|
|
|
|
$self->{_authorize}{login_sig} = $login_sig; |
45
|
|
|
|
|
|
|
$self->{_authorize}{referer} = $url; |
46
|
|
|
|
|
|
|
return 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else{ |
49
|
|
|
|
|
|
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub search_cookie{ |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
my $cookie_name = shift; |
56
|
|
|
|
|
|
|
my $result = undef; |
57
|
|
|
|
|
|
|
$self->{ua}->cookie_jar->scan(sub{ |
58
|
|
|
|
|
|
|
my($version,$key,$val,$path,$domain,$port,$path_spec,$secure,$expires,$discard,$rest) =@_; |
59
|
|
|
|
|
|
|
if($key eq $cookie_name){ |
60
|
|
|
|
|
|
|
$result = $val ; |
61
|
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
}); |
64
|
|
|
|
|
|
|
return $result; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _checkVC{ |
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
my $ua = $self->{ua}; |
70
|
|
|
|
|
|
|
my $api = 'http://check.ptlogin2.qq.com/check'; |
71
|
|
|
|
|
|
|
my @query_string = ( |
72
|
|
|
|
|
|
|
regmaster => undef, |
73
|
|
|
|
|
|
|
pt_tea => 1, |
74
|
|
|
|
|
|
|
uin => $self->{_authorize}{qq}, |
75
|
|
|
|
|
|
|
appid => $self->{_authorize}{appid}, |
76
|
|
|
|
|
|
|
js_ver => 10116, |
77
|
|
|
|
|
|
|
js_type => 1, |
78
|
|
|
|
|
|
|
login_sig => $self->{_authorize}{login_sig}, |
79
|
|
|
|
|
|
|
ul => 'http%3A%2F%2Fqun.qq.com%2F', |
80
|
|
|
|
|
|
|
r => rand(), |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
my @headers = (Referer => $self->{_authorize}{referer}); |
83
|
|
|
|
|
|
|
my $res = $ua->get(gen_url($api,@query_string),@headers); |
84
|
|
|
|
|
|
|
if($res->is_success){ |
85
|
|
|
|
|
|
|
print $res->content,"\n" if $self->{debug}; |
86
|
|
|
|
|
|
|
my($retcode,$verifycode,$md5_salt,$verifysession,$isRandSalt) = $res->content =~/'([^']*)'/g; |
87
|
|
|
|
|
|
|
if($retcode == 0){ |
88
|
|
|
|
|
|
|
$self->{_authorize}{verifycode} = $verifycode; |
89
|
|
|
|
|
|
|
$self->{_authorize}{md5_salt} = $md5_salt; |
90
|
|
|
|
|
|
|
$self->{_authorize}{isRandSalt} = $isRandSalt; |
91
|
|
|
|
|
|
|
$self->{_authorize}{verifysession} = $verifysession; |
92
|
|
|
|
|
|
|
return 1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif($retcode == 1){ |
95
|
|
|
|
|
|
|
$self->{_authorize}{cap_cd} = $verifycode; |
96
|
|
|
|
|
|
|
$self->{_authorize}{md5_salt} = $md5_salt; |
97
|
|
|
|
|
|
|
$self->{_authorize}{isRandSalt} = $isRandSalt; |
98
|
|
|
|
|
|
|
$self->{_authorize}{verifysession} = $verifysession; |
99
|
|
|
|
|
|
|
$self->{_authorize}{is_need_img_verifycode} = 1; |
100
|
|
|
|
|
|
|
return 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else{ |
103
|
|
|
|
|
|
|
return 0; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else{ |
107
|
|
|
|
|
|
|
return 0; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _getimage { |
112
|
|
|
|
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
return 1 if $self->{_authorize}{is_need_img_verifycode} != 1; |
114
|
|
|
|
|
|
|
my $ua = $self->{ua}; |
115
|
|
|
|
|
|
|
my $api = 'http://captcha.qq.com/getimage'; |
116
|
|
|
|
|
|
|
my @query_string = ( |
117
|
|
|
|
|
|
|
uin => $self->{_authorize}{qq}, |
118
|
|
|
|
|
|
|
aid => $self->{_authorize}{appid}, |
119
|
|
|
|
|
|
|
cap_cd => $self->{_authorize}{cap_cd}, |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
my @headers = (Referer => $self->{_authorize}{referer}); |
122
|
|
|
|
|
|
|
my $res = $ua->get(gen_url($api,@query_string) . "&" . rand(),@headers); |
123
|
|
|
|
|
|
|
if($res->is_success){ |
124
|
|
|
|
|
|
|
my ($fh, $filename) = tempfile("webqq_img_verify_XXXX",SUFFIX =>".jpg",TMPDIR => 1); |
125
|
|
|
|
|
|
|
binmode $fh; |
126
|
|
|
|
|
|
|
print $fh $res->content(); |
127
|
|
|
|
|
|
|
close $fh; |
128
|
|
|
|
|
|
|
if(-t STDIN){ |
129
|
|
|
|
|
|
|
print "input verifycode [ $filename ]: "; |
130
|
|
|
|
|
|
|
chomp($self->{_authorize}{verifycode} = ); |
131
|
|
|
|
|
|
|
return 1; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else{ |
134
|
|
|
|
|
|
|
return 0; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else{return 0;} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _login { |
141
|
|
|
|
|
|
|
my $self = shift; |
142
|
|
|
|
|
|
|
my $ua = $self->{ua}; |
143
|
|
|
|
|
|
|
my $api = 'http://ptlogin2.qq.com/login'; |
144
|
|
|
|
|
|
|
my $p = pwd_encrypt($self->{_authorize}{pwd},$self->{_authorize}{md5_salt},$self->{_authorize}{verifycode},1); |
145
|
|
|
|
|
|
|
my @query_string = ( |
146
|
|
|
|
|
|
|
u => $self->{_authorize}{qq}, |
147
|
|
|
|
|
|
|
verifycode => $self->{_authorize}{verifycode}, |
148
|
|
|
|
|
|
|
pt_vcode_v1 => 0, |
149
|
|
|
|
|
|
|
pt_verifysession_v1 => $self->{_authorize}{verifysession} || $self->search_cookie("verifysession") , |
150
|
|
|
|
|
|
|
pt_randsalt => 0, |
151
|
|
|
|
|
|
|
ptredirect => 1, |
152
|
|
|
|
|
|
|
p => $p, |
153
|
|
|
|
|
|
|
u1 => 'http%3A%2F%2Fqun.qq.com%2F', |
154
|
|
|
|
|
|
|
h => 1, |
155
|
|
|
|
|
|
|
t => 1, |
156
|
|
|
|
|
|
|
g => 1, |
157
|
|
|
|
|
|
|
from_ui => 1, |
158
|
|
|
|
|
|
|
ptlang => 2052, |
159
|
|
|
|
|
|
|
action => '1-10-1427007348452', |
160
|
|
|
|
|
|
|
js_ver => 10116, |
161
|
|
|
|
|
|
|
js_type => 1, |
162
|
|
|
|
|
|
|
login_sig => $self->{_authorize}{login_sig}, |
163
|
|
|
|
|
|
|
pt_uistyle => 20, |
164
|
|
|
|
|
|
|
aid => $self->{_authorize}{appid}, |
165
|
|
|
|
|
|
|
daid => $self->{_authorize}{daid}, |
166
|
|
|
|
|
|
|
); |
167
|
|
|
|
|
|
|
my @headers = (Referer => $self->{_authorize}{referer}); |
168
|
|
|
|
|
|
|
my $res = $ua->get(gen_url($api,@query_string) . "&",@headers); |
169
|
|
|
|
|
|
|
if($res->is_success){ |
170
|
|
|
|
|
|
|
print $res->content,"\n" if $self->{debug}; |
171
|
|
|
|
|
|
|
my($retcode,undef,$api_check_sig,undef,$status,$uin) = $res->content =~/'([^']*)'/g; |
172
|
|
|
|
|
|
|
if($retcode == 0){ |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
elsif($retcode == 4){ |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
elsif($retcode != 0){ |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
$self->{_authorize}{api_check_sig} = $api_check_sig; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
return 1; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
sub _check_sig { |
188
|
|
|
|
|
|
|
my $self = shift; |
189
|
|
|
|
|
|
|
my $ua = $self->{ua}; |
190
|
|
|
|
|
|
|
my $api = $self->{_authorize}{api_check_sig}; |
191
|
|
|
|
|
|
|
my @headers = (Referer => $self->{_authorize}{referer}); |
192
|
|
|
|
|
|
|
my $res = $ua->get($api,@headers); |
193
|
|
|
|
|
|
|
return 1; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |