use LWP::UserAgent;
use URI::Escape;
use Net::Ping;
use JSON qw(encode_json);
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 $now = time();
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);
###获取uuid,用于生成2维码
my $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 ) {
$r = $response->decoded_content;
print $r;
print "\n";
}
else {
die $response->status_line;
}; my $uuid = $1 if ( $r =~ /window\.QRLogin\.code = 200; window\.QRLogin\.uuid = "(.*?)"/g ) ;
print "\$uuid is $uuid\n"; ###根据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; # 验证码内容
print "\n";
}
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 ] \n"; #https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=waJHHDI-og==&tip=1&r=-1969830274&_=1479438579726
# window.code=201;window.userAvatar = 'data:img/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABQODxIPDRQSEBIXFRQYHjIhHhwcHj0sLiQySUBMS0dARkVQWnNiUFVtVkVGZIhlbXd7gYKBT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CywEtrsAGVdhkwAqBFeRsAATsJJWr7oAAR5Zvi39xoXKXLYAdOqztvrZBbUkixABybMnwRuYAAxHQAKgl2ITtJMAIqVygAAP
# /Z';
#如果返回是201 就把$show_tip 设置为0
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\n";
print "2--\$api is $api\n";
sleep (2);
$ua->default_headers;
if ( $response->is_success ) {
$r = $response->decoded_content;
print "\$r is $r\n";
next unless defined $r;
my %data = $r =~ /window\.(.+?)=(.+?);/g;
if ( $data{code} == 201 ) {
print"手机微信扫码成功,请在手机微信上点击 [登录] 按钮...\n";
$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 "正在进行登录...\n";
foreach ($r) {
if ( $_ =~ /window.redirect_uri="(.*?)"/ )
{
$api = $1;
print "\$api is $api\n";
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\n";
print "\$2 is $2\n";
print "\$3 is $3\n";
print "\$4 is $4\n";
$ticket=$1;
$user = $4;
print "\$user is $user\n";
return 1;
}
}
else {
die $response->status_line;
} }
};
&login();
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\n";
print "\$wxsid is $wxsid\n";
print "\$wxuin is $wxuin\n";
print "\$pass_ticket is $pass_ticket\n";
$Skey_x = uri_escape($Skey);
use POSIX;
my $a = "e";
for ( my $b = 0 ; 15 > $b ; $b++ ) {
$a .= POSIX::floor( 10 * rand() );
}
$DeviceID = $a;
} };
my @chatroom_id = (); #my $response= $browser->post("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit", [ "r" => "-$now","lang" => "zh_CN","pass_ticket"=>"$pass_ticket"]);
my $login_url ="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=-$now&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->content(); #获取的是响应正文

perl post json数据的更多相关文章

  1. Perl解析JSON数据精解

    简介:JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - Dece ...

  2. perl post发送json数据

    sub  wx_init {                #$login_url ="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=- ...

  3. 深入了解Struts2返回JSON数据的原理

    首先来看一下JSON官方对于"JSON"的解释: JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析 ...

  4. 浅谈JSON数据解析方法

    JSON数据解析 JSON是什么?? 如何把JSON数据解析出来 如何把一个字典转换为JSON JSON详细介绍 JSON(JavaScript Object Notation) 是一种轻量级的数据交 ...

  5. iOS - JSON 数据解析

     iOS - JSON 数据解析 前言 NS_CLASS_AVAILABLE(10_7, 5_0) @interface NSJSONSerialization : NSObject @availab ...

  6. 【多端应用开发系列1.1.1 —— Android:使用新浪API V2】服务器Json数据处理——Json数据概述

    [前白] 一些基础的东西本系列中就不再详述了,争取尽量写些必不可少的技术要点. 由于本系列把Web Service 构建放到了第二部分,Android项目就采用新浪微博API v2作为服务器端. [原 ...

  7. Android(java)学习笔记208:Android中操作JSON数据(Json和Jsonarray)

    1.Json 和 Xml       JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的 ...

  8. Json数据解析在Unity3d中的应用

    最近做项目过程中因为Json文件名写错了一个字母Unity报错,找错误找到半夜,当时为了验错,写了一个小Demo,正好借此总结一下Json. 1.什么是Json JSON(JavaScript Obj ...

  9. perl 读取json 格式的文件

    使用JSON 模块中的 decode_json 函数,将json文件中的数据解码为perl 中的对象,然后进行处理 代码如下: #!/usr/bin/env perl use JSON; use En ...

随机推荐

  1. html调用applet

    1.相同目录下 <applet code="*.class" width=250 height=50> </applet> 指定applet类名称,appl ...

  2. 浅析ASP.NET的状态保持

    ASP.NET的状态保持:1.viewstate:隐藏域,记录服务器端控件的状态,适用于页面不关闭的情况下多次与服务器交互,页面自己给自己传值:文本框的改变事件.IspostBack也依赖viewst ...

  3. Ext.Net学习笔记06:Ext.Net DirectEvents用方补充

    在ASP.NET控件上面使用DirectEvents 我们在ASP.NET中实现无刷新的页面请求的时候,通常会用到UpdatePanel,现在Ext.Net为我们提供了另外一种渠道:通过DirectE ...

  4. IOS高级开发 runtime(一)

    一. 简介 IOS 开发中灵活使用runtime 会提高我们的程序性能和开发速度.要想使用runtime,首先要引入系统的头文件. <span style="font-size:18p ...

  5. asp:DateDiff 函数

    DateDiff 函数 返回 Variant (Long) 的值,表示两个指定日期间的时间间隔数目. 语法 DateDiff(interval, date1, date2[, firstdayofwe ...

  6. MYSQL连接数据库

    web.config <connectionStrings>   <add name="MysqlDB" connectionString="Data ...

  7. 国庆第三天2014年10月3日10:21:39,Nutz,WebCollector,jsoup

    (1)做得好,做得快,只能选择一样. (2)时间过得很快,你没法在假期的一天里完成更多的计划.假期全部由自己支配,相对长一点的睡眠,新加入的娱乐(视频或者游戏),你不比在工作中更有效率. (3)每天练 ...

  8. hdu 1286 找新朋友 (欧拉函数)

    Problem Description 新年快到了,"猪头帮协会"准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的 ...

  9. android之调用webservice 实现图片上传

    转:http://www.cnblogs.com/top5/archive/2012/02/16/2354517.html public void testUpload(){ try{ String ...

  10. 【转】关于oracle with as用法

    原文链接:关于oracle with as用法 with as语法–针对一个别名with tmp as (select * from tb_name) –针对多个别名with   tmp as (se ...