diff --git a/conf/urls_conf.py b/conf/urls_conf.py index 8b425ff..51a09d2 100644 --- a/conf/urls_conf.py +++ b/conf/urls_conf.py @@ -2,6 +2,20 @@ import time loginUrls = { 'normal': { + 'index':{ + 'url': r'https://www.12306.cn/index/', + 'method': 'GET', + 'headers': { + 'Accept': r'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Upgrade-Insecure-Requests': '1', + }, + 'response': 'html', + }, + 'conf':{ + 'url':'https://kyfw.12306.cn/otn/login/conf', + 'method': 'GET', + 'response': 'html', + }, 'init': { 'url': r'https://kyfw.12306.cn/otn/login/init', 'method': 'GET', @@ -17,6 +31,8 @@ 'headers': { 'Accept': r'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Referer': r'https://www.12306.cn/index/', + 'Upgrade-Insecure-Requests': '1', + 'Accept-Encoding':'gzip, deflate, br', }, 'response': 'html', }, @@ -113,8 +129,13 @@ 'response': 'html', }, "getDevicesId": { # 获取用户信息 - "url": "https://kyfw.12306.cn/otn/HttpZF/logdevice", + "url": "https://kyfw.12306.cn/otn/HttpZF/logdevice?algID=z0nwCFNNFy&hashCode=Sonomt4GXxQ8y5nP8OKANN4uqj_LKFPbEeGZQpQSQLc&FMQw=0&q4f3=zh-CN&VySQ=FGF9QEe67lYGavdZicwJH4vsu9jHLwS5&VPIf=1&custID=133&VEek=unknown&dzuS=0&yD16=0&EOQP=f57fa883099df9e46e7ee35d22644d2b&lEnu=3232235621&jp76=52d67b2a5aa5e031084733d5006cc664&hAqN=Win32&platform=WEB&ks0Q=d22ca0b81584fbea62237b14bd04c866&TeRS=1080x1920&tOHY=24xx1080x1920&Fvje=i1l1o1s1&q5aJ=-8&wNLf=99115dfb07133750ba677d055874de87&0aew=Mozilla/5.0%20(Windows%20NT%206.1;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/68.0.3440.106%20Safari/537.36&E3gR=6ffe6a32e9af788920458ef31ceafe4a×tamp=", "method": "GET", + 'headers' :{ + 'Host': 'kyfw.12306.cn', + 'Referer': 'https://kyfw.12306.cn/otn/resources/login.html', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36', + } } }, # -------------------------------------------------------------------------------------------------------- @@ -251,13 +272,8 @@ 'method': 'POST', 'headers': { 'Referer': 'https://kyfw.12306.cn/otn/leftTicket/init', - 'Content-Type': r'application/x-www-form-urlencoded; charset=UTF-8', + 'Content-Type': r'application/x-www-form-urlencoded', 'Host': r'kyfw.12306.cn', - 'X-Requested-With':'XMLHttpRequest', - 'Accept-Encoding':'gzip, deflate, br', - 'Accept-Language':'zh-CN,zh;q=0.9', - 'Origin':'https://kyfw.12306.cn', - 'Upgrade-Insecure-Requests':'1', }, 'response': 'html', }, diff --git a/fuckeverything.py b/fuckeverything.py index 814cf0d..000a1fb 100644 --- a/fuckeverything.py +++ b/fuckeverything.py @@ -1,5 +1,5 @@ import time - +from conf.urls_conf import loginUrls from conf.constant import SEAT_TYPE from configure import * from net import init_ip_pool @@ -34,8 +34,8 @@ def main(): cookies = {c.name: c.value for c in EasyHttp.get_session().cookies} RAIL_EXPIRATION = cookies.get('RAIL_EXPIRATION') - #当前实际显示有效时间为4天,实际访问可下单时间大概为2天(细节可按实际情况调节) - if 'RAIL_EXPIRATION' in cookies and (int(RAIL_EXPIRATION)-172800000) < int(time.time()*1000) : + #(int(RAIL_EXPIRATION)-172800000) < int(time.time()*1000) + if 'RAIL_EXPIRATION' in cookies and int(RAIL_EXPIRATION) < int(time.time()*1000) : Log.v('cookie登录已过期,重新请求') EasyHttp.removeCookies() status,login = do_login() @@ -48,6 +48,7 @@ def main(): return else: login = Login() + login._urlInfo = loginUrls['normal'] Log.v('已登录状态,开始寻找小票票') seatTypesCode = SEAT_TYPE_CODE if SEAT_TYPE_CODE else [SEAT_TYPE[key] for key in SEAT_TYPE.keys()] diff --git a/ip.db b/ip.db index 2526fb8..25fca94 100644 Binary files a/ip.db and b/ip.db differ diff --git a/train/login/Capthca.py b/train/login/Capthca.py index 0e7d149..51f1f3d 100644 --- a/train/login/Capthca.py +++ b/train/login/Capthca.py @@ -1,3 +1,4 @@ +import json import os from io import BytesIO @@ -93,7 +94,7 @@ def verifyCaptchaByHand(self, type=TYPE_LOGIN_NORMAL_WAY): return results, self.check(results, type) def __indexTransCaptchaResults(self, indexes, sep=r','): - coordinates = ['40,40', '110,40', '180,40', '250,40', '40,110', '110,110', '180,110', '250,110'] + coordinates = ['31, 35', '116, 46', '191, 24', '243, 50', '22, 114', '117, 94', '167, 120', '251, 105'] results = [] for index in indexes.split(sep=sep): results.append(coordinates[int(index)]) @@ -121,9 +122,10 @@ def verifyCodeAuto(self): # img_base64 = result body = {'base64': img_base64} - response = requests.post(autoVerifyUrls['api']['url'],json=body,headers ={ - 'Content-Type': 'application/json', - }).json() + response = EasyHttp.post_custom(autoVerifyUrls['api'],data=json.dumps(body)).json() + # response = requests.post(autoVerifyUrls['api']['url'],json=body,headers ={ + # 'Content-Type': 'application/json', + # }).json() if response['success'] != True: return None, False @@ -134,7 +136,7 @@ def verifyCodeAuto(self): 'type': 'D', '=':'' } - response = requests.post(autoVerifyUrls['img_url']['url'],json=body).json() + response = EasyHttp.post_custom(autoVerifyUrls['img_url'],data=json.dumps(body)).json() content = str(response['res']) results = content.replace('(','').replace(')','') Log.d('识别坐标:%s'%results) diff --git a/train/login/Login.py b/train/login/Login.py index 6dc171e..482bc77 100644 --- a/train/login/Login.py +++ b/train/login/Login.py @@ -53,6 +53,7 @@ def isSuccess(response): jsonRet['newapptk'] if jsonRet and 'newapptk' in jsonRet else 'no newapptk' def _uamtk_static(self): + EasyHttp.send(self._urlInfo['conf']) jsonRet = EasyHttp.send(self._urlInfo['uamtk-static'], data={'appid': 'otn'}) def isSuccess(response): @@ -110,15 +111,15 @@ def _loginNormal(self, userName, userPwd, autoCheck=2): payload['appid'] = 'otn' payload['answer'] = results - jsonRet = EasyHttp.send(self._urlInfo['login'], data=payload) + response = EasyHttp.post_custom(self._urlInfo['login'], data=payload) def isLoginSuccess(responseJson): return 0 == responseJson['result_code'] if responseJson and 'result_code' in responseJson else False, \ responseJson[ 'result_message'] if responseJson and 'result_message' in responseJson else '登录失败' - result, msg = isLoginSuccess(jsonRet) - if not result: + result, msg = isLoginSuccess(response.json()) + if not result : return False, msg self._userLogin() self._passportRedirect() @@ -171,16 +172,18 @@ def _init(self): EasyHttp.send(self._urlInfo['init']) def _login_init(self): - EasyHttp.send(self._urlInfo['loginInit']) + self._urlInfo["getDevicesId"]['url'] = self._urlInfo["getDevicesId"]['url'] + str(int(time.time()*1000)) devices_id_rsp = EasyHttp.get_custom(self._urlInfo["getDevicesId"]) if devices_id_rsp: callback = devices_id_rsp.text.replace("callbackFunction('", '').replace("')", '') text = json.loads(callback) devices_id = text.get('dfp') exp = text.get('exp') - EasyHttp.setCookies(RAIL_DEVICEID=devices_id,RAIL_EXPIRATION=exp) + EasyHttp.setCookies(RAIL_DEVICEID=devices_id, RAIL_EXPIRATION=exp) # Log.d('设备Id:%s'%devices_id) - return True,'获取设备指纹成功' + return True, '获取设备指纹成功' + EasyHttp.send(self._urlInfo['index']) + EasyHttp.send(self._urlInfo['loginInit']) return False,'获取设备指纹失败' diff --git a/train/submit/Submit.py b/train/submit/Submit.py index eaf895c..7a467af 100644 --- a/train/submit/Submit.py +++ b/train/submit/Submit.py @@ -57,8 +57,17 @@ def getRepeatSubmitToken(html): # print('RepeatSubmitToken = %s' % repeatSubmitToken) return repeatSubmitToken + formData = { + '_json_att': '' + } self._urlInfo['getExtraInfo']['headers']['Referer'] = self._urlInfo['getExtraInfo']['headers']['Referer']+ '?linktypeid='+self.__ticket.tourFlag - html = EasyHttp.send(self._urlInfo['getExtraInfo']) + response = EasyHttp.post_custom(self._urlInfo['getExtraInfo'],data=formData) + + if response and response.status_code == requests.codes.ok: + html = response.text + else: + html = None + # 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) @@ -109,7 +118,7 @@ def _getPassengerDTOs(self): 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 '无法获取乘客信息,请先进行添加!', \ + jsonRet['messages'] if jsonRet and 'messages' in jsonRet else '无法获取乘客信息,请先进行添加!', \ self.__getPassengerInfo(passengersList) # passengerName:乘客姓名