webQQ协议——获取信息
2014-03-08 22:58
232 查看
"
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
好像这部分就这个hash值比较难搞定, 其他的都挺容易的, 下面附上获取上面所有信息的python代码
Queryable.py 在我写的那篇模拟登录(WebQQLogin)的文章中有。。
参数dict是模拟登录成后返回的
GetFriendInfo.py
GetGroupInfo.py
GetSelfInfo.py
GetRecentListInfo.py
GetOnlineBuddyInfo.py
GetDiscussInfo.py
最后一个AbstractGetInfo.py, 上面所有的模块都继承于这个模块
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"));
相关文章推荐
- WebQQ协议分析(4)——获取好友信息(1)
- WebQQ协议分析(3)——获取用户信息
- WebQQ协议分析(4)——获取好友信息(1)
- WebQQ协议分析(3)——获取用户信息
- WebQQ协议分析(5)——获取好友信息(2)
- Http协议之获取自定义文件Head信息(1)
- PF_NETLINK 协议 获取IPV6路由信息的一些陷阱
- HTTTP协议头中,添加某一个字段,获取返回数据中头信息的某一个字段。
- VirtualBox的Ubuntu中文件共享问题的解决:未处理的错误消息,获取文件"/media/sf_***"信息出错,协议错误
- WebQQ设计之获取群信息
- 基于ONVIF协议的(IPC)客户端程序开发-8:获取设备基本信息
- webQQ协议——获取好友消息
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第七节 获取本机网间控制报文协议(ICMP)信息
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第七节 获取本机网间控制报文协议(ICMP)信息
- wmi协议支持远程执行cmd命令,并返回获取命令相关信息
- iOS开发 https协议后获取信息失败
- 使用soap 协议登录zimbra,并且获取收件箱信息
- Servlet--获取Http协议请求头信息
- C winpcap 网络抓包 并获取IP TCP 协议的相关信息
- ONVIF协议网络摄像机(IPC)客户端程序开发(8):获取设备基本信息