get 请求: 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 &_=1455501911998 参数: _ 1455501911998 appid wx782c26e4c19acffb fun new lang zh_CN redirect_uri https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage perl 实现: 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"; 返回uuid: window.QRLogin.code = 200; window.QRLogin.uuid = "odcptUu2JA=="; perl 获取uuid: if ( $r =~ /window.QRLogin.code = 200; window.QRLogin.uuid = "(.*?)"/g ) { $uuid = $1; print "$uuid is $uuid "; } get: https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login? loginicon=true &uuid=odcptUu2JA== &tip=1 &r=491993519 &_=1455501911999 _ 1455501911999 loginicon true r 491993519 tip 1 uuid odcptUu2JA== 响应内容: window.code=201;window.userAvatar = 'data:img/jpg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QAIRXhpZgAA/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU /9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAhACEAwEiAAIRAQMRAf /EAB0AAAAHAQEBAAAAAAAAAAAAAAADBAUGBwgJAgH/xAA8EAACAQIFAgQEAwcCBgMAAAABAgMEEQAFBhIhBzEIE0FRImFxgRQykQkVI0KhseEWwUNSYmPR8CQzcv /EAB0BAAEFAQEBAQAAAAAAAAAAAAUCAwQGBwgBAAn/xAA0EQABAwIEBAQFBAEFAAAAAAABAAIDBBEFEiExBhNBYSJRgaEHFDJxsZHB4fBCFSMzYtH /2gAMAwEAAhEDEQA/ANTMgMu6PhGNjhQ9Erxi1t45FsEOn4TdvdVgI3F2NgtvXFOdTPF70/6axSxfvFs9zKEA/h8tG8WPvJ+W33OPz8ocLrMSfy6SIvPYfk7D1W3SytjFybBXRt3kWHI74 获取2维码: https://login.weixin.qq.com/qrcode/odcptUu2JA== 响应就是2微码 perl 实现: my $api = "https://login.weixin.qq.com/qrcode/$uuid"; GET: https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login? loginicon=true &uuid=odcptUu2JA==&tip=0 &r=491986618 &_=1455501912000 参数: _ 1455501912000 loginicon true r 491986618 tip 0 uuid odcptUu2JA== 响应: window.code=200; window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage? ticket=AeWPQvkt58OOsMey6KvDGecs@qrticket_0 &uuid=odcptUu2JA== &lang=zh_CN &scan=1455502017"; 获取 /https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=(.*?)&uuid=(.*?)&lang=(.*?)&scan=(.*)/ $ticket $scan 信息 GET: https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage ?ticket=AeWPQvkt58OOsMey6KvDGecs@qrticket_0 &uuid=odcptUu2JA== &lang=zh_CN &scan=1455502017 &fun=new &version=v2 参数: fun new lang zh_CN scan 1455502017 ticket AeWPQvkt58OOsMey6KvDGecs@qrticket_0 uuid odcptUu2JA== version v2 perl 实现: "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"; 响应信息: <error><ret>0</ret><message>OK</message> <skey>@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3</skey> <wxsid>gIxwZLa2t2UI1PKK</wxsid> <wxuin>1284510822</wxuin> <pass_ticket>o%2B%2BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho %2FZM2YUiV9pszaKAka</pass_ticket> <isgrayscale>1</isgrayscale></error> 获取信息: /<error.*<skey>(.*?)</skey><wxsid>(.*?)</wxsid><wxuin>(.*?)</wxuin><pass_ticket>(.*?)</pass_ticket.*/ ) { $Skey = $1; $wxsid = $2; $wxuin = $3; $pass_ticket = $4; POST登录: https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit? r=492001298 &pass_ticket=o%252B%252BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho%252FZM2YUiV9pszaKAka 参数: pass_ticket o%2B%2BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho%2FZM2YUiV9pszaKAka r 492001298 JSON: BaseRequest Object { Uin="1284510822", Sid="gIxwZLa2t2UI1PKK", Skey="@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3", 更多...} DeviceID "e170005867035434" Sid "gIxwZLa2t2UI1PKK" Skey "@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3" Uin "1284510822" 响应信息: { "BaseResponse": { "Ret": 0, "ErrMsg": "" } , "Count": 11, "ContactList": [{ "Uin": 0, "UserName": "filehelper", "NickName": "文件传输助手", "HeadImgUrl": "/cgi-bin/mmwebwx-bin/webwxgeticon?seq=647236593&username=filehelper&skey=@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3" , "ContactFlag": 3, "MemberCount": 0, "MemberList": [], jrhmpt01:/root# grep '@@' t1 | grep UserName "UserName": "@@fc1a24d417aaa62e2235c0c49e0076e261ac33ffdb7ce42ed1b7aab1df5e45b6", --中均杭州 "UserName": "@@2c7bf588af4ed91bb09d1e47bc9fdc90aecff367d5038252c0cbb4837512f373", --龙翔开发 "UserName": "@@538bdb20d541ebdec03ac9a5f623f7058960e8a1cf39063d8ea534248863bab0", --中均-p2g开发 "UserName": "@@e0dd1658aba02dd6cc7d1320a65d946abf516921f83637fe54e7290521fb7bc7", --曾经的 "UserName": "@@f5a78ff117abd869d3546aa86b427b265669334360d26fbcbc723df031eec53b", --Perl语言交流 "UserName": "@@1447bd7bcd21cf2224059a5f05cdb28cae915e909939e40156a22af63730067f", --杭州运动达人吊炸天 "UserName": "@@5594d9ec894462d1ecb494c117d7cbefffe0fb963c62add1efa0ff1f06e52f6b", --万友“御驾俱乐部” 返回7个最近的聊天群: 返回synckey: "SyncKey": { "Count": 4, "List": [{ "Key": 1, "Val": 647243436 } ,{ "Key": 2, "Val": 647244477 } ,{ "Key": 3, "Val": 647244323 } ,{ "Key": 1000, "Val": 1455498480 } ] } GET获取好友信息: https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact? pass_ticket=o%252B%252BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho%252FZM2YUiV9pszaKAka &r=1455501928636&seq=0 &skey=@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3 pass_ticket o%2B%2BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho%2FZM2YUiV9pszaKAka r 1455501928636 seq 0 skey @crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3 perl 实现: "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?lang=zh_CN&pass_ticket=$pass_ticket&seq=0&skey=$skey"; POST 批量获取群或者好友信息: https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact? type=ex &r=1455501928665 &pass_ticket=o%252B%252BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho%252FZM2YUiV9pszaKAka 参数: pass_ticket o%2B%2BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho%2FZM2YUiV9pszaKAka r 1455501928665 type ex POST: BaseResponse Object { Ret=0, ErrMsg=""} Ret 0 ErrMsg "" Count 13 ContactList [Object { Uin=0, UserName="@@3fd3e5c2576f2e4fd2ae52...6e5654c3c836e864bb6e1a3", NickName="高一(4)班", 更多...}, Object { Uin=0, UserName="@@c5eeb4d29e6e29b3b937e8...48fe609affa8361b3899d6d", NickName="信管", 更多...}, Object { Uin=0, UserName="@@affc3f9e95476b672cee2a...a3dbd2ff5cf1b9f7f0b336c", HeadImgUrl="/cgi-bin/mmwebwx-bin/web...ff5cf1b9f7f0b336c&skey=", 更多...}, 10 更多...] 0 Object { Uin=0, UserName="@@3fd3e5c2576f2e4fd2ae52...6e5654c3c836e864bb6e1a3", NickName="高一(4)班", 更多...} 1 Object { Uin=0, UserName="@@c5eeb4d29e6e29b3b937e8...48fe609affa8361b3899d6d", NickName="信管", 更多...} 2 Object { Uin=0, UserName="@@affc3f9e95476b672cee2a...a3dbd2ff5cf1b9f7f0b336c",HeadImgUrl="/cgi-bin/mmwebwx-bin/web...ff5cf1b9f7f0b336c&skey=", 更多...} 3 Object { Uin=0, UserName="@@f3b2a1e0c34e2f6ee10130...ea852b8ef01ffda0f90845b", NickName="草中01届 参加同学会成员", 更多...} 4 Object { Uin=0, UserName="@@5594d9ec894462d1ecb494...c62add1efa0ff1f06e52f6b", NickName="万友“御驾俱乐部”", 更多...} 5 Object { Uin=0, UserName="@@1447bd7bcd21cf2224059a...939e40156a22af63730067f", NickName="杭州运动达人吊炸天", 更多...} 6 Object { Uin=0, UserName="@@f5a78ff117abd869d3546a...0d26fbcbc723df031eec53b", NickName="Perl语言交流", 更多...} 7 Object { Uin=0, UserName="@@e0dd1658aba02dd6cc7d13...83637fe54e7290521fb7bc7", NickName="曾经的", 更多...} 8 Object { Uin=0, UserName="@@538bdb20d541ebdec03ac9...f39063d8ea534248863bab0", NickName="中均-p2g开发", 更多...} 9 Object { Uin=0, UserName="@@2c7bf588af4ed91bb09d1e...5038252c0cbb4837512f373", NickName="龙翔-开发", 更多...} 10 Object { Uin=0, UserName="@@fc1a24d417aaa62e2235c0...b7ce42ed1b7aab1df5e45b6", NickName="中均杭州", 更多...} 11 Object { Uin=0, UserName="@0775fda855788551bbe250c...f8cfc0822798bb54d127f41", NickName="悠悠球", 更多...} 12 Object { Uin=0, UserName="@17c18ef608386145b132bd0b0054e8df", NickName="我们青年", 更多...} synccheck消息: https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck? r=1455501928659 &skey=%40crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3 &sid=gIxwZLa2t2UI1PKK &uin=1284510822 &deviceid=e558196322767022 &synckey=1_647243436%7C2_647244477%7C3_647244323%7C1000_1455498480 &_=1455501912001 之前接口返回的信息: 返回synckey: "SyncKey": { "Count": 4, "List": [{ "Key": 1, "Val": 647243436 } ,{ "Key": 2, "Val": 647244477 } ,{ "Key": 3, "Val": 647244323 } ,{ "Key": 1000, "Val": 1455498480 } ] } window.synccheck={retcode:"0",selector:"2"} 如果 selector不等于0 说明有消息可以接收,同时 &synckey=1_647243436%7C2_647244477%7C3_647244323%7C1000_1455498480 也会更新 POST 接收消息: https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync? sid=gIxwZLa2t2UI1PKK &skey=@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3 &pass_ticket=o%252B%252BIadCvPXn43usbrXpKIHywlcfiZtDYIz1NHOgTeGDHHho%252FZM2YUiV9pszaKAka JSON: BaseRequest Object { Uin=1284510822, Sid="gIxwZLa2t2UI1PKK", Skey="@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3", 更多...} DeviceID "e556867536148005" Sid "gIxwZLa2t2UI1PKK" Skey "@crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3" Uin 1284510822 SyncKey Object { Count=4, List=[4]} Count 4 List [Object { Key=1, Val=647243436}, Object { Key=2, Val=647244477}, Object { Key=3, Val=647244323}, Object { Key=1000, Val=1455498480}] 0 Object { Key=1, Val=647243436} Key 1 Val 647243436 1 Object { Key=2, Val=647244477} Key 2 Val 647244477 2 Object { Key=3, Val=647244323} Key 3 Val 647244323 3 Object { Key=1000, Val=1455498480} Key 1000 Val 1455498480 rr 491984352 返回的信息: "SyncKey": { "Count": 6, "List": [{ "Key": 1, "Val": 647243436 } ,{ "Key": 2, "Val": 647244478 } ,{ "Key": 3, "Val": 647244323 } ,{ "Key": 11, "Val": 647244136 } ,{ "Key": 13, "Val": 647230079 } ,{ "Key": 1000, "Val": 1455499548 } ] } , "SKey": "" } 下次去synccheck的时候需要使用最新的SKey信息: https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455501929217 &skey=%40crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3&sid=gIxwZLa2t2UI1PKK&uin=1284510822 &deviceid=e543010771618021 &synckey=1_647243436%7C2_647244478%7C3_647244323%7C11_647244136%7C13_647230079%7C1000_1455499548 &_=1455501912002 继续webwxsync 获取消息: "SyncKey": { "Count": 7, "List": [{ "Key": 1, "Val": 647243436 } ,{ "Key": 2, "Val": 647244479 } ,{ "Key": 3, "Val": 647244323 } ,{ "Key": 11, "Val": 647244136 } ,{ "Key": 13, "Val": 647230079 } ,{ "Key": 201, "Val": 1455502020 } ,{ "Key": 1000, "Val": 1455499548 } ] } , "SKey": "" } 继续synccheck: https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455501929535&skey=%40crypt_597aeefd_bdc74c48d52021dfc48d48e030038bf3 &sid=gIxwZLa2t2UI1PKK &uin=1284510822&deviceid=e873338445592918 &synckey=1_647243436%7C2_647244479%7C3_647244323%7C11_647244136%7C13_647230079%7C201_1455502020%7C1000_1455499548 &_=1455501912003 "SyncKey": { "Count": 7, "List": [{ "Key": 1, "Val": 647243436 } ,{ "Key": 2, "Val": 647244492 } ,{ "Key": 3, "Val": 647244323 } ,{ "Key": 11, "Val": 647244136 } ,{ "Key": 13, "Val": 647230079 } ,{ "Key": 201, "Val": 1455502724 } ,{ "Key": 1000, "Val": 1455499548 } ] } , "SKey": "" } synckey 1_647243436|2_647244492|3_647244323|11_647244136|13_647230079|201_1455502724|1000_1455499548 synckey 1_647243436|2_647244492|3_647244323|11_647244136|13_647230079|201_1455502724|1000_1455499548 List [Object { Key=1, Val=647243436}, Object { Key=2, Val=647244492}, Object { Key=3, Val=647244323}, 4 更多...] 0 Object { Key=1, Val=647243436} 1 Object { Key=2, Val=647244492} 2 Object { Key=3, Val=647244323} 3 Object { Key=11, Val=647244136} 4 Object { Key=13, Val=647230079} 5 Object { Key=201, Val=1455502724} 6 Object { Key=1000, Val=1455499548} "SyncKey": { "Count": 7, "List": [{ "Key": 1, "Val": 647243436 } ,{ "Key": 2, "Val": 647244493 } ,{ "Key": 3, "Val": 647244323 } ,{ "Key": 11, "Val": 647244136 } ,{ "Key": 13, "Val": 647230079 } ,{ "Key": 201, "Val": 1455502763 } ,{ "Key": 1000, "Val": 1455499548 } ] } , "SKey": "" } synckey 1_647243436|2_647244493|3_647244323|11_647244136|13_647230079|201_1455502763|1000_1455499548 $url is https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455506643&skey=%40crypt_597aeefd_1c4a59656d1b8b73fc5c47148d5e9dd4&sid=MNNfAOeEeHbK2NbV&uin=1284510822&deviceid=e162744016627176&synckey=1_647243436|2_647244579|3_647244568|11_647244136|13_647230079|201_1455506642|1000_1455499548|&_=1455506643 window.synccheck={retcode:"0",selector:"0"}$mss is 0 $url is https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455506670&skey=%40crypt_597aeefd_1c4a59656d1b8b73fc5c47148d5e9dd4&sid=MNNfAOeEeHbK2NbV&uin=1284510822&deviceid=e162744016627176&synckey=1_647243436|2_647244579|3_647244568|11_647244136|13_647230079|201_1455506642|1000_1455499548|&_=1455506670 window.synccheck={retcode:"0",selector:"0"}$mss is 0 $url is https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455506697&skey=%40crypt_597aeefd_1c4a59656d1b8b73fc5c47148d5e9dd4&sid=MNNfAOeEeHbK2NbV&uin=1284510822&deviceid=e162744016627176&synckey=1_647243436|2_647244579|3_647244568|11_647244136|13_647230079|201_1455506642|1000_1455499548|&_=1455506697 window.synccheck={retcode:"0",selector:"0"}$mss is 0 $url is https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455506724&skey=%40crypt_597aeefd_1c4a59656d1b8b73fc5c47148d5e9dd4&sid=MNNfAOeEeHbK2NbV&uin=1284510822&deviceid=e162744016627176&synckey=1_647243436|2_647244579|3_647244568|11_647244136|13_647230079|201_1455506642|1000_1455499548|&_=1455506724 window.synccheck={retcode:"0",selector:"0"}$mss is 0 $url is https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455506751&skey=%40crypt_597aeefd_1c4a59656d1b8b73fc5c47148d5e9dd4&sid=MNNfAOeEeHbK2NbV&uin=1284510822&deviceid=e162744016627176&synckey=1_647243436|2_647244579|3_647244568|11_647244136|13_647230079|201_1455506642|1000_1455499548|&_=1455506751 $url is https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=1455506800&skey=%40crypt_597aeefd_1c4a59656d1b8b73fc5c47148d5e9dd4&sid=MNNfAOeEeHbK2NbV&uin=1284510822&deviceid=e162744016627176&synckey=1_647243436|2_647244583|3_647244568|11_647244136|13_647230079|201_1455506797|1000_1455499548|&_=1455506800