perl weixin webwxinit 接口

<pre name="code" class="python">https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?
r=1921102163
&pass_ticket=ovyLkGVM8W6lUAbZpt%252BhgJdeomQYRPOu8yf6FkW%252B7GE5Meq4S3qn4Qz%252FQyD64vsD

参数;
pass_ticket	ovyLkGVM8W6lUAbZpt%2BhgJdeomQYRPOu8yf6FkW%2B7GE5Meq4S3qn4Qz%2FQyD64vsD
r	        1921102163

JSON:

BaseRequest Object { Uin="1284510822",  Sid="zJpU4C7YK9KeMmQ0",  Skey="@crypt_597aeefd_95352fe37541ae84f1c15b4d8a86e710",  更多...}
	
DeviceID	"e290361266006370"
	
Sid        "zJpU4C7YK9KeMmQ0"
	
Skey       "@crypt_597aeefd_95352fe37541ae84f1c15b4d8a86e710"
	
Uin        "1284510822"

返回:

webwxinit是显示你微信首屏上的近期联系人 包括最近聊天的好友和群组

可能不会显示群成员信息

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

"UserName": "filehelper",
"NickName": "文件传输助手

"UserName": "@@afabc51b74c3eb4c9941a6da70f20b072799b09a06e16eb8f193025b75d2425b",
"NickName": "云霁大会现场群",

"UserName": "@@b3a5e222726a2eb2329065f83a2a01bb9d7e553b5695c155597147653d477c00",
"NickName": "中均-p2g开发",

"UserName": "newsapp",
"NickName": "腾讯新闻"


"Uin": 0,
"UserName": "weixin",
"NickName": "微信团队",

"UserName": "@b506a484e1b82246124c283a7daff85d",
"NickName": "积分联盟",

"UserName": "@@f786bc5ff6f8501e745f0b82b480ac22a698349cd5d4ce645af81ce1afc1f7c2",
"NickName": "技术改革工作办公室",

"UserName": "@294b2f5030f2c47712f1701f7cd43158", ###微信好友
"NickName": "天使的风衣",


返回:
"SyncKey": {
"Count": 4,
"List": [{
"Key": 1,
"Val": 646985545
}
,{
"Key": 2,
"Val": 646985575
}
,{
"Key": 3,
"Val": 646985306
}
,{
"Key": 1000,
"Val": 1454062118
}
]
}
,


Perl程序:

@chatroom_id=();
#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 "-------------init-----------------
";
#print $res->status_line."
";  
#print $res->as_string();#获取的是原始内容,包括响应头,响应正文  
#print $res->content();#获取的是响应正文
$d=$res->content();




返回的json 需要转换为数组:

{
"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_95352fe37541ae84f1c15b4d8a86e710"
,
"ContactFlag": 3
]}}


$d=encode_utf8($d);
$d = decode_json($d);

use Data::Dumper;

  my $var= Dumper($d);
  #print $var;

foreach $m (@{$d->{ContactList}}){
#print "----------------
";
#print $m->{UserName};
if ($m->{UserName} =~/@@/){
push (@chatroom_id ,$m->{UserName});
};
print "
";

};



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