mirror of https://github.com/testerSunshine/12306
加速需要验证码订票的速度
parent
c1ce4e4469
commit
b1ab036026
|
@ -41,39 +41,18 @@
|
|||
|
||||
set:
|
||||
station_dates:
|
||||
# - "2018-01-27"
|
||||
# - "2018-01-28"
|
||||
# - "2018-02-22"
|
||||
- "2018-02-23"
|
||||
|
||||
station_trains:
|
||||
- "G1031"
|
||||
- "G1013"
|
||||
- "G73"
|
||||
- "G6001"
|
||||
- "G6163"
|
||||
- "G1015"
|
||||
- "G79"
|
||||
- "G6031"
|
||||
- "G279"
|
||||
- "G817"
|
||||
- "G1017"
|
||||
- "G6485"
|
||||
- "G821"
|
||||
- "G1019"
|
||||
- "G6033"
|
||||
- "G75"
|
||||
- "G6025"
|
||||
- "G1021"
|
||||
- "G825"
|
||||
- "G6027"
|
||||
- "G6141"
|
||||
# - "G4741"
|
||||
# - "G2365"
|
||||
# - "G1371"
|
||||
# - "G1337"
|
||||
# - "G1377"
|
||||
# - "G1329"
|
||||
# - "G1302"
|
||||
# - "G1372"
|
||||
# - "G1326"
|
||||
- "D2879"
|
||||
- "D1813"
|
||||
- "D2975"
|
||||
- "D1825"
|
||||
- "D1829"
|
||||
- "D2841"
|
||||
- "D1833"
|
||||
# - "K4300"
|
||||
# - "K5226"
|
||||
# - "K7772"
|
||||
|
@ -83,13 +62,14 @@ set:
|
|||
# - "G1373"
|
||||
# - "G1363"
|
||||
# - "G4933"
|
||||
from_station: "长沙南"
|
||||
to_station: "深圳北"
|
||||
from_station: "三江南"
|
||||
to_station: "广州南"
|
||||
set_type:
|
||||
- "一等座"
|
||||
- "二等座"
|
||||
is_more_ticket: True
|
||||
ticke_peoples:
|
||||
- "高智"
|
||||
- "梁敏"
|
||||
# - "彭淑杰"
|
||||
12306count:
|
||||
# - uesr: ""
|
||||
|
@ -97,9 +77,8 @@ set:
|
|||
- uesr: "931128603@qq.com"
|
||||
- pwd: "QWERTY"
|
||||
|
||||
select_refresh_interval: 0.5
|
||||
expect_refresh_interval: 0.1
|
||||
ticket_black_list_time: 3
|
||||
select_refresh_interval: 0.3
|
||||
ticket_black_list_time: 6
|
||||
is_aotu_code: True
|
||||
aotu_code_type: 2
|
||||
#enable_proxy: False
|
||||
|
|
|
@ -37,6 +37,7 @@ class GoLogin:
|
|||
识别验证码
|
||||
:return: 坐标
|
||||
"""
|
||||
try:
|
||||
if self.is_aotu_code:
|
||||
if self.aotu_code_type == 1:
|
||||
return DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"], "./tkcode").main()
|
||||
|
@ -54,6 +55,8 @@ class GoLogin:
|
|||
img = Image.open('./tkcode')
|
||||
img.show()
|
||||
return self.codexy()
|
||||
except:
|
||||
pass
|
||||
|
||||
def readImg(self, code_url):
|
||||
"""
|
||||
|
@ -224,6 +227,7 @@ class GoLogin:
|
|||
if self.codeCheck():
|
||||
uamtk = self.baseLogin(user, passwd)
|
||||
if uamtk:
|
||||
self.getUserName(uamtk)
|
||||
break
|
||||
|
||||
def logout(self):
|
||||
|
|
|
@ -28,7 +28,7 @@ sys.setdefaultencoding('utf-8')
|
|||
|
||||
class select:
|
||||
def __init__(self):
|
||||
self.from_station, self.to_station, self.station_dates, self._station_seat, self.is_more_ticket, self.ticke_peoples, self.select_refresh_interval, self.station_trains, self.expect_refresh_interval, self.ticket_black_list_time = self.get_ticket_info()
|
||||
self.from_station, self.to_station, self.station_dates, self._station_seat, self.is_more_ticket, self.ticke_peoples, self.select_refresh_interval, self.station_trains, self.ticket_black_list_time = self.get_ticket_info()
|
||||
self.is_aotu_code = _get_yaml()["is_aotu_code"]
|
||||
self.aotu_code_type = _get_yaml()["aotu_code_type"]
|
||||
self.order_request_params = {} # 订单提交时的参数
|
||||
|
@ -60,10 +60,9 @@ class select:
|
|||
ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
|
||||
select_refresh_interval = ticket_info_config["select_refresh_interval"]
|
||||
station_trains = ticket_info_config["set"]["station_trains"]
|
||||
expect_refresh_interval = ticket_info_config["expect_refresh_interval"]
|
||||
ticket_black_list_time = ticket_info_config["ticket_black_list_time"]
|
||||
print "*"*20
|
||||
print "当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n刷新间隔:{6}\n候选购买车次:{7}\n未开始刷票间隔时间:{8}\n僵尸票关小黑屋时长:{9}\n".format\
|
||||
print "当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n刷新间隔:{6}\n候选购买车次:{7}\n僵尸票关小黑屋时长:{8}\n".format\
|
||||
(
|
||||
from_station,
|
||||
to_station,
|
||||
|
@ -73,11 +72,10 @@ class select:
|
|||
",".join(ticke_peoples),
|
||||
select_refresh_interval,
|
||||
",".join(station_trains),
|
||||
expect_refresh_interval,
|
||||
ticket_black_list_time,
|
||||
)
|
||||
print "*"*20
|
||||
return from_station, to_station, station_dates, set_type, is_more_ticket, ticke_peoples, select_refresh_interval, station_trains, expect_refresh_interval, ticket_black_list_time
|
||||
return from_station, to_station, station_dates, set_type, is_more_ticket, ticke_peoples, select_refresh_interval, station_trains, ticket_black_list_time
|
||||
|
||||
def get_order_request_params(self):
|
||||
return self.order_request_params
|
||||
|
@ -154,7 +152,10 @@ class select:
|
|||
识别验证码
|
||||
:return:
|
||||
"""
|
||||
while True:
|
||||
if self.is_aotu_code:
|
||||
self.randCode = self.login.getRandCode()
|
||||
self.is_aotu_code = False
|
||||
|
||||
def getRepeatSubmitToken(self):
|
||||
"""
|
||||
|
@ -393,6 +394,8 @@ class select:
|
|||
if 'data' in checkOrderInfo:
|
||||
if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo["data"]["ifShowPassCode"] == "Y":
|
||||
is_need_code = True
|
||||
t = threading.Thread(target=self.callRandCode())
|
||||
t.start()
|
||||
if self.getQueueCount(train_no, set_type, is_need_code):
|
||||
return True
|
||||
if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo['data']['submitStatus'] is True:
|
||||
|
@ -459,6 +462,21 @@ class select:
|
|||
else:
|
||||
print("未知错误 {0}".format("".join(getQueueCountResult)))
|
||||
|
||||
def checkRandCodeAnsyn(self, randCode):
|
||||
"""
|
||||
识别验证码
|
||||
:return: 识别结果
|
||||
"""
|
||||
checkRandCodeAnsyn = self.confUrl["checkRandCodeAnsyn"]["req_url"]
|
||||
randData = {
|
||||
"randCode": randCode,
|
||||
"rand": "randp",
|
||||
"_json_att": None,
|
||||
"REPEAT_SUBMIT_TOKEN": self.get_token()
|
||||
}
|
||||
fresult = self.httpClint.send(checkRandCodeAnsyn, randData) # 校验验证码是否正确
|
||||
return fresult['data']['msg']
|
||||
|
||||
def checkQueueOrder(self, is_node_code=False):
|
||||
"""
|
||||
模拟提交订单是确认按钮,参数获取方法还是get_ticketInfoForPassengerForm 中获取
|
||||
|
@ -483,31 +501,31 @@ class select:
|
|||
}
|
||||
|
||||
try:
|
||||
for i in range(3):
|
||||
if is_node_code:
|
||||
|
||||
print("正在使用自动识别验证码功能")
|
||||
checkRandCodeAnsyn = self.confUrl["checkRandCodeAnsyn"]["req_url"]
|
||||
while True:
|
||||
if self.randCode:
|
||||
checkcode = self.checkRandCodeAnsyn(self.randCode)
|
||||
if checkcode == 'TRUE':
|
||||
print("验证码通过,正在提交订单")
|
||||
data['randCode'] = self.randCode
|
||||
self.randCode = ""
|
||||
break
|
||||
else:
|
||||
for i in range(3):
|
||||
codeImgByOrder = self.confUrl["codeImgByOrder"]["req_url"]
|
||||
self.login.readImg(codeImgByOrder)
|
||||
randCode = self.login.getRandCode()
|
||||
randData = {
|
||||
"randCode": randCode,
|
||||
"rand": "randp",
|
||||
"_json_att": None,
|
||||
"REPEAT_SUBMIT_TOKEN": self.get_token()
|
||||
}
|
||||
fresult = self.httpClint.send(checkRandCodeAnsyn, randData) # 校验验证码是否正确
|
||||
checkcode = fresult['data']['msg']
|
||||
if checkcode == 'TRUE':
|
||||
print("验证码通过,正在提交订单")
|
||||
data['randCode'] = randCode
|
||||
break
|
||||
else:
|
||||
print ("验证码有误, 接口返回{0} 第{1}次尝试重试".format(fresult, i))
|
||||
print ("验证码有误, {0}次尝试重试".format(i+1))
|
||||
print("验证码超过限定次数3次,放弃此次订票机会!")
|
||||
break
|
||||
else:
|
||||
print("不需要验证码")
|
||||
break
|
||||
checkQueueOrderResult = self.httpClint.send(checkQueueOrderUrl, data)
|
||||
if "status" in checkQueueOrderResult and checkQueueOrderResult["status"]:
|
||||
c_data = checkQueueOrderResult["data"] if "data" in checkQueueOrderResult else {}
|
||||
|
|
Loading…
Reference in New Issue