Skip to content

Commit

Permalink
12306登录更新
Browse files Browse the repository at this point in the history
  • Loading branch information
V-I-C-T-O-R committed Apr 23, 2019
1 parent 9ddc463 commit e5ad41e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 23 deletions.
30 changes: 23 additions & 7 deletions conf/urls_conf.py
Expand Up @@ -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',
Expand All @@ -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',
},
Expand Down Expand Up @@ -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&timestamp=",
"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',
}
}
},
# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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',
},
Expand Down
7 changes: 4 additions & 3 deletions 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
Expand Down Expand Up @@ -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()
Expand All @@ -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()]
Expand Down
Binary file modified ip.db
Binary file not shown.
12 changes: 7 additions & 5 deletions train/login/Capthca.py
@@ -1,3 +1,4 @@
import json
import os
from io import BytesIO

Expand Down Expand Up @@ -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)])
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions train/login/Login.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,'获取设备指纹失败'


Expand Down
13 changes: 11 additions & 2 deletions train/submit/Submit.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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:乘客姓名
Expand Down

0 comments on commit e5ad41e

Please sign in to comment.