def login(self): if not LOGIN_SESSION.cookies.get("RAIL_EXPIRATION") or \ not LOGIN_SESSION.cookies.get("RAIL_DEVICEID"): status, msg = self._init() if not status: return status, msg # status, msg = self._get_device_fingerprint() # if not status: # Log.v("设备ID获取失败") # return status, msg # self._init2() captcha = Captcha("normal") status, msg = captcha.verify() if not status: Log.v("验证码校验失败") return status, msg payload = { 'username': Config.train_account.user, 'password': Config.train_account.pwd, 'appid': 'otn', 'answer': captcha.results } json_response = send_requests(LOGIN_SESSION, self.URLS['login'], data=payload) result, msg = json_status(json_response, [], '0') if not result: return (False, json_response.get("result_message", None)) \ if isinstance(json_response, dict) else (False, '登录接口提交返回数据出现问题') self._passportredirect() result, msg, apptk = self._uamtk() if not result: Log.v(msg) return False, msg status, msg = self._uamauthclient(apptk) return status, msg
def _uamtk(self): json_data = send_requests(LOGIN_SESSION, self.URLS["uamtk"], data={'appid': 'otn'}) Log.d(json_data) result, msg = json_status(json_data, ["result_message", "newapptk"]) if not result: return result, msg, None else: return result, msg, json_data["newapptk"]
def _uamauthclient(self, apptk): json_response = send_requests(LOGIN_SESSION, self.URLS['uamauthclient'], data={'tk': apptk}) status, msg = json_status(json_response, ["username", "result_message"]) if status: Log.v("欢迎 {0} 登录".format(json_response["username"])) return status, msg
def check(self, results): params_data = {'answer': results, 'rand': 'sjrand', 'login_site': 'E'} while True: try: json_response = send_captcha_requests( LOGIN_SESSION, LOGIN_URL_MAPPING["normal"]["captchaCheck"], params=params_data) break except (ResponseCodeError, ResponseError): Log.v("提交验证码错误, 重新提交验证码验证") continue Log.v('验证码校验结果: %s' % json_response) status, msg = json_status(json_response, [], ok_code=self.success_code) if not status: Log.v("验证码识别失败") return status, msg
def login(self): self._init() captcha = Captcha("normal") status, msg = captcha.verify() if not status: Log.v("验证码校验失败") return status, msg payload = { 'username': Config.train_account.user, 'password': Config.train_account.pwd, 'appid': 'otn', 'answer': captcha.results } json_response = send_requests(LOGIN_SESSION, self.URLS['login'], data=payload) result, msg = json_status(json_response, [], '0') if not result: return False, json_response.get("result_message", None) self._passportredirect() result, msg, apptk = self._uamtk() if not result: Log.v(msg) return False, msg status, msg = self._uamauthclient(apptk) return status, msg