Python3.2 simulates webqq login and python3.2webqq Login

Source: Internet
Author: User

Python3.2 simulates webqq login and python3.2webqq Login

This is an example code for simulating webqq login using python. The Code is as follows:

Import hashlibfrom urllib import request, parsefrom http import cookiejarimport re, random, timeimport threading as thimport json. encoder as json_encodeimport json. decoder as json_decodeclass QQ: "" Login QQ "" _ headers = {'user-agent': 'mozilla/5.0 (Windows NT 6.1; WOW64) appleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.9 Safari/534.30 ', \ 'Referer': 'http: // ui.ptlogin2.qq.com/cgi-bin/login? Export & f_url = loginerroralert & strong_login = 1 & login_state = 10 & t = 20110909003 '\} _ cookiepath = 'C: \ Users \ dingyangfan \ Desktop \ php \ tt.txt '_ qq = None _ pswd = None _ verifycode = None _ clientid = 21628014 _ http = {} _ psessionid = ''_ ptwebqq ='' _ vfwebqq = ''_ skey = ''_ Poll2 = None _ get_msg_tip = None _ rc = 0 _ send_num = 31330000 def _ init _ (self): self. httpproess () self. _ Login () pass def _ preprocess (self, password, verifycode): "" QQ password encryption "return hashlib. md5 (self. _ md5_3 (password ). encode ('utf-8') + (verifycode ). upper ()). encode ('utf-8 ')). hexdigest (). upper () pass def _ md5_3 (self, str): "qqpassword md5_3" return hashlib. md5 (hashlib. md5 (hashlib. m D5 (str ). digest ()). digest ()). hexdigest (). upper () pass def httpproess (self): "initialization simulation process" "self. _ http ['cj '] = cookiejar. mozillaCookieJar (self. _ cookiepath) self. _ http ['opener'] = request. build_opener (request. HTTPCookieProcessor (self. _ http ['cj ']) return self. _ http pass def _ request (self, url, method = 'get', data ={}, savecookie = False ): "request url" if (method ). upper () = 'post': data = parse. urlen Code (data ). encode ('utf-8') self. _ http ['req'] = request. request (url, data, self. _ headers) else: self. _ http ['req'] = request. request (url = url, headers = self. _ headers) fp = self. _ http ['opener']. open (self. _ http ['req']) try: str = fp. read (). decode ('utf-8') encoding t UnicodeDecodeError: str = fp. read () if savecookie = True: self. _ http ['cj ']. save (ignore_discard = True, ignore_expires = True) fp. close () return Str pass def _ getcookies (self, name): fp = open (self. _ cookiepath) fp. seek (130) for read in fp. readlines (): str = read. split (name) if len (str) = 2: fp. close () return str [1]. strip () fp. close () return None pass def _ getverifycode (self): "@ url: http://ptlogin2.qq.com/check? Uin = 644826377 & appid = 1003903 & r = 0.56373973749578 "" urlv = 'HTTP: // ptlogin2.qq.com/check? Uin = '+ (' % s' % self. _ qq) + '& appid = 1003903 & r =' + ('% s' % random. random (). random () str = self. _ request (url = urlv, savecookie = True) str = re. findall (R' \ d | (? <= \ ') [A-zA-Z0-9 \!] {4} ', str) return str pass def _ request_login (self): "@ url: http://ptlogin2.qq.com/login @ params: {u: 644826377 p: 73DA5C1145E0F82247F60B3A17B89E6A verifycode :! S10 webqq_type: 10 remember_uin: 1 login2qq: 1 aid: 1003903 u1: http://webqq.qq.com/loginproxy.html? Login2qq = 1 & webqq_type = 10 h: 1 ptredirect: 0 ptlang: 2052 from_ui: 1 pttype: 1 dumy: fp: loginerroralert action: 1-24-62651 mibao_css: m_webqq} "" urlv = 'HTTP: // ptlogin2.qq.com/login? U = '+ (' % s' % self. _ qq) + '&' + 'P = '+ (' % s' % self. _ pswd) + '& verifycode =' + ('% s' % self. _ verifycode [1]) + '& remember_uin = 1 & aid = 000000' + "percent % 3 Fstrong % 3 Dtrue" +' & h = 1 & ptredirect = 0 & ptlang = 1003903 & from_ui = 1 & pttype = 1 & dumy = & fp = loginerroralert 'str = self. _ request (url = urlv, savecookie = True) if str. find ('logon successful ')! =-1: # execute the second logon self. _ ptwebqq = self. _ getcookies ('ptwebqq') self. _ skey = self. _ getcookies ('skey') self. _ request_post () elif str. find ('incorrect ')! =-1: print ('the account or password you entered is incorrect. Please enter it again. ') Else: print ('login failed') pass def _ request_post (self): ''' http://d.web2.qq.com/channel/login2 r: {"status": "online", "ptwebqq ": "identifier", "passwd_sig": "", "clientid": "21628014", "psessionid": null} clientid: 21628014 psessionid: null ''' self. _ headers. update ({'Referer': 'http: // d.web2.qq.com/proxy.html? V = 20110331002 & callback = 2'}) a = {'status': 'online', 'ptwebqq': self. _ getcookies ('ptwebqq'), 'passwd _ sig ': '', 'clientid': self. _ clientid, 'psessionid': 'null'} array = {'r': json_encode.JSONEncoder (). encode (a), 'clientid': self. _ clientid, 'psessionid': 'null'} url = 'HTTP: // d.web2.qq.com/channel/login2' str = self. _ request (url, 'post', array) str = json_decode.JSONDecoder (). decode (str) self. _ psessionid = str ['Result'] ['psessionid'] self. _ vfwebqq = str ['result'] ['vfwebqq'] self. _ get_friend_info2 () self. _ get_user_friends2 () self. _ get_group_name_list_mask2 () self. _ poll2 _ () self. _ get_msg_tip _ () pass def _ poll2 _ (self): "" I don't know what to do. It is connected once every minute. It is a persistent connection and receives a message @ url: http://d.web2.qq.com/channel/poll2 r: {"clientid": "9467930", "psessionid": "Temperature Principal "," key ": 0," ids ": []} clientid: 9467930 psessionid: Principal D7a8b3bb11a64d3c9565868322 "self. _ headers. update ({'Referer': 'http: // d.web2.qq.com/proxy.html? V = 20110331002 & callback = 2'}) urlv = 'HTTP: // d.web2.qq.com/channel/poll2' a = {'clientid': self. _ clientid, 'psessionid': self. _ psessionid, 'key': 0, 'kids': []} array = {'r': json_encode.JSONEncoder (). encode (a), 'clientid': self. _ clientid, 'psessionid': self. _ psessionid} self. _ poll2 = self. _ request (url = urlv, method = 'post', data = array) str = json_decode.JSONDecoder (). decode (self. _ poll2) print (str) if str ['Refercode'] = 0: if str ['result'] [0] ['Poll _ type'] = 'message': self. _ message (str ['result'] [0] ['value'] ['from _ uin']) elif str ['result'] [0] ['Poll _ type'] = 'group _ message': self. _ group_message (str ['result'] [0] ['value'] ['from _ uin']) pass t1 = th. timer (1, self. _ poll2 _) t1.start () pass def _ get_msg_tip _ (self): "" # I don't know what it is, anyway, always request @ url: http://webqq.qq.com/web2/get_msg_tip? Uin = & tp = 1 & id = 0 & retype = 1 & rc = 64 & lv= 2 & t = 1315746772886 "" self. _ headers. update ({'Referer': 'http: // webqq.qq.com/'}) self. _ rc + = 1 num = 100 + self. _ rc t = '% s' %' % d' % time. time () + '% s' % num urlv = 'HTTP: // webqq.qq.com/web2/get_msg_tip? Uin = & tp = 1 & id = 0 & retype = 1 & rc = '+' % s' % self. _ rc + '& lv = 3 & t =' + t self. _ get_msg_tip = self. _ request (urlv) print (self. _ get_msg_tip) t2 = th. timer (60, self. _ get_msg_tip _) t2.start () pass def _ get_friend_info2 (self): ''' @ url: http://s.web2.qq.com/api/get_friend_info2? Tuin = self. _ qq & verifysession = & code = & vfwebqq = self. _ vfwebqq ''' self. _ headers. update ({'Referer': 'http: // s.web2.qq.com/proxy.html? V = 20110412001 & callback = 1 & id = 2 '}) url = 'HTTP: // s.web2.qq.com/api/get_friend_info2? Tuin = '+ self. _ qq + '& verifysession = & code = & vfwebqq =' + self. _ vfwebqq + '& t = % s' %' % d' % time. time () + '000000' str = self. _ request (url) print (str) pass def _ get_user_friends2 (self): ''' @ url: http://s.web2.qq.com/api/get_user_friends2 ''' self. _ headers. update ({'Referer': 'http: // s.web2.qq.com/proxy.html? V = 20110412001 & callback = 1 & id = 2'}) url = 'HTTP: // s.web2.qq.com/api/get_user_friends2'a = {'H': 'hello', 'vfwebqq': self. _ vfwebqq} array = {'r': json_encode.JSONEncoder (). encode (a)} str = self. _ request (url, 'post', array) print (str) pass def _ get_group_name_list_mask2 (self): ''' @ url: http://s.web2.qq.com/api/get_group_name_list_mask2 ''' self. _ headers. update ({'Referer': 'http: // s.web2.qq.com/proxy.html? V = 20110412001 & callback = 1 & id = 2'}) url = 'HTTP: // s.web2.qq.com/api/get_group_name_list_mask2' a = {'vfwebqq': self. _ vfwebqq} array = {'r': json_encode.JSONEncoder (). encode (a)} str = self. _ request (url, 'post', array) print (str) pass def _ send_message (self, uid, msg): ''' @ url: http://d.web2.qq.com/channel/send_buddy_msg2 r: {"to": 3023379661, "face": 180, "content": "[\" Haha \ ", \" \ n [prompt: This user is using WebQQ: http://webqq.q Q.com/#\ ", [\" font \ ", {\" name \ ": \" \ ", \" size \ ": \" 10 \", \ "style \": [000000, 0], \ "color \": \ "31330001 \"}] "," msg_id ":," clientid ": "76133590", "psessionid": "s"} clientid: 76133590 psessionid: s Referer: http://d.web2.qq.com/proxy.html? V = 20110331002 & callback = 2 {"retcode": 0, "result": "OK"} ''' self. _ send_num + = 1 msg = "[\" "+ msg +" \ ", [\" font \ ", {\" name \ ": \" \", \ "size \": \ "10 \", \ "style \": [0, 0], \ "color \": \ "000000 \"}] "self. _ headers. update ({'Referer': 'http: // d.web2.qq.com/proxy.html? V = 20110331002 & callback = 2'}); url = 'HTTP: // d.web2.qq.com/channel/send_buddy_msg2'a = {'to': uid, 'face': 180, 'content': msg, 'msg _ id': self. _ send_num, 'clientid': self. _ clientid, 'psessionid': self. _ psessionid} array = {'r': json_encode.JSONEncoder (). encode (a), 'clientid': self. _ clientid, 'psessionid': self. _ psessionid} str = self. _ request (url, 'post', array) print (str) pass def _ message (self, uid): ''' {"re Tcode ": 0," result ": [{" poll_type ":" message "," value ": {" msg_id ": 13013," from_uin ": 3023379661," to_uin ": 644826377, "msg_id2": 503935, "msg_type": 9, "reply_ip": 176752345, "time": 1316143960, "content": [["font ", {"size": 13, "color": "000000", "style": [0, 0], "name": "\ u5B8B \ u4F53"}], "\ u4E0D \ u662F \ u5427 \ u3002"]} '''self. _ send_message (uid, 'I am a robot % s' % time. time () pass def _ send_group_message (self, gid, msg): ''' @ ur L: http://d.web2.qq.com/channel/send_qun_msg2 r: {"group_uin": 1132101900, "content": "[\" HAHAHA, test \ ", \" \ n [prompt: This user is using WebQQ: http://webqq.qq.com/#\ ", [\" font \ ", {\" name \ ": \" \ ", \" size \ ": \" 10 \", \ "style \": [000000, 0], \ "color \": \ "31330002 \"}] "," msg_id ":," clientid ": "76133590", "psessionid": "a"} clientid: 76133590 psessionid: a Referer: http://d.web2.qq.com/proxy.html? V = 20110331002 & callback = 2 {"retcode": 0, "result": "OK"} ''' self. _ send_num + = 1 msg = "[\" "+ msg +" \ ", [\" font \ ", {\" name \ ": \" \", \ "size \": \ "10 \", \ "style \": [0, 0], \ "color \": \ "000000 \"}] "self. _ headers. update ({'Referer': 'http: // d.web2.qq.com/proxy.html? V = 20110331002 & callback = 2'}); url = 'HTTP: // d.web2.qq.com/channel/send_qun_msg2'a = {'group _ uin': gid, 'content': msg, 'msg _ id': self. _ send_num, 'clientid': self. _ clientid, 'psessionid': self. _ psessionid} array = {'r': json_encode.JSONEncoder (). encode (a), 'clientid': self. _ clientid, 'psessionid': self. _ psessionid} str = self. _ request (url, 'post', array) print (str) pass def _ group_message (self, gid): ''' {"retcode": 0, "result": [{"poll_type": "group_message", "value": {"msg_id": 8044, "from_uin": 1132101900, "to_uin": 644826377, "msg_id2": 178306, "msg_type": 43, "reply_ip": 2886742214, "group_code": 317106137, "send_uin": 3023379661, "seq": 10654, "time ": 1316143836, "info_seq": 32946855, "content": [["font", {"size": 13, "color": "000000", "style, 0], "name": "\ u5B8B \ u4F53"}], "\ u5DE5"]} '''self. _ send_group_message (gid, 'I am a robot % s' % time. time () pass def _ Login (self): "qq Login" self. _ qq = input ('qq: ') self. _ pswd = input ('qq password: ') self. _ qq = self. _ qq. strip () self. _ pswd = self. _ pswd. strip () self. _ verifycode = self. _ getverifycode () self. _ pswd = self. _ preprocess (self. _ pswd, # password \ '% s' % self. _ verifycode [1] # Verification Code \) self. _ request_login () pass s = QQ ()

The above is all the content of this article. I hope it will help you learn python programming.

Articles you may be interested in:
  • Implementation Code for logging on to QQ mail via python
  • Open the python code of QQ on the computer
  • Script code for Detecting Online status of mobile QQ using python
  • Use webqq protocol to use python to log on to qq and send the source code reference
  • Using python to implement a simple QQ single-user Robot
  • Python collects QQ files uploaded from blogs
  • Using Python to implement QQ game tools
  • Python automatically sends emails to QQ Group members
  • Use Python Tornado framework to implement a simple WebQQ Robot

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.