• 模拟微信登陆和获取好友信息


    use LWP::UserAgent;
    use Net::Ping;
    use Socket;
    use Net::SMTP;
    use LWP;
    use LWP::Simple;
    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use URI::Escape;
    use URI::URL;
    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(5);
    $ua->env_proxy;
    $ua->agent("Mozilla/8.0");
      my $cookie_jar = HTTP::Cookies->new(
          file=>'lwp_cookies.txt',
          autosave=>1,
          ignore_discard=>1);
          $ua->cookie_jar($cookie_jar);
    
    $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 "111111111111111111111111111111111
    ";
    print "$r is $r
    ";
    print "111111111111111111111111111111111
    ";
    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 "22222222222222222222222222222
    ";
    print "222222222222222222222222222
    ";
        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=-$now&_=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=-$now&_=$now";
            my $response = $ua->get($api);
            $ua->default_headers;
            if ( $response->is_success ) {
                $r = $response->decoded_content;
    print "3333333333333333333
    ";
    print "$r is $r
    ";
                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="(.*?)"/ ) {
                             $api = $1;
                            print "$api is $api
    ";
                            my $response = $ua->get($api);
                            $ua->default_headers;
                        }
                    };
    
                      foreach ($r) {
                        if ( $_ =~ /https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=(.*?)&uuid=*/ ) {
                             $ticket = $1;
                            print "$ticket is $ticket
    ";
                        }
                    };
    
    
                          foreach ($api) {
                        if ( $_ =~ /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
    ";
                             $user = $4;
                            print "$user is $user
    ";
                            return 1;
                        }
                    };
    
                }
                else {
                    die $response->status_line;
                }
    
            }
        }
    };
    &login();
    sleep(5);
    
    sub get_ticket {
    my $api="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=$ticket&uuid=$uuid&lang=zh_CN&scan=$user&fun=new&version=v2&lang=zh_CN";
    my $response = $ua->get($api);
    $ua->default_headers;
    
    if ( $response->is_success ) {
        print $response->decoded_content;    # or whatever
    $r=$response->decoded_content;
     if ($r =~/<error.*<skey>(.*?)</skey><wxsid>(.*?)</wxsid><wxuin>(.*?)</wxuin><pass_ticket>(.*?)</pass_ticket.*/) 
    {
      $Skey = $1;
      $wxsid=$2;
      $wxuin=$3;
      $pass_ticket=$4;
     
     print "$Skey is $Skey
    ";
     print "$wxsid is $wxsid
    ";
     print "$wxuin is $wxuin
    ";
     print "$pass_ticket is $pass_ticket
    ";
    use POSIX;
     my $a = "e";
        for(my $b = 0;15 > $b;$b++){
            $a .= POSIX::floor(10 * rand());
        };
    $DeviceID=$a;
    }
    
    }};
    
    sub RUN {
        print "启动全局事件循环...
    ";
        AE::cv->recv;
    };
    
    sub get_friend {
    #my $response= $browser->post("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit", [ "r" => "-$now","lang" => "zh_CN","pass_ticket"=>"$pass_ticket"]); #多加了
    $login_url="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=-1816029078&lang=zh_CN&pass_ticket=$pass_ticket";
    my $post = {
    BaseRequest =>  {
                Uin         =>  $wxuin,
                Sid         =>  $wxsid,
                Skey        =>  $Skey,
                DeviceID    =>  $DeviceID,
            }
    };
    use JSON qw(encode_json);
    $json_string = encode_json($post);
    
    my $req = HTTP::Request->new('POST' => $login_url,[ 'r'=>"-$now", 'lang'=>'zh_CN', 'pass_ticket'=>"$pass_ticket"]); 
    $req->referer("https://wx.qq.com/?&lang=zh_CN");
    $req->content_type('application/json; charset=UTF-8');#post请求,如果有发送参数,必须要有这句  
     $req->content("$json_string");#发送post的参数  
     my $res = $ua->request($req);  
     print $res->status_line."
    ";  
     print $res->as_string();#获取的是原始内容,包括响应头,响应正文  
    print $res->content();#获取的是响应正文
    print "888888888888888888888
    ";
    
    use Data::Dumper;
    my $xx= Dumper($res);      
    print "99999999999999
    ";  
    print $xx;      
    print "
    "
    };
    &get_ticket();
    sleep(5);
    &get_friend();
    sleep(5);
    &RUN();
    

  • 相关阅读:
    JAVA-JSP内置对象之response对象
    JAVA-JSP内置对象之request对象的其他方法
    JAVA-JSP内置对象之request获得封装所有参数值的Map
    JAVA-JSP内置对象之request获得参数的所有参数值(多个值)
    JAVA-JSP内置对象之request获得参数的参数值(一个值)
    Animator根骨骼运动原始实现代码
    Unity胶囊体的碰撞检测实现
    Animation Play/Stop测试
    texconv下载以及使用命令
    unity替换mesh测试
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351070.html
Copyright © 2020-2023  润新知