my $show_tip = 1; sub login { while (1) { my $api ="https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=$uuid&tip=$show_tip&r=-$now&_=$now"; my $response = $ua->get($api); print "1--$show_tip is $show_tip "; print "2--$api is $api "; sleep (2); $ua->default_headers; if ( $response->is_success ) { $r = $response->decoded_content; print "$r is $r "; next unless defined $r; my %data = $r =~ /window.(.+?)=(.+?);/g; if ( $data{code} == 201 ) { print"手机微信扫码成功,请在手机微信上点击 [登录] 按钮... "; $show_tip = 0; ##回到循环顶部,此时请求的url是"https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=$uuid&tip=$show_tip&r=-$now&_=$now"; next; } elsif ( $data{code} == 200 ) { print "正在进行登录... "; foreach ($r) { if ( $_ =~ /window.redirect_uri="(.*?)"/ ) { $api = $1; print "$api is $api "; my $response = $ua->get($api); $ua->default_headers; } } }; if ( $api =~ /https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=(.*?)&uuid=(.*?)&lang=(.*?)&scan=(.*)/ ) { print "$1 is $1 "; print "$2 is $2 "; print "$3 is $3 "; print "$4 is $4 "; $ticket=$1; $user = $4; print "$user is $user "; return 1; } } else { die $response->status_line; } } }; centos6.5:/root/mojo#perl scan.pl window.QRLogin.code = 200; window.QRLogin.uuid = "gduih3Nyww=="; $uuid is gduih3Nyww== 登录二维码已经下载到本地 [ /tmp/weixin_qrcode_bYwp.jpg ] 1--$show_tip is 1 2--$api is https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=gduih3Nyww==&tip=1&r=-1479440494&_=1479440494 $r is window.code=201;window.userAvatar = 'data:img/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABQODxIPDRQSEBIXFRQYHjIhHhwcHj0sLiQySUBMS0dARkVQWnNiUFVtVkVGZIhlbXd7gYKBTmCNl4x9lnN+gXz/2wBDARUXFx4aHjshITt8U0ZTfHx8fHx8fHx8fHx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P/Z'; 手机微信扫码成功,请在手机微信上点击 [登录] 按钮... 1--$show_tip is 0 2--$api is https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=gduih3Nyww==&tip=0&r=-1479440494&_=1479440494 $r is window.code=200; window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=AQV3nhqeStaayKkSthVOuQXu@qrticket_0&uuid=gduih3Nyww==&lang=zh_CN&scan=1479440653"; 正在进行登录... $api is https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=AQV3nhqeStaayKkSthVOuQXu@qrticket_0&uuid=gduih3Nyww==&lang=zh_CN&scan=1479440653 $1 is AQV3nhqeStaayKkSthVOuQXu@qrticket_0 $2 is gduih3Nyww== $3 is zh_CN $4 is 1479440653 $user is 1479440653