def _captchaCheck(self, results): data = { 'answer': results, 'login_site': 'E', 'rand': 'sjrand', } result = EasyHttp.send(loginUrls['normal']['captchaCheck'], data=data) Log.v('验证码校验结果:%s' % result.get('result_message')) return result.get('result_code') == '4'
def _uamtk(self): jsonRet = EasyHttp.send(self._urlInfo['uamtk'], data={'appid': 'otn'}) def isSuccess(response): return response[ 'result_code'] == 0 if response and 'result_code' in response else False return isSuccess(jsonRet), \ jsonRet['result_message'] if jsonRet and 'result_message' in jsonRet else 'no result_message', \ jsonRet['newapptk'] if jsonRet and 'newapptk' in jsonRet else 'no newapptk'
def _uamauthclient(self, apptk): jsonRet = EasyHttp.send(self._urlInfo['uamauthclient'], data={'tk': apptk}) # print(jsonRet) def isSuccess(response): return response['result_code'] == 0 if response and 'result_code' in response else False return isSuccess(jsonRet), '%s:%s' % (jsonRet['username'], jsonRet['result_message']) if jsonRet \ else 'uamauthclient failed'
def _captchaCheck(self, results): data = {"answer": results, "login_site": "E", "rand": "sjrand"} jsonRet = EasyHttp.send(loginUrls["normal"]["captchaCheck"], data=data) print("captchaCheck: %s" % jsonRet) def verify(response): return (Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response["result_code"] if "result_code" in response else False) return verify(jsonRet)
def getCaptcha(self): Log.v('正在获取验证码...') urlInfo = loginUrls['normal']['loginCaptchaCode'] response = EasyHttp.send(urlInfo) if response and response['result_code'] != '0': Log.v('获取验证码失败') return None img_base64 = base64.b64decode(response['image']) return img_base64
def _queryOrderWaitTime(self): params = { 'random': '%d' % (time.time() * 1000), 'tourFlag': self.__ticket.ticketInfoForPassengerForm['tour_flag'] or 'dc', '_json_att': '', 'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo['queryOrderWaitTime'], params=params) return jsonRet['status'], jsonRet['messages'], jsonRet['data']['waitTime'], jsonRet['data']['orderId'], \ jsonRet['data']['msg'] if 'msg' in jsonRet['data'] else None
def _resultOrderForDcOrWcQueue(self, orderSequenceNo): formData = { "orderSequence_no": orderSequenceNo, "_json_att": "", "REPEAT_SUBMIT_TOKEN": self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo["resultOrderForQueue"], data=formData) print("resultOrderForDcOrWcQueue", jsonRet) return jsonRet["status"], jsonRet["messages"], jsonRet["data"][ "submitStatus"]
def _resultOrderForDcOrWcQueue(self, orderSequenceNo): formData = { 'orderSequence_no': orderSequenceNo, '_json_att': '', 'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo['resultOrderForQueue'], data=formData) # print('resultOrderForDcOrWcQueue', jsonRet) return jsonRet['status'], jsonRet['messages'], jsonRet['data'][ 'submitStatus']
def _queryMyOrderNoComplete(self): formData = { '_json_att': '', } jsonRet = EasyHttp.send(self._urlInfo['queryMyOrderNoComplete'], data=formData) try: status = jsonRet['status'] messages = jsonRet['messages'] datas = jsonRet['data'] except Exception as e: return False,None,None return status, messages, datas
def _checkRandCodeAnsyn(self, results): formData = { 'randCode': results, 'rand': 'sjrand', } jsonRet = EasyHttp.send(loginUrls['other']['captchaCheck'], data=formData) print('checkRandCodeAnsyn: %s' % jsonRet) def verify(response): return response['status'] and Captcha.__REPONSE_OHTER_CDOE_SUCCESSFUL == response['data']['result'] return verify(jsonRet)
def _getPassengerDTOs(self): if not self._getExtraInfo(): return False, '获取乘客信息失败', None formData = { '_json_att': '', 'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo['getPassengerDTOs'], data=formData) passengersList = jsonRet['data']['normal_passengers'] return jsonRet['status'] if 'status' in jsonRet else False, \ jsonRet['messages'] if jsonRet and 'messages' in jsonRet else '无法获取乘客信息,请先进行添加!', \ self.__getPassengerInfo(passengersList)
def _login_init(self): url_info = copy.deepcopy(self._urlInfo["getDevicesId"]) url_info['url'] = self._urlInfo["getDevicesId"]['url'] + str( int(time.time() * 1000)) devices_id_rsp = EasyHttp.get_custom(url_info) if devices_id_rsp: callback = devices_id_rsp.text.replace("callbackFunction('", '').replace("')", '') try: text = json.loads(callback) devices_id = text.get('dfp') exp = text.get('exp') except Exception as e: print(e) return False, '获取设备指纹失败,请查询12306设备Id获取url是否需要更新' EasyHttp.setCookies(RAIL_DEVICEID=devices_id, RAIL_EXPIRATION=exp) # Log.d('设备Id:%s'%devices_id) return True, '获取设备指纹成功' EasyHttp.send(self._urlInfo['index']) EasyHttp.send(self._urlInfo['loginInit']) return False, '获取设备指纹失败,请查询12306设备Id获取url是否需要更新'
def _checkRandCodeAnsyn(self, results): formData = {"randCode": results, "rand": "sjrand"} jsonRet = EasyHttp.send(loginUrls["other"]["captchaCheck"], data=formData) print("checkRandCodeAnsyn: %s" % jsonRet) def verify(response): return (response["status"] and Captcha.__REPONSE_OHTER_CDOE_SUCCESSFUL == response["data"]["result"]) return verify(jsonRet)
def _uamtk(self): jsonRet = EasyHttp.send(self._urlInfo["uamtk"], data={"appid": "otn"}) def isSuccess(response): return response[ "result_code"] == 0 if "result_code" in response else False return ( isSuccess(jsonRet), jsonRet["result_message"] if "result_message" in jsonRet else "no result_message", jsonRet["newapptk"] if "newapptk" in jsonRet else "no newapptk", )
def query(trainDate, fromStation, toStation, passengerType=PASSENGER_TYPE_ADULT): params = { r'leftTicketDTO.train_date': trainDate, r'leftTicketDTO.from_station': city2code(fromStation), r'leftTicketDTO.to_station': city2code(toStation), r'purpose_codes': passengerType } jsonRet = EasyHttp.send(queryUrls['query'], params=params) try: if jsonRet: return Query.__decode(jsonRet['data']['result'], passengerType) except Exception as e: Log.e(e) return []
def _captchaAutoCheck(self, results): params = { 'answer': results, 'login_site': 'E', 'rand': 'sjrand', '_':int(time.time() * 1000) } jsonRet = EasyHttp.send(autoVerifyUrls['check_url'],params=params) # Log.d('验证码识别结果: %s' % jsonRet if jsonRet else 'None') def verify(response): return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response['result_code'] if response and 'result_code' in response else False return verify(jsonRet)
def _uamauthclient(self, apptk): jsonRet = EasyHttp.send(self._urlInfo["uamauthclient"], data={"tk": apptk}) print(jsonRet) def isSuccess(response): return (response["result_code"] == 0 if response and "result_code" in response else False) return ( isSuccess(jsonRet), "%s:%s" % (jsonRet["username"], jsonRet["result_message"]) if jsonRet else "uamauthclient failed", )
def _captchaCheck(self, results): data = { 'answer': results, 'login_site': 'E', 'rand': 'sjrand', } jsonRet = EasyHttp.send(loginUrls['normal']['captchaCheck'], data=data) print('captchaCheck: %s' % jsonRet) def verify(response): return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response[ 'result_code'] if 'result_code' in response else False return verify(jsonRet)
def _login_init(self): #死方法来手动每次更新deviceid url url_info = copy.deepcopy(self._urlInfo["getDevicesId"]) url_info['url'] = self._urlInfo["getDevicesId"]['url'] + str(int(time.time()*1000)) devices_id_rsp = EasyHttp.get_custom(url_info) # params = {"algID": request_alg_id(self._urlInfo['getJS']), "timestamp": int(time.time() * 1000)} # params = dict(params, **get_hash_code_params()) # devices_id_rsp = EasyHttp.send(self._urlInfo["getDevicesId"],params=params) if devices_id_rsp: callback = devices_id_rsp.text[18:-2] # callback = devices_id_rsp.replace("callbackFunction('", '').replace("')", '') try: text = json.loads(callback) devices_id = text.get('dfp') exp = text.get('exp') except Exception as e: return False,'获取设备指纹失败' EasyHttp.setCookies(RAIL_DEVICEID=devices_id, RAIL_EXPIRATION=exp) # Log.d('设备Id:%s'%devices_id) return True, '获取设备指纹成功' EasyHttp.send(self._urlInfo['index']) EasyHttp.send(self._urlInfo['loginInit']) return False,'获取设备指纹失败'
def _captchaAutoCheck(self, results): params = { 'answer': results, 'login_site': 'E', 'rand': 'sjrand', } jsonRet = EasyHttp.send(autoVerifyUrls['check_url'], params=params) # print('captchaCheck: %s' % jsonRet) def verify(response): return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response[ 'result_code'] if 'result_code' in response else False return verify(jsonRet)
def _submitOrderRequest(self, tourFlag='dc'): formData = { 'secretStr': TrainUtils.undecodeSecretStr(self.__ticket.secretStr), # 'secretStr': self.__ticket.secretStr, # 'secretStr': urllib.parse.unquote(self.__ticket.secretStr), 'train_date': Utils.formatDate(self.__ticket.startDate), # 2018-01-04 'back_train_date': time.strftime("%Y-%m-%d", time.localtime()), # query date:2017-12-31 'tour_flag': tourFlag, 'purpose_codes': self.__ticket.passengerType, 'query_from_station_name': self.__ticket.fromStation, 'query_to_station_name': self.__ticket.toStation, 'undefined': '', } jsonRet = EasyHttp.send(self._urlInfo['submitOrderRequest'], data=formData) # print('submitOrderRequest %s' % jsonRet) return jsonRet['status'], jsonRet['messages']
def _getPassengerDTOs(self): if not self._getExtraInfo(): return False, "获取乘客信息失败", None formData = { "_json_att": "", "REPEAT_SUBMIT_TOKEN": self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo["getPassengerDTOs"], data=formData) passengersList = jsonRet["data"]["normal_passengers"] return ( jsonRet["status"] if "status" in jsonRet else False, jsonRet["messages"] if "messages" in jsonRet else "无法获取乘客信息,请先进行添加!", self.__getPassengerInfo(passengersList), )
def _getExtraInfo(self): def getRepeatSubmitToken(html): repeatSubmitToken = re.findall(r"var globalRepeatSubmitToken = '(.*)'", html)[0] # print('RepeatSubmitToken = %s' % repeatSubmitToken) return repeatSubmitToken html = EasyHttp.send(self._urlInfo['getExtraInfo']) if not Utils.check(html, 'getExtraInfoUrl: failed to visit %s' % self._urlInfo['getExtraInfo']['url']): return False self.__ticket.repeatSubmitToken = getRepeatSubmitToken(html) def decodeTicketInfoForPassengerForm(html): ticketInfoForPassengerForm = re.findall(r'var ticketInfoForPassengerForm=(.*);', html)[0] return json.loads(ticketInfoForPassengerForm.replace("'", "\"")) # print('=======================') self.__ticket.ticketInfoForPassengerForm = decodeTicketInfoForPassengerForm(html) return True
def query(trainDate, fromStation, toStation, passengerType=PASSENGER_TYPE_ADULT): params = { r"leftTicketDTO.train_date": trainDate, r"leftTicketDTO.from_station": city2code(fromStation), r"leftTicketDTO.to_station": city2code(toStation), r"purpose_codes": passengerType, } jsonRet = EasyHttp.send(queryUrls["query"], params=params) try: if jsonRet: return Query.__decode(jsonRet["data"]["result"], passengerType) except Exception as e: Log.e(e) return []
def _captchaCheck(self, results): data = { 'answer': results, 'login_site': 'E', 'rand': 'sjrand', '_': int(time.time() * 1000) } jsonRet = EasyHttp.send(loginUrls['normal']['captchaCheck'], params=data) if not jsonRet: return False def verify(response): return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response[ 'result_code'] if 'result_code' in response else False return verify(jsonRet)
def _queryOrderWaitTime(self): params = { "random": "%10d" % (time.time() * 1000), "tourFlag": self.__ticket.ticketInfoForPassengerForm["tour_flag"] or "dc", "_json_att": "", "REPEAT_SUBMIT_TOKEN": self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo["queryOrderWaitTime"], params=params) print("queryOrderWaitTime: %s" % jsonRet) return ( jsonRet["status"], jsonRet["messages"], jsonRet["data"]["waitTime"], jsonRet["data"]["orderId"], jsonRet["data"]["msg"] if "msg" in jsonRet["data"] else None, )
def _getQueueCount(self): formData = { # Thu+Jan+04+2018+00:00:00+GMT+0800 # 'train_date': datetime.strptime( # self.__ticket.ticketInfoForPassengerForm['queryLeftTicketRequestDTO']['train_date'], '%Y%m%d').strftime( # '%b+%a+%d+%Y+00:00:00+GMT+0800'), # Mon Jan 08 2018 00:00:00 GMT+0800 (中国标准时间) "train_date": datetime.strptime( self.__ticket.ticketInfoForPassengerForm[ "queryLeftTicketRequestDTO"]["train_date"], "%Y%m%d", ).strftime("%b %a %d %Y 00:00:00 GMT+0800") + " (中国标准时间)", "train_no": self.__ticket.ticketInfoForPassengerForm[ "queryLeftTicketRequestDTO"]["train_no"], "stationTrainCode": self.__ticket.trainNo, "seatType": self.__ticket.seatType, "fromStationTelecode": self.__ticket.fromStationCode, "toStationTelecode": self.__ticket.toStationCode, "leftTicket": self.__ticket.ticketInfoForPassengerForm["leftTicketStr"], "purpose_codes": self.__ticket.ticketInfoForPassengerForm["purpose_codes"], "train_location": self.__ticket.ticketInfoForPassengerForm["train_location"], "_json_att": "", "REPEAT_SUBMIT_TOKEN": self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo["getQueueCount"], data=formData) return ( jsonRet["status"], jsonRet["messages"], jsonRet["data"]["ticket"] if "data" in jsonRet and "ticket" in jsonRet["data"] else -1, jsonRet["data"]["count"] if "data" in jsonRet and "count" in jsonRet["data"] else -1, )
def _submitOrderRequest(self, tourFlag="dc"): formData = { "secretStr": TrainUtils.undecodeSecretStr(self.__ticket.secretStr), # 'secretStr': self.__ticket.secretStr, # 'secretStr': urllib.parse.unquote(self.__ticket.secretStr), "train_date": Utils.formatDate(self.__ticket.startDate), # 2018-01-04 "back_train_date": time.strftime("%Y-%m-%d", time.localtime()), # query date:2017-12-31 "tour_flag": tourFlag, "purpose_codes": self.__ticket.passengerType, "query_from_station_name": self.__ticket.fromStation, "query_to_station_name": self.__ticket.toStation, "undefined": "", } jsonRet = EasyHttp.send(self._urlInfo["submitOrderRequest"], data=formData) print("submitOrderRequest %s" % jsonRet) return jsonRet["status"], jsonRet["messages"]
def _checkOrderInfo(self, passengersDetails, seatType, ticketTypeCodes=1): formData = { 'cancel_flag': self.__ticket.ticketInfoForPassengerForm['orderRequestDTO']['cancel_flag'] or '2', 'bed_level_order_num': self.__ticket.ticketInfoForPassengerForm['orderRequestDTO'][ 'bed_level_order_num'] or '000000000000000000000000000000', 'passengerTicketStr': TrainUtils.passengerTicketStrs(seatType, passengersDetails, ticketTypeCodes), 'oldPassengerStr': TrainUtils.oldPassengerStrs(passengersDetails), 'tour_flag': self.__ticket.ticketInfoForPassengerForm['tour_flag'] or 'dc', 'randCode': '', 'whatsSelect': '1', '_json_att': '', 'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken, } jsonRet = EasyHttp.send(self._urlInfo['checkOrderInfo'], data=formData) submitStatus = '' errMsg = '' if jsonRet['data']: submitStatus = jsonRet['data']['submitStatus'] errMsg = jsonRet['data']['errMsg'] if 'errMsg' in jsonRet['data'] else 'submit falied' return jsonRet['status'], jsonRet['messages'], submitStatus, errMsg
def _loginAsyncSuggest(self, userName, userPwd): self._init() results, verify = Captcha().verifyCaptchaByHand( type=TYPE_LOGIN_OTHER_WAY) if not verify: return False, '验证码识别错误!' formData = { 'loginUserDTO.user_name': userName, 'userDTO.password': userPwd, 'randCode': results, } jsonRet = EasyHttp.send(self._urlInfo['login'], data=formData) print('loginAsyncSuggest: %s' % jsonRet) def isSuccess(response): return response['status'] and response['data']['loginCheck'] == 'Y' if 'data' in response else False, \ response['data']['otherMsg'] if 'data' in response else response['messages'] loginSuccess, otherMsg = isSuccess(jsonRet) return loginSuccess, '%s:%s' % (userName, otherMsg or '登录成功!')