web 微信一些接口说明

步骤:1 获取uuid


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&_=1453465626377

get参数:
_	1453465626377
appid	wx782c26e4c19acffb
fun	new
lang	zh_CN
redirect_uri	https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage

返回:
window.QRLogin.code = 200; window.QRLogin.uuid = "Qa59OV8VIQ==";

步骤:2 获取2维码,传入uuid

https://login.weixin.qq.com/qrcode/4cNObDuxNw==


3.
tip=1 返回window.code=408;登录二维码已失效,重新获取二维码

tip=0 

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=Qa59OV8VIQ==&tip=1&r=-1766681075&_=1453465626378
get 参数;
_	1453465626378
loginicon	true
r	-1766681075
tip	1
uuid	Qa59OV8VIQ==

https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=Qa59OV8VIQ==&tip=0&r=-1766735228&_=1453465626380

_	1453465626380
loginicon	true
r	-1766735228
tip	0
uuid	Qa59OV8VIQ==


r是随机产生的 没太大意义

响应信息:
window.code=200;
window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=ARqkZUhYgDfuVx0314feW7aE@qrticket_0&uuid=Qa59OV8VIQ==&lang=zh_CN&scan=1453465660";

从响应信息里获取:

$ticket ticket=ARqkZUhYgDfuVx0314feW7aE@qrticket_0



4.登陆url https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=ARqkZUhYgDfuVx0314feW7aE@qrticket_0&uuid=Qa59OV8VIQ==&lang=zh_CN&scan=1453465660&fun=new&version=v2&lang=zh_CN



fun	new
lang	zh_CN
lang	zh_CN
scan	1453465660
ticket	ARqkZUhYgDfuVx0314feW7aE@qrticket_0
uuid	Qa59OV8VIQ==
version	v2

响应:

0OK@crypt_597aeefd_ce02369345ff76b204cc95197559f030OS0vN26ZvReX17I11284510822aaZXuDcg6yE6bOqFMBQkc9XcnV54VCX1PkiYRkqvytvjsp9ssy6TkmOt4t2
%2BYoVR1


 if ($r =~/\(.*?)\<\/skey\>\(.*?)\<\/wxsid\>\(.*?)\<\/wxuin\>\(.*?)\<\/pass_ticket.*/) 

从响应信息里获取:
$pass_ticket获取 pass_ticket:


5. 获取初始信息

post 参数:
lang	zh_CN
pass_ticket	aaZXuDcg6yE6bOqFMBQkc9XcnV54VCX1PkiYRkqvytvjsp9ssy6TkmOt4t2%2BYoVR
r	-1766680381

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=-1766680381&lang=zh_CN&pass_ticket=aaZXuDcg6yE6bOqFMBQkc9XcnV54VCX1PkiYRkqvytvjsp9ssy6TkmOt4t2%252BYoVR

返回好友和群信息:
一个@打头的是好友 两个@@ 的是群组


返回的json
响应信息:
{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
}
,
"Count": 11,
"ContactList": [{
"Uin": 0,
"UserName": "filehelper",
"NickName": "文件传输助手",

,{
"Uin": 350786855,
"UserName": "@475bb3101c0b2b9287279d81778825e9",
"NickName": "",
"AttrStatus": 0,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": "q75"
}
,{
"Uin": 165739,
"UserName": "@35d6d71ec6733b7d334027a1a7d5421d",
"NickName": "",
"AttrStatus": 0,
"PYInitial": "",
"PYQuanPin": "",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"MemberStatus": 0,
"DisplayName": "",
"KeyWord": "hcs"
}

可以看到从https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit ,已经没有任何NickName的信息了


对应于:
0OK@crypt_597aeefd_bc0a3d5f638c31ec286cb32b42b77a91VnHvwmxpAsRNpheK1284510822j7b2VdaVETGS3S2hEfR6ZSYx5xIssTZqFOLCTdomA
%2BPqhR8xwYGRl%2FsOAT%2BVRaiU1

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=-1771919172&lang=zh_CN&pass_ticket=j7b2VdaVETGS3S2hEfR6ZSYx5xIssTZqFOLCTdomA%252BPqhR8xwYGRl%252FsOAT%252BVRaiU

lang	
zh_CN
pass_ticket	
j7b2VdaVETGS3S2hEfR6ZSYx5xIssTZqFOLCTdomA%2BPqhR8xwYGRl%2FsOAT%2BVRaiU
r	
-1771919172

JSON:
	
BaseRequest
	Object { Uin="1284510822",  Sid="VnHvwmxpAsRNpheK",  Skey="@crypt_597aeefd_bc0a3d5f638c31ec286cb32b42b77a91",  更多...}
	
DeviceID	"e285907588157171"
	
Sid             "VnHvwmxpAsRNpheK"
	
Skey            "@crypt_597aeefd_bc0a3d5f638c31ec286cb32b42b77a91"
	
Uin              "1284510822"





  BaseRequest =>  {
            Uin         =>  $self->wxuin,
            Sid         =>  $self->wxsid,
            Skey        =>  $self->skey,
            DeviceID    =>  $self->deviceid,
        }



my $res = $ua->post($login_url,{
                          'r'=>"-$now",
                          'lang'=>'zh_CN',
                          'pass_ticket'=>"$pass_ticket"
                                      }, BaseRequest =>  {
            Uin         =>  $self->wxuin,
            Sid         =>  $self->wxsid,
            Skey        =>  $self->skey,
            DeviceID    =>  $self->deviceid,
        });


这里deviceid是计算出来的 不是服务端返回的 

0OK@crypt_597aeefd_85805448c197d4bba1bcbb225626c34a3ZgR+ZS1WztjyupN1284510822K0vjTPEwcSRU73VKC659GOWxJJjFRCtD2IwUcJysY%2FxWEr6RIt7IEVmBSdxu1KvU1$Skey is @crypt_597aeefd_85805448c197d4bba1bcbb225626c34a
$wxsid is 3ZgR+ZS1WztjyupN
$wxuin is 1284510822
$pass_ticket is K0vjTPEwcSRU73VKC659GOWxJJjFRCtD2IwUcJysY%2FxWEr6RIt7IEVmBSdxu1KvU

     '_request' => bless( {
                                        '_content' => 'pass_ticket=K0vjTPEwcSRU73VKC659GOWxJJjFRCtD2IwUcJysY%252FxWEr6RIt7IEVmBSdxu1KvU&lang=zh_CN&r=-1453472610',
                                        '_uri' => bless( do{\(my $o = 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit')}, 'URI::https' ),
                                        '_headers' => bless( {
                                                               'user-agent' => 'Mozilla/8.0',
                                                               'content-type' => 'application/x-www-form-urlencoded',
                                                               'baserequest' => {
                                                                                  'DeviceID' => 'e285907588157171',
                                                                                  'Skey' => '@crypt_597aeefd_85805448c197d4bba1bcbb225626c34a',
                                                                                  'Uin' => '1284510822',
                                                                                  'Sid' => '3ZgR+ZS1WztjyupN'
                                                                                }


	my $post = {
        BaseRequest =>  {
            Uin         =>  $self->wxuin,
            Sid         =>  $self->wxsid,
            Skey        =>  $self->skey,
            DeviceID    =>  $self->deviceid,
        },
    };
use JSON qw(encode_json);
$json_string = encode_json($post);
$ua->post($url, Referer=>"https://wx.qq.com/?&lang=zh_CN","Content-Type"=>"application/json; charset=UTF-8",Content=>$json_string);

sub get_init {
#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."\n";  
 print $res->as_string();#获取的是原始内容,包括响应头,响应正文  
print $res->content();#获取的是响应正文
print "888888888888888888888\n";

#use Data::Dumper;
};




       my $res = $ua->post($login_url,{
                          'r'=>"-$now",
                          'lang'=>'zh_CN',
                          'pass_ticket'=>"$pass_ticket"}
                                      ,
 Referer=>"https://wx.qq.com/?&lang=zh_CN",
"Content-Type"=>"application/json; charset=UTF-8",
Content=>$json_string
        );


	POST https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit
Referer: https://wx.qq.com/?&lang=zh_CN
User-Agent: Mozilla/8.0
Content-Type: application/json; charset=UTF-8
Lang: zh_CN
Pass-Ticket: tr0K58lYox2T8ay49KEOBF9wdGrvf2DtqZkVxJ50ws3IT%2FRQtORRuHIt%2F59F3hke
R: -1453477692

{"BaseRequest":{"DeviceID":"e211614876626179","Skey":"@crypt_597aeefd_eb05b28c345325f6ad89372af9077676","Uin":"1284510822","Sid":"n91V1KkG4LJQu0qm"}}

post 和 get都一样啊 没什么区别
my $ua = LWP::UserAgent->new; 你不要没发一次http就新建一个$ua 这样的话 cookie没办法继承

你全局 my $ua = LWP::UserAgent->new;  只使用一个ua就行了 这样cookie在能够在多个请求直接自动保持


6.


获取好友接口:

get 参数;
lang	zh_CN
pass_ticket	iJ4GrCog8KIWlhibOCeICcVJYlPGfCdF2ZjnLBy88Y5oG93679Pku9Wu2RNADbRU
r	1453525907497
seq	0
skey	@crypt_597aeefd_d84b707081d9db61e639b8aec84c1903

https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?lang=zh_CN&pass_ticket=iJ4GrCog8KIWlhibOCeICcVJYlPGfCdF2ZjnLBy88Y5oG93679Pku9Wu2RNADbRU&r=1453525907497&seq=0&skey=@crypt_597aeefd_d84b707081d9db61e639b8aec84c1903

$url="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?lang=zh_CN&pass_ticket=$pass_ticket&seq=0&skey=$skey";


{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
}
,
"MemberCount": 243,
"MemberList": [{
"Uin": 0,
"UserName": "@4ec3bd7d3c2753cbb49ee81da30ceb5db53771670613e888339bfca533df0df9",
"NickName": "知道",
"HeadImgUrl": "/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@4ec3bd7d3c2753cbb49ee81da30ceb5db53771670613e888339bfca533df0df9
&skey=@crypt_597aeefd_cf3d5a55576baf6625a9bde69acfa6db",
"ContactFlag": 3,
"MemberCount": 0,
"MemberList": [],
"RemarkName": "",
"HideInputBarFlag": 0,
"Sex": 2,
"Signature": "",
"VerifyFlag": 0,
"OwnerUin": 0,
"PYInitial": "ZD",
"PYQuanPin": "zhidao",
"RemarkPYInitial": "",
"RemarkPYQuanPin": "",
"StarFriend": 0,
"AppAccountFlag": 0,
"Statues": 0,
"AttrStatus": 185,
"Province": "浙江",
"City": "杭州",
"Alias": "",
"SnsFlag": 16,
"UniFriend": 0,
"DisplayName": "",
"ChatRoomId": 0,
"KeyWord": "",
"EncryChatRoomId": ""
}

"@4ec3bd7d3c2753cbb49ee81da30ceb5db53771670613e888339bfca533df0df9"
一个@打头的是好友 两个@@ 的是群组

7.获取群信息接口:
https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact?type=ex&r=1453686440414&lang=zh_CN&pass_ticket=a4M6SjxBvR8c9I66LB3b1MHSKujJAMueHMdhJgTxoStJK4akNvbJ5eGdRFkHxDNc


post   参数:
pass_ticket	4UD2MBQwgZDQJlLJgn3lWG8gwCchs8yIXiGz7Tj7Bf7HQ7R3og0p0cEF4VjcMP3o
r	1453685536235
type	ex


json:


	
参数头信息Post响应JSON缓存Cookies
按 key 排序
		
BaseResponse  Object { Ret=0,  ErrMsg=""}
Ret                    0
ErrMsg                 ""
Count                  50
ContactList
	
	[Object { Uin=0,  UserName="@@ca1db30d7ba3d211185cc2...b10d9bee127cda5c9eb4f0f",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...ee127cda5c9eb4f0f&skey=",  更多...}, Object { Uin=0,  UserName="@@870445cfcfb4399d19aa9d...6e3d1136b5923de0870aa27",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...36b5923de0870aa27&skey=",  更多...}, Object { Uin=0,  UserName="@@1c19f60149606454aef85f...cad7001398105d202a7902f",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...1398105d202a7902f&skey=",  更多...}, 47 更多...]
0
	
	Object { Uin=0,  UserName="@@ca1db30d7ba3d211185cc2...b10d9bee127cda5c9eb4f0f",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...ee127cda5c9eb4f0f&skey=",  更多...}
1
	
	Object { Uin=0,  UserName="@@870445cfcfb4399d19aa9d...6e3d1136b5923de0870aa27",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...36b5923de0870aa27&skey=",  更多...}
2
	
	Object { Uin=0,  UserName="@@1c19f60149606454aef85f...cad7001398105d202a7902f",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...1398105d202a7902f&skey=",  更多...}
3
	
	Object { Uin=0,  UserName="@@7577e849f1787abb3ddbd7...44f9924e0616c213bd47b52",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...4e0616c213bd47b52&skey=",  更多...}
4
	
	Object { Uin=0,  UserName="@@953ecc8fa1d51da48442ab...241d82bece9e8ee807340e4",  NickName="Oracle小筑",  更多...}
5
	
	Object { Uin=0,  UserName="@@c4049f3a5ee6564b5eef98...32b1910a280d5c9d1b6e463",  NickName="高三(4)班",  更多...}
6
	
	Object { Uin=0,  UserName="@@547948cb25c7849450fa7a...af70400b693841797302447",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...0b693841797302447&skey=",  更多...}
7
	
	Object { Uin=0,  UserName="@@a033dd42bedf3c048f9e8f...f672697f5160701b17b720f",  NickName="Perl",  更多...}
8
	
	Object { Uin=0,  UserName="@@e47a7d401fbb9508d4439a...f9000c81d3b96b9af908fb3",  NickName="中均一周年庆",  更多...}
9
	
	Object { Uin=0,  UserName="@@97ddfde491ab61a3a566b6...0f70de6a5699600bea44f0f",  NickName="客服IT问题反馈",  更多...}
10
	
	Object { Uin=0,  UserName="@@05b771799b4f88ee275e97...c48dfa7754e56ea8fc6a6a3",  NickName="技术改革工作办公室",  更多...}
11
	
	Object { Uin=0,  UserName="@@40d1cbea7ec715cd532ac6...c04114121f44c38f361d5e5",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...121f44c38f361d5e5&skey=",  更多...}
12
	
	Object { Uin=0,  UserName="@@42e742d1905dc127c2c90f...d3f260c4194f60c8c934728",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...c4194f60c8c934728&skey=",  更多...}
13
	
	Object { Uin=0,  UserName="@@796ab64b89195416712440...4039783fca21acb50eb8c4d",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...3fca21acb50eb8c4d&skey=",  更多...}
14
	
	Object { Uin=0,  UserName="@@0a30ed2d31b19e5efae1c8...347266cc8b5c8b1c6aa3824",  NickName="浙大食堂吃饭群",  更多...}
15
	
	Object { Uin=0,  UserName="@@0e02ba2d78a110b8d3e579...ec3a761836c20f97bd24d9a",  HeadImgUrl="/cgi-bin/mmwebwx-bin/web...1836c20f97bd24d9a&skey=",  更多...}
16
	
	Object { Uin=0,  UserName="@@e758444b4552205c750ebb...ed861dc83829e379a2b7cc6",  NickName="龙翔-开发",  更多...}
17
	
	Object { Uin=0,  UserName="@@c27bcd9d3f7abc1daf0922...cae4241794a4f7afcbbc6cb",  NickName="中均营销IT问题反馈",  更多...}
18
	
	Object { Uin=0,  UserName="@@9c44f6658975106772f1a5...8bef43a7fa2559a133299c9",  NickName="中均运维",  更多...}
	
	
	
	sub _get_chatroom{
    my $self  = shift;
    my @chatroom_id = @_;
    my $post = {
        BaseRequest =>  {
            Uin         =>  $self->wxuin,
            DeviceID    =>  $self->deviceid,
            Sid         =>  $self->wxsid,
            Skey        =>  $self->skey,
        },
        Count       =>  @chatroom_id+0,
        List        =>  [map { {UserName=>$_,ChatRoomId=>""} } @chatroom_id ],
    };

	这个@chatroom_id  怎么拿到的?

就是你之前 webwxinit webwxgetcontact 这些接口返回的
好友列表里的

这里的@chatrrom_id 是UserName 数组

Username 就是好友的id 或者 群组的id

webwxinit 接口返回群信息和好友信息 ,好友信息全,群成员信息不全,部分群信息

{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
}
,
"Count": 11,
"ContactList": [{
"Uin": 0,
"UserName": "filehelper",
"NickName": "文件传输助手",
"HeadImgUrl": "/cgi-bin/mmwebwx-bin/webwxgeticon?seq=638861246&username=filehelper&skey=@crypt_597aeefd_0b7d529e6a34c4119a682b00981b721d"
,


init 接口返回全部群ID:
"ChatSet": "filehelper,@@e348759078474d582072759ebb4fbbc4a007699c01e59325602fb80846a9b368,@70ceba75137c3b4ec4ab2a856331a1b7,weixin,@@7e8f3573afa6366575359f4db885d07cc55d45dc48a977a09d1c680656176cc3,@21bc87416cbf1531dbdbb7a0bda2fd0a37f7784f4de6a9fc8981dd87198d5343,@@742f906c9926486a4a34a13f1625239b0dfe073801fa08f198330b6a892c42d1,@@97ed98b4bc8f8d44efbcea4ddedfa799e7fff2eb716c2ef838232b73f9cba316,@aa49d31f8c7225ad4c72d954f8ddd4cb,@65e0955491336752ebd7ea9cd200a063,@@f07c66eca4ccd07c28ea7a879941c731bba9b727953d113183a0d47adb5dfe4b,@@693ca144e087271af4bc5041222a6f60566c795f572b9fc511c058f1f62e0342,@54c6c42123cc5d63bba273a0359bed6a,@d1b437d47db62a60853b7132238a4f7c283e5e1334cc1a17d16b8e596ac4ac20,@@cc100ea82521c904a72301fdbeda4fc8b83c6111a34563a7ca3cb75a4a7b7de7,@@85b5788b13925552572b8457e1e004ed0832e462e383f1a3770ee681f89bb9f6,@@d5a86d631aafdd7d70d8a18ecfffd432c71474831ce31dfb8f891c7df4bb1041,@@18fd96f7d7f93975df36c1eeb6418cbc777148eb302455674d66ec2f851f13aa,@@d59cfe358679f0c2147d3a06ae256267df3e72ea672867a125e2710c33165702,",
"SKey": "@crypt_597aeefd_e3bb36d8ac68ba0f1cc6057c29923826",



webwxgetcontact  返回好友信息,没有群信息
{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
}
,
"MemberCount": 243,



webwxbatchgetcontact 返回全部群信息

{
"BaseResponse": {
"Ret": 0,
"ErrMsg": ""
}
,
"Count": 13,
"ContactList": [{


jrhmpt01:/root/wx# cat a3 | grep '@@' | grep UserName
"UserName": "@@d59cfe358679f0c2147d3a06ae256267df3e72ea672867a125e2710c33165702",
"UserName": "@@18fd96f7d7f93975df36c1eeb6418cbc777148eb302455674d66ec2f851f13aa",
"UserName": "@@d5a86d631aafdd7d70d8a18ecfffd432c71474831ce31dfb8f891c7df4bb1041",
"UserName": "@@85b5788b13925552572b8457e1e004ed0832e462e383f1a3770ee681f89bb9f6",
"UserName": "@@cc100ea82521c904a72301fdbeda4fc8b83c6111a34563a7ca3cb75a4a7b7de7",
"UserName": "@@693ca144e087271af4bc5041222a6f60566c795f572b9fc511c058f1f62e0342",
"UserName": "@@f07c66eca4ccd07c28ea7a879941c731bba9b727953d113183a0d47adb5dfe4b",
"UserName": "@@97ed98b4bc8f8d44efbcea4ddedfa799e7fff2eb716c2ef838232b73f9cba316",
"UserName": "@@742f906c9926486a4a34a13f1625239b0dfe073801fa08f198330b6a892c42d1",
"UserName": "@@7e8f3573afa6366575359f4db885d07cc55d45dc48a977a09d1c680656176cc3",
"UserName": "@@e348759078474d582072759ebb4fbbc4a007699c01e59325602fb80846a9b368",
jrhmpt01:/root/wx# cat a3 | grep '@@' | grep UserName | wc -l
11



接收消息:

https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck

vim _synccheck.pm 


请求synccheck 有消息就会返回 然后执行sync去处理消息 然后继续请求synccheck


没有频度控制 一直请求就行了



 
  
 
  
 
 

你可能感兴趣的:(perl,WeixinClient)