def _sendmsg(self,to,msg): url = 'http://web2-b.qq.com/channel/send_msg' send = {} send['to']=to send['face']=0 content = [] content.append(msg) msg_config = [] msg_config.append('font') msg_config.append({"name":"\xe5\xae\x8b\xe4\xbd\x93", "size":"10", "style":[0,0,0], "color":"000000"}) content.append(msg_config) send['content']=json.dumps(content) send['msg_id'] = get_msgid(self.msg_count) send['clientid'] = self.clientid send['psessionid'] = self.psessionid r = urllib.quote(json.dumps(send)) body = r'r=%s' % r Headers['Cookie']=getcookiestr(self.cookies) resp,content = Post(url,body=body,headers=Headers) content_dict= json.loads(content) if resp['status'] == '200' and content_dict['retcode'] == 0: logging.info('send msg to %d successs!',to) return True else: logging.error('send msg to %d failure!',to) logging.error('resp:%s content:%s',str(resp),str(content)) return False
def _add_need_verify(self,toid,message): url = 'http://web2-b.qq.com/api/add_need_verify' Headers['Cookie']=getcookiestr(self.cookies) params = { 'tuin':toid, 'myallow':1, 'groupid':0, 'msg':message, 'vfwebqq':self.vfwebqq, } body = 'r='+json.dumps(params) resp, content = Post(url,body =body,headers=Headers)
def _channel_poll2(self): url = 'http://d.web2.qq.com/channel/poll2' params ={ 'clientid':self.clientid, 'psessionid':self.psessionid, 't':int(time.time()), 'vfwebqq':self.vfwebqq } Headers['Cookie'] = getcookiestr(self.cookies) resp,content = Get(url,params=params,headers=Headers) self.cookies=Cookie(resp.get('set-cookie','')) print resp print content
def _get_online_buddies(self): url = 'http://web2-b.qq.com/channel/get_online_buddies' params = { 'clientid':self.clientid, 'psessionid':self.psessionid, 't':int(time.time()) } Headers['Cookie']=getcookiestr(self.cookies) resp,content = Get(url,params=params,headers=Headers) content_dict= json.loads(content) if resp['status'] == '200' and content_dict['retcode'] == 0: return content_dict['result'] else: logging.error('resp:%s,content:%s',str(resp),content) return None
def _get_user_friends(self): url = 'http://web2-b.qq.com/api/get_user_friends' params={ 'h':'hello', 'vfwebqq':self.vfwebqq } body = 'r='+json.dumps(params) Headers['Cookie']=getcookiestr(self.cookies) resp,content = Post(url,body=body,headers=Headers) content_dict= json.loads(content) if resp['status'] == '200' and content_dict['retcode'] == 0: return content_dict['result'] else: logging.error('resp:%s,content:%s',str(resp),content) return None
def _channel_login(self): url = 'http://web2-b.qq.com/channel/login' self.cookies['notifyNewApp'] = 1 self.cookies['pgv_pvid'] = 1935756508 self.cookies['pgv_flv'] = '10.1 r103' self.cookies['pgv_info'] = 'pgvReferrer=&ssid=s471232060' Headers['Cookie']=getcookiestr(self.cookies) Headers['Content-Type']='application/x-www-form-urlencoded' Headers['Proxy-Connection'] = 'keep-alive' Headers['Referer'] = 'http://web2-b.qq.com/proxy.html?v=20101025002' Headers['Origin'] = 'http://web2-b.qq.com' Headers['Accept-Encoding'] = 'gzip,deflate,sdch' body =r"r=%7B%22status%22%3A%22%22%2C%22ptwebqq%22%3A%22"+self.cookies['ptwebqq'].value+r"%22%2C%22passwd_sig%22%3A%22%22%2C%22clientid%22%3A%22"+self.clientid+r"%22%7D" resp,content = Post(url,body=body,headers=Headers) #self.cookies = Cookie(resp.get('set-cookie','')) login_data = json.loads(content) if login_data['retcode'] == 0: self.psessionid = login_data['result']['psessionid'] self.vfwebqq = login_data['result']['vfwebqq'] return True else: return False