line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
sub Mojo::Weixin::_login { |
2
|
0
|
|
|
0
|
|
|
my $self = shift; |
3
|
0
|
|
|
|
|
|
$self->info("客户端准备登录..."); |
4
|
0
|
|
|
|
|
|
my $api = 'https://login.'. $self->domain .'/cgi-bin/mmwebwx-bin/login'; |
5
|
0
|
0
|
|
|
|
|
if(not $self->_is_need_login()){ |
6
|
0
|
|
|
|
|
|
$self->info("检测到近期登录活动,尝试直接恢复登录"); |
7
|
0
|
|
|
|
|
|
$self->wxuin($self->search_cookie("wxuin")); |
8
|
0
|
|
|
|
|
|
$self->wxsid($self->search_cookie("wxsid")); |
9
|
0
|
0
|
0
|
|
|
|
if(defined $self->wxuin and defined $self->wxsid){ |
10
|
0
|
|
|
|
|
|
$self->login_state("success"); |
11
|
0
|
|
|
|
|
|
return 1; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
else{ |
15
|
0
|
|
|
|
|
|
$self->info("登录状态已失效,需要重新登录"); |
16
|
0
|
|
|
|
|
|
$self->clear_cookie(); |
17
|
|
|
|
|
|
|
} |
18
|
0
|
|
|
|
|
|
my $qrcode_uuid = $self->_get_qrcode_uuid(); |
19
|
0
|
0
|
|
|
|
|
if(not defined $qrcode_uuid){ |
20
|
0
|
|
|
|
|
|
$self->info("无法获取到登录二维码,登录失败"); |
21
|
0
|
|
|
|
|
|
$self->stop(); |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
|
$self->qrcode_uuid($qrcode_uuid); |
24
|
0
|
0
|
|
|
|
|
if(not $self->_get_qrcode_image($qrcode_uuid)){ |
25
|
0
|
|
|
|
|
|
$self->info("下载二维码失败,客户端退出"); |
26
|
0
|
|
|
|
|
|
$self->stop(); |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
my $i=1; |
29
|
0
|
|
|
|
|
|
$self->info("等待手机微信扫描二维码..."); |
30
|
0
|
|
|
|
|
|
$self->state('scaning'); |
31
|
0
|
|
|
|
|
|
while(1){ |
32
|
0
|
|
|
|
|
|
$self->check_controller(); |
33
|
|
|
|
|
|
|
my @query_string = ( |
34
|
|
|
|
|
|
|
loginicon => 'true', |
35
|
|
|
|
|
|
|
uuid => $qrcode_uuid, |
36
|
|
|
|
|
|
|
tip => $show_tip , |
37
|
1
|
|
|
1
|
|
8
|
r => sub{use integer;unpack 'i',~ pack 'l',$self->now() & 0xFFFFFFFF}->(), |
|
1
|
|
|
0
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
_ => $self->now(), |
39
|
|
|
|
|
|
|
); |
40
|
0
|
|
|
|
|
|
my $r = $self->http_get($self->gen_url($api,@query_string)); |
41
|
0
|
0
|
|
|
|
|
next unless defined $r; |
42
|
0
|
|
|
|
|
|
my %data = $r=~/window\.(.+?)=(.+?);/g; |
43
|
0
|
0
|
|
|
|
|
$data{redirect_uri}=~s/^["']|["']$//g if defined $data{redirect_uri}; |
44
|
0
|
0
|
|
|
|
|
if($data{code} == 408){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
select undef,undef,undef,0.5; |
46
|
0
|
0
|
|
|
|
|
if($i==5){ |
47
|
0
|
|
|
|
|
|
$self->emit("qrcode_expire"); |
48
|
0
|
|
|
|
|
|
$self->info("登录二维码已失效,重新获取二维码"); |
49
|
0
|
|
|
|
|
|
$qrcode_uuid = $self->_get_qrcode_uuid(); |
50
|
0
|
|
|
|
|
|
$self->_get_qrcode_image($qrcode_uuid); |
51
|
0
|
|
|
|
|
|
$self->state('scaning'); |
52
|
0
|
|
|
|
|
|
$i = 1; |
53
|
0
|
|
|
|
|
|
next; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
$i++; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif($data{code} == 201){ |
58
|
0
|
|
|
|
|
|
$self->info("手机微信扫码成功,请在手机微信上点击 [登录] 按钮..."); |
59
|
0
|
|
|
|
|
|
$self->state('confirming'); |
60
|
0
|
|
|
|
|
|
$show_tip = 0; |
61
|
0
|
|
|
|
|
|
next; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif($data{code} == 200){ |
65
|
0
|
|
|
|
|
|
$self->info("正在进行登录..."); |
66
|
0
|
0
|
|
|
|
|
if($data{redirect_uri}=~m#https?://([^/]+)#m){ |
67
|
0
|
0
|
0
|
|
|
|
$self->domain($1) if ($1 and $1 ne $self->domain); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
my $data = $self->http_get($data{redirect_uri} . '&fun=new&version=v2&lang=zh_CN',{Referer=>'https://' . $self->domain . '/'}); |
70
|
|
|
|
|
|
|
#0OK@crypt_859d8a8a_3f3db5290570080d1db29da9507e35dersuMHe7xmA0aHW1D138122335hWdpMVCMqXIVfhXLcsJxYrC6bv785tVDLZAres096ZE%3D
|
71
|
0
|
0
|
|
|
|
|
if($data !~ m#^.*#){ |
72
|
0
|
|
|
|
|
|
$self->error("登录返回数据格式无效"); |
73
|
0
|
|
|
|
|
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
my %d = $data=~/<([^<>]+?)>([^<>]+?)<\/\1>/g; |
76
|
0
|
0
|
|
|
|
|
if($d{ret}!=0){ |
77
|
0
|
|
|
|
|
|
$self->error("登录返回状态码异常: $d{ret}, $d{message}"); |
78
|
0
|
|
|
|
|
|
$self->emit(login => -1,$d{message}); |
79
|
0
|
|
|
|
|
|
return 0; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
0
|
|
|
|
$self->skey($d{skey} || ''); |
82
|
0
|
|
0
|
|
|
|
$self->wxsid($d{wxsid} || $self->search_cookie("wxsid")); |
83
|
0
|
|
0
|
|
|
|
$self->wxuin($d{wxuin} || $self->search_cookie("wxuin")); |
84
|
0
|
|
0
|
|
|
|
$self->pass_ticket($d{pass_ticket} || ''); |
85
|
0
|
|
|
|
|
|
$self->info("微信登录成功"); |
86
|
0
|
|
|
|
|
|
$self->login_state("success"); |
87
|
0
|
|
|
|
|
|
return 2; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif($data{code} == 400){ |
90
|
0
|
|
|
|
|
|
$self->info("登录错误,客户端退出"); |
91
|
0
|
|
|
|
|
|
$self->stop(); |
92
|
0
|
|
|
|
|
|
last; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif($data{code} == 500){ |
95
|
0
|
|
|
|
|
|
$self->info("登录错误,客户端尝试重新登录..."); |
96
|
0
|
|
|
|
|
|
$i = 1; |
97
|
0
|
|
|
|
|
|
$show_tip = 1; |
98
|
0
|
|
|
|
|
|
$qrcode_uuid = $self->_get_qrcode_uuid(); |
99
|
0
|
|
|
|
|
|
$self->_get_qrcode_image($qrcode_uuid); |
100
|
0
|
|
|
|
|
|
$self->state('scaning'); |
101
|
0
|
|
|
|
|
|
next; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
1; |