def login(self): # tool.line() self.out("访问主页 获取 token session") responce = self.http.doGet('http://drrr.com/') re = responce.read() soup =BeautifulSoup.BeautifulSoup(re) # self.out soup.prettify() nameList = soup.findAll('input',{'name':{'token'}}) if(len(nameList) > 0): token = nameList[0]['data-value'] token = tool.encode(token) self.out("抓取成功: ") self.out("token\t " + token) self.out("cookie\t " + tool.toString(self.http.getCookie())) # tool.line() self.out("模拟登录") responce=self.http.doPost('http://drrr.com/', { "name":self.name, "login":"******", "token":token, "direct-join":"", "language":"zh-CN", "icon":"tanaka", }) else: self.out("error! 没能抓取到token")
def executeQuery(self, sql, *args): args = self.turnArray(args) # self.out(sql, args) conn = self.getConn() cursor = conn.cursor() res = cursor.execute(sql, args).fetchall() if (res is not None): for item in res: for key in item: item[key] = tool.encode(item[key]) else: res = [] # self.close() return res
def api(request): response = {} if request.method == 'GET': # Return encoded message (soundprint) if request.GET.get('message'): response['soundprint'] = tool.encode(request.GET['message']) # Return decoded message elif request.GET.get('soundprint'): response['message'] = tool.decode(request.GET['soundprint']) else: response['error'] = 'missing 1 parameter (message or soundprint)' else: response['error'] = 'must send GET request' return HttpResponse(json.dumps(response, indent=4), \ content_type='application/json')
def whileLogin(self): self.ifOk = False if(self.onConnect): self.out("已经在尝试登录") return self.socket.close() self.onConnect = True self.out("尝试登录:") # {CONF_V ARS: "*", ORG_VARS: true, logintype: "mobile", id: "18408249138", password: "******"} # Request URL:http://picc.cochat.cn/SY_ORG_LOGIN.login.do?DESKTOP_OS=Win10&USER_LAST_BROWSER=Win32&USER_LAST_CLIENT=2.5.1&USER_LAST_OS=DESKTOP&USER_LAST_PCNAME=%7B%7D # request Cookie:JSESSIONID=abcb0skaQYCGs6lvy9orw obj = self.http.doJson("http://picc.cochat.cn/SY_ORG_LOGIN.login.do?DESKTOP_OS=Win10&USER_LAST_BROWSER=Win32&USER_LAST_CLIENT=2.5.1&USER_LAST_OS=DESKTOP&USER_LAST_PCNAME=%7B%7D",{ "CONF_VARS":"*", "ORG_VARS":"true", "logintype":"mobile", "id":self.id, "password":self.pwd }) if(obj.get("error","") != ""): self.onConnect = False return self.loginUser = obj token = obj.get("USER_TOKEN", "") self.out("登录结果 token:" + token) urlWithPort = obj.get("CONF_VARS", {}).get("@C_SY_COMM_SOCKET_SERV_V1.0@", "http://cochat.cn:9091") uus = urlWithPort.split(':') port = int(uus[2]) url = uus[1][2:999] #cochat.cn 不需要ws http 只需要ip 域名 self.socketServerUrl = urlWithPort self.socketUrl = url self.socketPort = port self.showUser() self.config = { "transports":['websocket', 'polling'], # websocket优先 "timeout":5 * 1000, # 超时时间 "forceNew": True, "reconnection" : False }; self.out("socket开始") self.socket.connect(url,port) # , params=self.config) self.out("socket连接完成,开始初始化事件") socketMsgTypes = ("connect", "disconnect","error","connect_error","connect_timeout","connecting","reconnecting","message", "event") # socketMsgTypes = ("connect", "disconnect","message", "event") for item in socketMsgTypes: if(hasattr(self, item)): method = getattr(self, item) if(callable(method)): self.socket.on(item, method) else: self.out("变量而非方法" + item + "回调?") else: self.out("属性" + item + "不存在,是否写错了名字?") # self.socket.on("message", self.message) self.out("socket初始化事件完成,开始发送认证") self.data = { "userName":obj.get("USER_CODE", ""), "displayName": tool.encode(obj.get("ORG_VARS", {}).get("@USER_NAME@", "") ), #"ccc",# "odept":obj.get("ORG_VARS", {}).get("@ODEPT_CODE@", ""), "token":obj.get("USER_TOKEN", ""), "uuid":"" + str(uuid.uuid1()), "version":obj.get("USER_CODE", "") + "_LAST_MSG" } self.out(self.data) self.socket.emit('loginv17', self.data, self.onSocketLogin) self.out("已发送认证信息") self.ifOk = True self.onConnect = False return