Open source, address in HTTPS://GITHUB.COM/ATUPAL/WEBQQ
And so have time to write a full CLI QQ client.
How to use: Python login_qq.py can
Copy Code code as follows:
Import Urllib2
Import Httplib2
Import re
Import Random
From encryption import QQMD5
Import Cookielib
Import requests
Import Getpass
Import time
Import JSON
Import Urllib
Class WEBQQ:
def __init__ (self, User, pwd):
Self.cookies = Cookielib. Cookiejar ()
Self.opener = Urllib2.build_opener (
Urllib2. HttpHandler (),
Urllib2. Httpshandler (),
Urllib2. Httpcookieprocessor (self.cookies),
)
Urllib2.install_opener (Self.opener)
Self.user = user
Self.pwd = pwd
Self.mycookie = ";"
#self. ClientID = "21485768"
#self. ClientID = "34592990"
Self.clientid = str (random.randint (10000000, 99999999))
def getsafecode (self):
url = ' https://ssl.ptlogin2.qq.com/check?uin= ' + str (self.user) + ' &appid=1003903&js_ver=10017&js_type=0 &login_sig=0ihp3t5ghfoonssle-98x9hy4uaqmpvu*8*odgl5vyerelcb8fk-y3ts6c3*7e8-&u1=http%3a%2f% 2fweb2.qq.com%2floginproxy.html&r=0.8210972726810724 '
req = Urllib2. Request (URL)
#self. MyCookie + = "confirmuin=" + Self.user + ";"
#req. Add_header (' Cookies ', Self.mycookie)
Req = Urllib2.urlopen (req)
#cs = ['%s=%s '% (c.name, c.value) for C in Self.cookies]
#self. MyCookie + = ";". Join (CS)
Verifycode = Re.search (r "' (\d) ', ' (. +) ', ' (. +) '", Req.read ())
Self.check = Verifycode.group (1)
Self.verifycode1 = Verifycode.group (2)
Self.verifycode2 = Verifycode.group (3)
if Self.check = = "1":
url = ' https://ssl.captcha.qq.com/getimage?&uin= ' +str (self.user) + ' &aid=1002101&0.45644426648505 ' + str (Random.randint (10,99))
req = Urllib2. Request (URL)
Req = Urllib2.urlopen (req)
self.fi = Open ("./IMAGE.JGP", "WB")
While 1:
c = Req.read ()
If not C:
Break
Else:self.fi.write (c)
Self.fi.close ()
Self.verifycode1 = Raw_input ("Verifer:")
Print Self.check, Self.verifycode1, Self.verifycode2
def loginget (self):
#cs = ['%s=%s '% (c.name, c.value) for C in Self.cookies]
#self. MyCookie + = ";" "; ". Join (CS)
Login_url = ' https://ssl.ptlogin2.qq.com/login?u= ' +self.user + ' &p= ' + str (QQMD5 (). Md5_2 (Self.pwd, Self.verifycode1, Self.verifycode2)) + ' &verifycode= ' + self.verifycode1 + ' &webqq_type=10&remember_uin=1 &login2qq=1&aid=1003903&u1=http%3a%2f%2fweb.qq.com%2floginproxy.html%3flogin2qq%3d1%26webqq_type% 3d10&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert& action=2-14-32487&mibao_css=m_webqq&t=1&g=1&js_type=0&js_ver=10015&login_sig= 0ihp3t5ghfoonssle-98x9hy4uaqmpvu*8*odgl5vyerelcb8fk-y3ts6c3*7e8-'
req = Urllib2. Request (Login_url)
Req.add_header ("Referer", "https://ui.ptlogin2.qq.com/cgi-bin/login?target=self&style=5&mibao_css=m_ webqq&appid=1003903&enable_qlogin=0&no_verifyimg=1&s_url=http%3a%2f%2fweb.qq.com% 2floginproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20121029001 ")
#req. Add_header ("Cookie", Self.mycookie)
#self. Opener.addheaders.append (("Cookie", Self.mycookie)
Req = Urllib2.urlopen (req)
Print Req.read ()
For cookies in Self.cookies:
Print Cookie.name, ":", Cookie.value
if cookie.name = = ' PTWEBQQ ':
SELF.PTWEBQQ = Cookie.value
Print Urllib2.urlopen (' http://web2.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=0&lv= 3&t=1358252543124 '). Read ()
#cs = ['%s=%s '% (c.name, c.value) for C in Self.cookies]
#self. MyCookie + = ";" "; ". Join (CS)
def loginpost (self):
url = ' http://d.web2.qq.com/channel/login2 '
data = ' R=%7b%22status%22%3a%22online%22%2c%22ptwebqq%22%3a%22 ' + self.ptwebqq + '%22%2c%22passwd_sig%22%3a%22%22%2c %22clientid%22%3a%22 ' +self.clientid+ '%22%2c%22psessionid%22%3anull%7d&clientid= ' +self.clientid+ ' & Psessionid=null '
req = Urllib2. Request (URL, data)
#req. Add_header (' Cookies ', Self.mycookie)
Req.add_header (' Referer ', ' http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2 ')
Req = Urllib2.urlopen (req)
Self.result = Json.load (req)
Print self.result[' result ' [' vfwebqq '], self.result[' result ' [' Psessionid ']
def getgrouplist (self):
url = ' Http://s.web2.qq.com/api/get_group_name_list_mask2 '
data = ' r=%7b%22vfwebqq%22%3a%22 ' +self.result[' result ' [' vfwebqq '] + '%22%7d '
req = Urllib2. Request (URL, data)
Req.add_header (' Referer ', ' http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=1 ')
Req = Urllib2.urlopen (req)
Self.group = Json.load (req)
Pass
def getfriend (self):
url = ' Http://s.web2.qq.com/api/get_user_friends2 '
data = ' r=%7b%22vfwebqq%22%3a%22 ' +self.result[' result ' [' vfwebqq '] + '%22%7d '
req = Urllib2. Request (URL, data)
Req.add_header (' Referer ', ' http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=1 ')
Req = Urllib2.urlopen (req)
Self.friend = Json.load (req)
Print Self.friend
Pass
def getmeg (self):
Print Urllib2.urlopen (' http://web2.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=0&lv= 3&t=1358252543124 '). Read ()
Pass
def poll2 (self):
url = ' Http://d.web2.qq.com/channel/poll2 '
data = ' r=%7b%22clientid%22%3a%22 ' +self.clientid+ '%22%2c%22psessionid%22%3a%22 ' +self.result[' result ' [' Psessionid ']+ '%22%2c%22key%22%3a0%2c%22ids%22%3a%5b%5d%7d&clientid= ' +self.clientid+ ' &psessionid= ' + self.result[' result ' [' Psessionid ']
req = Urllib2. Request (URL, data)
#req. Add_header (' Cookies ', Self.mycookie)
Req.add_header (' Referer ', ' http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=3 ')
result = Json.load (Urllib2.urlopen (req))
Print result
def sendmsg (self, UIn, msg):
url = ' HTTP://D.WEB2.QQ.COM/CHANNEL/SEND_BUDDY_MSG2 '
data = ' r=%7b%22to%22%3a ' +uin+ '%2c%22face%22%3a237%2c%22content ' +urllib.quote (R ' ": [\" ' +msg+r '], \ "\\n" Tip: This user is using shift webqq "\", [\ "font\", {\ "name\": \ "song body \", \ "size\": \ "10\", \ "style\": [0,0,0],\ "color\": \ "000000\"}]] ", "') + ' msg_id%22%3a13190001%2c%22clientid%22%3a%22 ' +self.clientid+ '%22%2c%22psessionid%22%3a%22 ' +self.result[' Result ' ['] psessionid ']+ '%22%7d&clientid= ' +self.clientid+ ' &psessionid= ' +self.result[' result ' [' Psessionid ']
req = Urllib2. Request (URL, data)
#req. Add_header (' Cookies ', Self.mycookie)
Req.add_header (' Referer ', ' http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2 ')
Print Urllib2.urlopen (req). Read ()
Pass
def sendqunmsg (self, UIn, msg):
url = ' HTTP://D.WEB2.QQ.COM/CHANNEL/SEND_QUN_MSG2 '
data = ' r=%7b%22group_uin%22%3a ' +uin+ '%2c%22face%22%3a237%2c%22content ' +urllib.quote (R ' ": [\" ' +msg+r '], \ "\\n" Tip: This user is using shift webqq "\", [\ "font\", {\ "name\": \ "song body \", \ "size\": \ "10\", \ "style\": [0,0,0],\ "color\": \ "000000\"}]] ", "') + ' msg_id%22%3a13190001%2c%22clientid%22%3a%22 ' +self.clientid+ '%22%2c%22psessionid%22%3a%22 ' +self.result[' Result ' ['] psessionid ']+ '%22%7d&clientid= ' +self.clientid+ ' &psessionid= ' +self.result[' result ' [' Psessionid ']
req = Urllib2. Request (URL, data)
Req.add_header (' Referer ', ' http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2 ')
Print Urllib2.urlopen (req). Read ()
Pass
def main ():
user = Raw_input (' QQ: ')
PWD = Getpass.getpass (' Password: ')
QQ = WEBQQ (user, PWD)
Qq.getsafecode ()
Qq.loginget ()
Qq.loginpost ()
Qq.getgrouplist ()
Qq.getfriend ()
While 0:
Time.sleep (0.5)
Qq.poll2 ()
For I in range (100):
print ' to ', qq.friend[' result ' [' Info '][0][' UIn ']
print ' to ', qq.group[' result ' [' gnamelist '][10]
#qq. sendmsg (str (qq.friend[' result ' [' Info '][0][' UIn ']), ' Clientjsfzhiyong ')
ms = '
For _ in Xrange (i):
Ms + = '. '
Qq.sendqunmsg (str (qq.group[' result ' [' gnamelist '][10][' gid ']), MS)
#qq. sendmsg (' 2236071402 ', ' GEISF ')
if __name__ = = "__main__":
Main ()