加速需要验证码订票的速度

dev
wenxianping 7 years ago
parent c1ce4e4469
commit b1ab036026

@ -41,39 +41,18 @@
set: set:
station_dates: station_dates:
# - "2018-01-27"
# - "2018-01-28"
# - "2018-02-22"
- "2018-02-23" - "2018-02-23"
station_trains: station_trains:
- "G1031" - "D2879"
- "G1013" - "D1813"
- "G73" - "D2975"
- "G6001" - "D1825"
- "G6163" - "D1829"
- "G1015" - "D2841"
- "G79" - "D1833"
- "G6031"
- "G279"
- "G817"
- "G1017"
- "G6485"
- "G821"
- "G1019"
- "G6033"
- "G75"
- "G6025"
- "G1021"
- "G825"
- "G6027"
- "G6141"
# - "G4741"
# - "G2365"
# - "G1371"
# - "G1337"
# - "G1377"
# - "G1329"
# - "G1302"
# - "G1372"
# - "G1326"
# - "K4300" # - "K4300"
# - "K5226" # - "K5226"
# - "K7772" # - "K7772"
@ -83,13 +62,14 @@ set:
# - "G1373" # - "G1373"
# - "G1363" # - "G1363"
# - "G4933" # - "G4933"
from_station: "长沙南" from_station: "三江南"
to_station: "深圳北" to_station: "广州南"
set_type: set_type:
- "一等座"
- "二等座" - "二等座"
is_more_ticket: True is_more_ticket: True
ticke_peoples: ticke_peoples:
- "高智" - "梁敏"
# - "彭淑杰" # - "彭淑杰"
12306count: 12306count:
# - uesr: "" # - uesr: ""
@ -97,9 +77,8 @@ set:
- uesr: "931128603@qq.com" - uesr: "931128603@qq.com"
- pwd: "QWERTY" - pwd: "QWERTY"
select_refresh_interval: 0.5 select_refresh_interval: 0.3
expect_refresh_interval: 0.1 ticket_black_list_time: 6
ticket_black_list_time: 3
is_aotu_code: True is_aotu_code: True
aotu_code_type: 2 aotu_code_type: 2
#enable_proxy: False #enable_proxy: False

@ -37,23 +37,26 @@ class GoLogin:
识别验证码 识别验证码
:return: 坐标 :return: 坐标
""" """
if self.is_aotu_code: try:
if self.aotu_code_type == 1: if self.is_aotu_code:
return DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"], "./tkcode").main() if self.aotu_code_type == 1:
elif self.aotu_code_type == 2: return DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"], "./tkcode").main()
rc = RClient(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"]) elif self.aotu_code_type == 2:
im = open('./tkcode', 'rb').read() rc = RClient(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"])
Result = rc.rk_create(im, 6113) im = open('./tkcode', 'rb').read()
if "Result" in Result: Result = rc.rk_create(im, 6113)
return self.codexy(Ofset=",".join(list(Result["Result"])), is_raw_input=False) if "Result" in Result:
else: return self.codexy(Ofset=",".join(list(Result["Result"])), is_raw_input=False)
if "Error" in Result and Result["Error"]: else:
print Result["Error"] if "Error" in Result and Result["Error"]:
return "" print Result["Error"]
else: return ""
img = Image.open('./tkcode') else:
img.show() img = Image.open('./tkcode')
return self.codexy() img.show()
return self.codexy()
except:
pass
def readImg(self, code_url): def readImg(self, code_url):
""" """
@ -224,6 +227,7 @@ class GoLogin:
if self.codeCheck(): if self.codeCheck():
uamtk = self.baseLogin(user, passwd) uamtk = self.baseLogin(user, passwd)
if uamtk: if uamtk:
self.getUserName(uamtk)
break break
def logout(self): def logout(self):

@ -28,7 +28,7 @@ sys.setdefaultencoding('utf-8')
class select: class select:
def __init__(self): 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.is_aotu_code = _get_yaml()["is_aotu_code"]
self.aotu_code_type = _get_yaml()["aotu_code_type"] self.aotu_code_type = _get_yaml()["aotu_code_type"]
self.order_request_params = {} # 订单提交时的参数 self.order_request_params = {} # 订单提交时的参数
@ -60,10 +60,9 @@ class select:
ticke_peoples = ticket_info_config["set"]["ticke_peoples"] ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
select_refresh_interval = ticket_info_config["select_refresh_interval"] select_refresh_interval = ticket_info_config["select_refresh_interval"]
station_trains = ticket_info_config["set"]["station_trains"] 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"] ticket_black_list_time = ticket_info_config["ticket_black_list_time"]
print "*"*20 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, from_station,
to_station, to_station,
@ -73,11 +72,10 @@ class select:
",".join(ticke_peoples), ",".join(ticke_peoples),
select_refresh_interval, select_refresh_interval,
",".join(station_trains), ",".join(station_trains),
expect_refresh_interval,
ticket_black_list_time, ticket_black_list_time,
) )
print "*"*20 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): def get_order_request_params(self):
return self.order_request_params return self.order_request_params
@ -154,7 +152,10 @@ class select:
识别验证码 识别验证码
:return: :return:
""" """
self.randCode = self.login.getRandCode() while True:
if self.is_aotu_code:
self.randCode = self.login.getRandCode()
self.is_aotu_code = False
def getRepeatSubmitToken(self): def getRepeatSubmitToken(self):
""" """
@ -393,6 +394,8 @@ class select:
if 'data' in checkOrderInfo: if 'data' in checkOrderInfo:
if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo["data"]["ifShowPassCode"] == "Y": if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo["data"]["ifShowPassCode"] == "Y":
is_need_code = True is_need_code = True
t = threading.Thread(target=self.callRandCode())
t.start()
if self.getQueueCount(train_no, set_type, is_need_code): if self.getQueueCount(train_no, set_type, is_need_code):
return True return True
if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo['data']['submitStatus'] is True: if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo['data']['submitStatus'] is True:
@ -459,6 +462,21 @@ class select:
else: else:
print("未知错误 {0}".format("".join(getQueueCountResult))) 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): def checkQueueOrder(self, is_node_code=False):
""" """
模拟提交订单是确认按钮参数获取方法还是get_ticketInfoForPassengerForm 中获取 模拟提交订单是确认按钮参数获取方法还是get_ticketInfoForPassengerForm 中获取
@ -483,31 +501,31 @@ class select:
} }
try: try:
for i in range(3): if is_node_code:
if is_node_code: print("正在使用自动识别验证码功能")
while True:
print("正在使用自动识别验证码功能") if self.randCode:
checkRandCodeAnsyn = self.confUrl["checkRandCodeAnsyn"]["req_url"] checkcode = self.checkRandCodeAnsyn(self.randCode)
codeImgByOrder = self.confUrl["codeImgByOrder"]["req_url"] if checkcode == 'TRUE':
self.login.readImg(codeImgByOrder) print("验证码通过,正在提交订单")
randCode = self.login.getRandCode() data['randCode'] = self.randCode
randData = { self.randCode = ""
"randCode": randCode, break
"rand": "randp", else:
"_json_att": None, for i in range(3):
"REPEAT_SUBMIT_TOKEN": self.get_token() codeImgByOrder = self.confUrl["codeImgByOrder"]["req_url"]
} self.login.readImg(codeImgByOrder)
fresult = self.httpClint.send(checkRandCodeAnsyn, randData) # 校验验证码是否正确 randCode = self.login.getRandCode()
checkcode = fresult['data']['msg'] if checkcode == 'TRUE':
if checkcode == 'TRUE': print("验证码通过,正在提交订单")
print("验证码通过,正在提交订单") data['randCode'] = randCode
data['randCode'] = randCode break
break else:
else: print ("验证码有误, {0}次尝试重试".format(i+1))
print ("验证码有误, 接口返回{0}{1}次尝试重试".format(fresult, i)) print("验证码超过限定次数3次放弃此次订票机会!")
else: break
print("不需要验证码") else:
break print("不需要验证码")
checkQueueOrderResult = self.httpClint.send(checkQueueOrderUrl, data) checkQueueOrderResult = self.httpClint.send(checkQueueOrderUrl, data)
if "status" in checkQueueOrderResult and checkQueueOrderResult["status"]: if "status" in checkQueueOrderResult and checkQueueOrderResult["status"]:
c_data = checkQueueOrderResult["data"] if "data" in checkQueueOrderResult else {} c_data = checkQueueOrderResult["data"] if "data" in checkQueueOrderResult else {}

BIN
tkcode

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save