def jugdeParams(self): # 请求参数替换本地数据 if self.parameter: if self.formData == 0: if '/front/bet/betting.do' in self.url: betParams = eval(self.parameter) betParams['issue'] = str( int(Singleton().getBetIssue()) - 1) return 'json', [betParams] else: json_temp = eval(self.parameter) json_temp = self.judgeManageParams(json_temp) json_temp = self.judgePcParams(json_temp) if 'userId' in json_temp: if Singleton().getUserId(): json_temp['userId'] = Singleton().getUserId() self.parameter = json.dumps(json_temp) return 'data', [] else: list = self.parameter.split('&') files = dict() for listStr in list: files[listStr.split('=')[0]] = (None, listStr.split('=')[1]) self.judgeFormData(files) self.parameter = files return 'data', [] else: return 'data', []
def judgeHeader(self): # 处理请求头 if self.formData == 1: self.header[ 'content-type'] = 'application/x-www-form-urlencoded; charset=UTF-8' else: self.header['content-type'] = 'application/json;charset:utf-8' if Singleton().getSessionId(): self.header['sessionid'] = Singleton().getSessionId()
def showInterfaceDic(self, result, urlName): interfaceDic = dict() resultDic = dict() if result['code'] == 0: resultDic['code'] = result['code'] if 'msg' in result: resultDic['msg'] = result['msg'] else: resultDic['msg'] = '没有返回msg,让后台加' resultDic['requestTime'] = result['requestTime'] resultDic['url'] = result['url'] else: resultDic = result interfaceDic['result'] = resultDic # 额外的参数 listItemDic = dict() listItemDic['name'] = urlName listItemDic['url'] = result['url'] listItemDic['id'] = 0 if 'params' in result: listItemDic['params'] = result['params'] else: listItemDic['params'] = '' listItemDic['isLogin'] = '******' if Singleton().getSessionId() == '': listItemDic['isLogin'] = '******' interfaceDic['listItem'] = listItemDic if result['code'] == 0: interfaceDic['isPass'] = 0 else: interfaceDic['isPass'] = 1 return interfaceDic
def postGetSessionid(cls): # 请求sessionId success, json = requset.post(LoginModule.urlSessionId, None) if success == 0: if json['code'] == 0: Singleton().setSessionId(json['data']['sessionid']) return 0, json else: return json['code'], json else: return 1, json
def requestSessionid(self, session): # 请求sessionid distribute = self.domain + '/passport/distribute_sessionid.do' distribute_r = session.post(distribute, headers=self.header, timeout=self.timeout, verify=False) distribute_response = json.loads(distribute_r.text) sessionid = distribute_response['data']['sessionid'] Singleton().setSessionId(sessionid) self.judgeHeader()
def jugdeResponse(self, response): # 返回值存到本地 if 'login.do' in self.url: if 'userId' in response['data']: Singleton().setUserId(response['data']['userId']) if '/front/bet/betting.do' in self.url: if 'data' in response: Singleton().setOrderId(response['data']) if '/front/interface/draw_info.do' in self.url: if 'currentIssue' in response['data']: Singleton().setBetIssue(response['data']['currentIssue']) if '/passport/manage_login.do' in self.url: if 'data' in response: Singleton().setAccessToken(response['data']) self.judgeManageResponse(response) self.judgePcResponse(response)
def judgeFormData(self, dict): # formData请求参数替换本地数据 if '/passport/login_validate.do' in self.url: if 'accessToken' in dict: dict['accessToken'] = (None, Singleton().getAccessToken()) return dict
#! /usr/bin/python