#转载:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=563093
# -*- coding: cp936 -*-
"""2005-06-15看到微程朋友分析基于http的QQ协议,于是准备写一个QQ程序。但是现在http中的有些包已经不能用了。
我只有继续使用socket的协议了。感谢微程朋友的帮助。关于协议大家可以看他的blog
http://spaces.msn.com/members/mprogramer/Blog/cns!1pKnbff3FpJuGZcrsAlNZmZQ!147.entry
本程序为MIT授权
如果需要转载本程序,请保留版权信息"""
import urllib,httplib,md5,time
class qq:
def __init__(self):
self.pwd=md5.new('你的QQ密码').hexdigest()
self.headers=""
self.qq='你的QQ号码'
self.conn= httplib.HTTPConnection("219.133.51.11:8000")#这里是tqq.tencent.com的ip地址,也可以直接用域名
def Login(self):#登陆
self.headers=("VER=1.0&CMD=Login&SEQ="+\
str(int(time.time()*100)%(10**5))+"&UIN="+\
self.qq+"&PS="+\
self.pwd+\
"&M5=1&LC=9326B87B234E7235")
self.conn.request("POST","", self.headers)
response = self.conn.getresponse()
print response.read()
def Query_Stat(self):#在线好友
self.headers=("VER=1.0&CMD=Query_Stat&SEQ="+\
str(int(time.time()*100)%(10**5))+"&UIN="+\
self.qq+"&TN=50&UN=0")
self.conn.request("POST","", self.headers)
response = self.conn.getresponse()
print response.read()
def List(self):#好友列表
self.headers=("VER=1.0&CMD=List&SEQ="+\
str(int(time.time()*100)%(10**5))+"&UIN="+\
self.qq+"TN=160&UN=0")
self.conn.request("POST","", self.headers)
response = self.conn.getresponse()
print response.read()
def GetInfo(self):#指定QQ号码的详细内容
self.headers=("VER=1.0&CMD=GetInfo&SEQ="+\
str(int(time.time()*100)%(10**5))+"&UIN="+\
self.qq+"&LV=2&UN=40900181")
self.conn.request("POST","", self.headers)
response = self.conn.getresponse()
print response.read()
def AddToList(self):#增加指定QQ号码为好友
self.headers=("VER=1.0&CMD=AddToList&SEQ="+\
str(int(time.time()*100)%(10**5))+"&UIN="+\
self.qq+"&UN=278333853")
self.conn.request("POST","", self.headers)
response = self.conn.getresponse()
print response.read()
test=qq()
test.Login()
"""不知道为什么除了Login和Logout包其他的都有问题。很郁闷"""
#test.Query_Stat()
test.List()
#test.conn.close()
#test.GetInfo()