"
2014/06/28修改
重写了代码, 修改了Hash的计算方式;
"
信息与其发送请求的地址:
好友信息(http://s.web2.qq.com/api/get_user_friends2 )
群信息(http://s.web2.qq.com/api/get_group_name_list_mask2)
讨论组信息(http://s.web2.qq.com/api/get_discus_list)
自己的信息(http://s.web2.qq.com/api/get_self_info2)
最近列表(http://d.web2.qq.com/channel/get_recent_list2)
在线好友(http://d.web2.qq.com/channel/get_online_buddies2?)
其中获取好友信息还有群信息都需要hash的值, 这个值的计算函数在md.js中(以后就不知道会在哪了=。=,,)
下面的CalcHash是根据js文件中的函数写出来的python版本
CalcHash.py
#coding=utf-8
#hash由md.js中的u函数计算得出(传入uin, ptwebqq);
class CalcHash:
def __init__(self):
pass;
@staticmethod
def calcHash(x, K): #id, ptwebqq
x = str(x);
N = K + "password error";
T = "";
V = [];
while(1):
if(len(T) <= len(N)):
T += x;
if(len(T) == len(N)):
break;
else:
T = T[0:len(N)];
break;
for U in range(0, len(T)):
V.append(ord(T[U]) ^ ord(N[U]));
N = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
T = "";
for U in range(0, len(V)):
T += N[V[U] >> 4 & 15];
T += N[V[U] & 15];
return T;
def main():
print(CalcHash.calcHash("1234567", "5037f7bae5f3e19789a97e4e4716f7c52f2e81d81908638cdd6ac88ea2299392"));
if(__name__ == "__main__"):
main();
好像这部分就这个hash值比较难搞定, 其他的都挺容易的, 下面附上获取上面所有信息的python代码
Queryable.py 在我写的那篇模拟登录(WebQQLogin)的文章中有。。
参数dict是模拟登录成后返回的
GetFriendInfo.py
#coding=utf-8
from AbstractGetInfo import *;
from CalcHash import *;
URL_GET_FRIENDINFO = "http://s.web2.qq.com/api/get_user_friends2";
class GetFriendInfo(AbstractGetInfo):
def __init__(self, dict):
AbstractGetInfo.__init__(self, dict);
def doGet(self):
data = {"r":'{"vfwebqq":"' + self.queryInfo("vfwebqq") + '","hash":"' + CalcHash.calcHash(self.queryInfo("uin"), self.queryInfo("ptwebqq")) + '"}'};
request = urllib.request.Request(URL_GET_FRIENDINFO, headers = self.queryInfo("header"));
return request, data;
GetGroupInfo.py
#coding=utf-8
from AbstractGetInfo import *;
from CalcHash import *;
URL_GET_GROUPINFO = "http://s.web2.qq.com/api/get_group_name_list_mask2";
class GetGroupInfo(AbstractGetInfo):
def __init__(self, dict):
AbstractGetInfo.__init__(self, dict);
def doGet(self):
data = {"r":'{"vfwebqq":"' + self.queryInfo("vfwebqq") + '","hash":"' + CalcHash.calcHash(self.queryInfo("uin"), self.queryInfo("ptwebqq")) + '"}'};
request = urllib.request.Request(URL_GET_GROUPINFO, headers = self.queryInfo("header"));
return request, data;
GetSelfInfo.py
#coding=utf-8
import time;
from AbstractGetInfo import *;
URL_GET_SELFINFO = "http://s.web2.qq.com/api/get_self_info2";
class GetSelfInfo(AbstractGetInfo):
def __init__(self, dict):
AbstractGetInfo.__init__(self, dict);
def doGet(self):
data = {"t":str(int(time.time() * 1000))};
request = urllib.request.Request(URL_GET_SELFINFO, headers = self.queryInfo("header"));
return request, data;
GetRecentListInfo.py
#coding=utf-8
import urllib;
import urllib.request;
from AbstractGetInfo import AbstractGetInfo;
URL_GET_RECENTINFO = "http://d.web2.qq.com/channel/get_recent_list2";
class GetRecentListInfo(AbstractGetInfo):
def __init__(self, dict):
AbstractGetInfo.__init__(self, dict);
def doGet(self):
data = {
"r":'{"vfwebqq":"' + self.queryInfo("vfwebqq") + '","clientid":"' + self.queryInfo("clientid") + '","psessionid":"' + self.queryInfo("psessionid") + '"}',
"clientid":self.queryInfo("clientid"),
"psessionid":self.queryInfo("psessionid"),
};
request = urllib.request.Request(URL_GET_RECENTINFO, headers = self.queryInfo("header"));
return request, data;
GetOnlineBuddyInfo.py
#coding=utf-8
import time;
import urllib;
import urllib.request;
from urllib.parse import urlencode;
from AbstractGetInfo import AbstractGetInfo;
URL_GET_ONLINEBUDDYINFO = "http://d.web2.qq.com/channel/get_online_buddies2?";
class GetOnlineBuddyInfo(AbstractGetInfo):
def __init__(self, dict):
AbstractGetInfo.__init__(self, dict);
def doGet(self):
data = {
"clientid":self.queryInfo("clientid"),
"psessionid":self.queryInfo("psessionid"),
"t":str(int(time.time() * 1000)),
};
request = urllib.request.Request(URL_GET_ONLINEBUDDYINFO + urlencode(data), headers = self.queryInfo("header"));
return request, None;
GetDiscussInfo.py
#coding=utf-8
import time;
from AbstractGetInfo import *;
URL_GET_DISCUSSINFO = "http://s.web2.qq.com/api/get_discus_list";
class GetDiscussInfo(AbstractGetInfo):
def __init__(self, dict):
AbstractGetInfo.__init__(self, dict);
def doGet(self):
data = {
"clientid":self.queryInfo("clientid"),
"psessionid":self.queryInfo("psessionid"),
"vfwebqq":self.queryInfo("vfwebqq"),
"t":str(int(time.time() * 1000)),
};
request = urllib.request.Request(URL_GET_DISCUSSINFO, headers = self.queryInfo("header"));
return request, data;
最后一个 AbstractGetInfo.py, 上面所有的模块都继承于这个模块
#coding=utf-8
import json;
import urllib;
import urllib.request;
from urllib.parse import urlencode;
from Queryable import *;
class AbstractGetInfo(Queryable):
def __init__(self, dict):
Queryable.__init__(self, dict);
def doGet(self):
pass;
def get(self):
request, data = self.doGet();
opener = self.queryInfo("opener");
if(data == None):
return json.loads(opener.open(request).read().decode("utf-8"));
else:
return json.loads(opener.open(request, urlencode(data).encode("utf-8")).read().decode("utf-8"));