模拟微信登录

use  LWP::UserAgent;  
use File::Temp qw/tempfile/;
use AE;
my $api = 'https://login.weixin.qq.com/jslogin';
my $now= time();
  my @query_string = (
        appid           =>  'wx782c26e4c19acffb',
        redirect_uri    =>  'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage',
        fun             =>  'new',
        lang            =>  'zh_CN',
        _               =>  $now,
    );

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent("Mozilla/8.0");
$host = "https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=$now";
my $response = $ua->get($host);
  $ua->default_headers;
if ($response->is_success) {
 print $response->decoded_content;  # or whatever
$r=$response->decoded_content;
print "
";
}
else {
 die $response->status_line;
};
print "$r is $r
";
if ( $r =~ /window.QRLogin.code = 200; window.QRLogin.uuid = "(.*?)"/g){
$uuid=$1;
print "$uuid is $uuid
";
};


my $api="https://login.weixin.qq.com/qrcode/$uuid";
my $response = $ua->get($api);
  $ua->default_headers;
if ($response->is_success) {
 $r= $response->decoded_content;  # or whatever
$r=$response->decoded_content;
print "
";
}
else {
 die $response->status_line;
};


   my ($fh, $filename) = tempfile("weixin_qrcode_XXXX",SUFFIX =>".jpg",DIR => '/tmp');
    binmode $fh;
    print $fh $r;
    close $fh;
   print  "登录二维码已经下载到本地 [ $filename ] 
";

#https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=YaZ1MmzJ3Q==&tip=0&r=-1661116850&_=1453360034431



       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=-1661116850&_=$now";
my $response = $ua->get($api);
  $ua->default_headers;
if ($response->is_success) {
$r=$response->decoded_content;
print "222222222222222222222222
";
print "$r is $r
";
print "3333333333333333333333333333333
";
next unless defined $r;
 my %data = $r=~/window.(.+?)=(.+?);/g;

if ($data{code} ==201){
 print "手机微信扫码成功,请在手机微信上点击 [登录] 按钮...
";
         my    $show_tip = 0;
          next;
      }elsif
            ($data{code} == 200){
            print "正在进行登录...
";
            foreach ($r){
        if ($_ =~/window.redirect_uri="(.*?)"/){
       my $api=$1;
       print "$api is $api
";
     my $response = $ua->get($api);
  $ua->default_headers;
       return 1;
         }}}
else {
 die $response->status_line;
};

} }
};
&login();
sleep(5);
sub RUN{
    print "启动全局事件循环...
";
    AE::cv->recv;
}
&RUN();

原文地址:https://www.cnblogs.com/hzcya1995/p/13351073.html