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. js内置函数的使用

    arguments对象是一个参数对象,可以访问有操作和无操作的参数,能够获得每个参数的内容,参数的个数,例如:arguments[0];获第一个参数,arguments.length;获得参数的个数, ...

  2. PHP中的ob_start() 的使用

    1.在PHP编程中, 我们经常会遇到一些直接产生输出的函数, 如passthru(),readfile(), var_dump() 等. 但有时我们想把这些函数的输出导入到文件中,或者先经过处理再输出 ...

  3. Java NIO 选择器(Selector)的内部实现(poll epoll)

    http://blog.csdn.net/hsuxu/article/details/9876983 之前强调这么多关于linux内核的poll及epoll,无非是想让大家先有个认识: Java NI ...

  4. windows下能读写linux分区的软件 转

    1. ext2ifs 这个工具与explore2fs都是John Newbigin使用Delphi写的,explore2fs Copyright (C) 2000,Ext2IFS v0.3 Copyr ...

  5. 在office 2010中插入Mathtype出现ctrl+v不能复制的问题

    加载项中去掉command for那个即可 详细网址:http://heblue.blog.163.com/blog/static/96325568201375102628405/

  6. ora01033 oracle正在初始化或关闭

    toad连数据库报错: ORA-01033: ORACLE initialization or shutdown in progress 解决方法: 1)开始-运行-cmd 2)命令行中输入SQLPL ...

  7. mysql的分区技术

    一.概述 当 MySQL的总记录数超过了100万后,会出现性能的大幅度下降吗?答案是肯定的,但是,性 能下降>的比率不一而同,要看系统的架构.应用程序.还有>包括索引.服务器硬件等多种因素 ...

  8. cognos 10.2.2 搭建网关做负载均衡

    最近要设计cognos服务器灾备模式,所以想到了cognos10自带的gateway负载均衡模式,搭建起来还是挺简洁的 设计背景: cognos主服务器:231 cognos灾备服务器:238 gat ...

  9. selenium IDE处理各种窗口问题解决方法

    一.处理模态窗口:showModalDialog 由于弹出模态窗口后,就无法定位到当前窗口的元素和模态窗口的元素,需要添加js解决 模态窗口动作类似下面语句: <input id="c ...

  10. javascript document对象 第21节

    <html> <head> <title>DOM对象</title> <style type="text/css"> t ...