def submit_order(self, init_params): params = { "cancel_flag": 2, "bed_level_order_num": "000000000000000000000000000000", "passengerTicketStr": init_params["passengers_str"], "oldPassengerStr": init_params["ticket_str"], "tour_flag": "dc", "randCode": "", "whatsSelect": 1, "sessionId": "", "sig": "", "scene": "nc_login", "_json_att": "", "REPEAT_SUBMIT_TOKEN": init_params["REPEAT_SUBMIT_TOKEN"] } res = api.post(self.__check_order_info, data=params) result = res.json() if result["status"] and result["data"]["submitStatus"]: print("检查订单信息成功!") self.__ticket.query_left_tickets_info(init_params) if result["data"]["canChooseSeats"] == "Y": self.__ticket.choose_seat(init_params) return result["data"] else: print("检查订单信息失败!系统自动退出...") sys.exit(0)
def query_left_tickets_info(self, init_params): params = { "train_date": datetime.datetime.strptime( config.TRAIN_DATA, '%Y-%m-%d').strftime("%a %b %d %Y %H:%M:%S GMT+0800 (中国标准时间)"), "train_no": init_params["train_no"], "stationTrainCode": init_params["station_train_code"], "seatType": config.SEAT_TYPE, "fromStationTelecode": init_params["from_station_telecode"], "toStationTelecode": init_params["to_station"], "leftTicket": init_params["leftTicketStr"], "purpose_codes": init_params["purpose_codes"], "train_location": init_params["train_location"], "_json_att": "", "REPEAT_SUBMIT_TOKEN": init_params["REPEAT_SUBMIT_TOKEN"] } res = api.post(self.__query_queue_count_url, data=params) result = res.json() if result["status"]: print("您所选的座位还剩余" + result["data"]["ticket"] + "张车票, 当前排队人数为:" + result["data"]["count"]) else: print("获取余票失败!系统自动退出.....") sys.exit(0)
def get_apptk(self): res = api.post(self.__get_apptk_url, data={"appid": "otn"}) data = res.json() if data["result_code"] == 0: print("获取apptk成功!") return data["newapptk"] else: print("获取apptk失败!系统自动退出...") sys.exit(0)
def get_not_complete_order(self): params = {"_json_att": ""} res = api.post(self.__not_complete_order, data=params) result = res.json() if result["status"]: return result["data"]["orderDBList"] else: print("获取未完成失败!系统自动退出。。。") sys.exit(0)
def get_passenger(self): data = {"_json_att": "", "REPEAT_SUBMIT_TOKEN": self.__submit_token} res = api.post(self.__get_passenger_url, data=data) result = res.json() normal_passengers = result["data"]["normal_passengers"] passengers = filter( lambda passenger: passenger["passenger_name"] in config.PASSENGERS, normal_passengers) return list(passengers)
def validate_apptk(self, newapptk): data = {'tk': newapptk} res = api.post(self.__validate_apptk_url, data=data) result = res.json() if result['result_code'] == 0: print("apptk认证成功!") return result["apptk"] else: print("apptk认证失败!系统自动退出....") sys.exit(0)
def get_cached_order(self): params = {"_json_att": ""} res = api.post(self.__not_complete_order, data=params) result = res.json() if result["status"]: return result["data"]["orderCacheDTO"] else: print(result) print("获取缓存订单失败!系统自动退出...") sys.exit(0)
def silde_passcode(self): data = {"appid": "otn", "slideMode": 0, "username": self.__username} response = api.post(self.__slide_passcode_url, data=data) data = response.json() if data["result_code"] == '0': print("启用滑块验证!") self.__if_check_slide_passcode_token = data[ "if_check_slide_passcode_token"] elif data["result_code"] == '1': print("滑块校验成功!") else: raise Exception("滑块验证失败!")
def login(self): data = { "username": self.__username, "password": self.__password, "appid": "otn", "answer": self.__answer } response = api.post(self.__login_url, data=data) data = response.json() if data["result_code"] == 0: print("用户" + config.USERNAME + "登陆成功!") return data["uamtk"] else: print("用户" + config.USERNAME + "登陆失败!系统自动退出...") sys.exit(0)
def ready_order(self): secret = self.__ticket.get_train_secret(self.__train_number) data = { "secretStr": secret, "train_date": self.__train_date, "back_train_date": self.__train_date, "tour_flag": "dc", "purpose_codes": "ADULT", "query_from_station_name": self.__from_station_name, "query_to_station_name": self.__to_station_name, "undefined": "" } res = api.post(self.__submit_url, data=data) result = res.json() if result["status"] and result['data'] == 'N': print("订单提交成功!") else: print(result) print("订单提交失败!系统自动退出...") sys.exit(0)
def choose_seat(self, init_params): params = { "passengerTicketStr": init_params["passengers_str"], "oldPassengerStr": init_params["ticket_str"], "randCode": "", "purpose_codes": init_params["purpose_codes"], "key_check_isChange": init_params["key_check_isChange"], "leftTicketStr": init_params["leftTicketStr"], "train_location": init_params["train_location"], "choose_seats": config.CHOOSE_SEATS, "seatDetailType": 000, "whatsSelect": 1, "roomType": 00, "dwAll": "N", "_json_att": "", "REPEAT_SUBMIT_TOKEN": init_params["REPEAT_SUBMIT_TOKEN"] } res = api.post(self.__choose_seats_url, data=params) result = res.json() if result["status"] and result["data"]["submitStatus"]: print("选择座位成功!") else: print("您所坐的车辆不支持选座!")
def check_captcha(self, answer): params = {"answer": answer, "rand": "sjrand", "login_site": "E"} res = api.post(self.__check_captcha_url, data=params) return res.json()["result_code"] == "4"