def submit_order(self): ''' 提交购票请求 :return: ''' # print(self.secretStr) self.secretStr = unquote(self.secretStr) url = 'https://kyfw.12306.cn/otn/leftTicket/submitOrderRequest' data = { 'secretStr': self.secretStr, 'train_date': train_data, 'back_train_date': train_data, 'tour_flag': 'dc', 'purpose_codes': 'ADULT', 'query_from_station_name': from_station, 'query_to_station_name': to_station, 'undefined': '', } res = s.post(url, data=data, headers=headers, verify=False) url1 = 'https://kyfw.12306.cn/otn/confirmPassenger/initDc' data = { '_json_att': '' } res = s.post(url1, data=data, headers=headers, verify=False) # print(res.text) return res.text
def confirm_order(self): ''' 确认提交 :return: ''' url = 'https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue' data = { 'passengerTicketStr': '{},0,1,{},1,{},{},N'.format(submit_seat[self.seat], name, idendity, mobile), 'oldPassengerStr': '{},1,{},{}_'.format(name, idendity, user_num), 'randCode': '', 'purpose_codes': '00', 'key_check_isChange': self.key_check_isChange, 'leftTicketStr': self.train_information[12], 'train_location': self.train_information[15], 'choose_seats': '', 'seatDetailType': '000', 'whatsSelect': '1', 'roomType': '00', 'dwAll': 'N', '_json_att': '', 'REPEAT_SUBMIT_TOKEN': self.REPEAT_SUBMIT_TOKEN, } res = s.post(url, data=data, headers=headers, verify=False) html = json.loads(res.text) if html['data']['submitStatus']: print('订票成功啦!请30分钟内到官网进行支付') return Order_ticket.message()
def get_count(self): ''' 确认数量 :return: ''' global train_data year_s, mon_s, day_s = train_data.split('-') data_time = datetime(int(year_s), int(mon_s), int(day_s)) data_time = datetime.strftime(data_time, '%a %b %d %Y %X') url = 'https://kyfw.12306.cn/otn/confirmPassenger/getQueueCount' data = { 'train_date': '{} GMT+0800 (CST)'.format(data_time), 'train_no': self.train_information[2], 'stationTrainCode': self.train_information[3], 'seatType': '{}'.format(submit_seat[self.seat]), 'fromStationTelecode': self.train_information[6], 'toStationTelecode': self.train_information[7], 'leftTicket': self.train_information[12], 'purpose_codes': '00', 'train_location': self.train_information[15], '_json_att': '', 'REPEAT_SUBMIT_TOKEN': self.REPEAT_SUBMIT_TOKEN, } res = s.post(url, data=data, headers=headers, verify=False) print(res.text)
def check_user(self): ''' 检查用户是否登陆 :return: ''' url = 'https://kyfw.12306.cn/otn/login/checkUser' data = { '_json_att=': '' } res = s.post(url, data=data, headers=headers, verify=False)
def login(self): ''' 输入账号密码进行登陆 :return: ''' url1 = 'https://kyfw.12306.cn/passport/web/login' data = {'username': username, 'password': password, 'appid': 'otn'} res1 = s.post(url1, headers=headers, data=data, verify=False) url2 = 'https://kyfw.12306.cn/otn/login/userLogin' res2 = s.get(url2, headers=headers, verify=False) url3 = 'https://kyfw.12306.cn/passport/web/auth/uamtk' data = {'appid': 'otn'} res3 = s.post(url3, headers=headers, data=data, verify=False) html = json.loads(res3.text) # print(html) newapptk = html['newapptk'] url4 = 'https://kyfw.12306.cn/otn/uamauthclient' data = {'tk': newapptk} res4 = s.post(url4, headers=headers, data=data, verify=False) html = json.loads(res4.text) if html['result_code'] == 0: print('账号验证通过,登陆成功') else: print('账号验证失败,清检查用户名或者密码是否有错误,再重试')
def verify_code(self): ''' 提交验证码进行验证 :return: ''' code_content = Login12306.get_code() code = self.pic.post_pic(code_content, Chaojiying_kind) # print(code) data = {'answer': code, 'login_site': 'E', 'rand': 'sjrand'} check_url = 'https://kyfw.12306.cn/passport/captcha/captcha-check' res = s.post(check_url, data=data, headers=headers, verify=False) html = json.loads(res.text) # print(res.text) if html['result_code'] == '4': print('验证码校验成功') return True else: print('验证码校验失败,正在重新验证') return self.verify_code()
def check_info(self): ''' 确认信息是否正确页面 :return: ''' url = 'https://kyfw.12306.cn/otn/confirmPassenger/checkOrderInfo' data = { 'cancel_flag': '2', 'bed_level_order_num': '000000000000000000000000000000', 'passengerTicketStr': '{},0,1,{},1,{},{},N'.format(submit_seat[self.seat], name, idendity, mobile), 'oldPassengerStr': '{},1,{},{}_'.format(name, idendity, user_num), 'tour_flag': 'dc', 'randCode': '', 'whatsSelect': '1', '_json_att': '', 'REPEAT_SUBMIT_TOKEN': self.REPEAT_SUBMIT_TOKEN, } res = s.post(url, data=data, headers=headers, verify=False) print(res.text)