mirror of https://github.com/testerSunshine/12306
parent
829ec1163e
commit
0b3d04ace4
|
@ -183,5 +183,11 @@
|
||||||
- 注意:如果多日期查询的话,可能查询时间会比较长
|
- 注意:如果多日期查询的话,可能查询时间会比较长
|
||||||
- 增加如果排队时间超过一分钟,自动取消订单
|
- 增加如果排队时间超过一分钟,自动取消订单
|
||||||
|
|
||||||
|
- 2018.1.23更新
|
||||||
|
- 增加若快平台打码,yaml新增字段aotu_code_type,1=打码兔,2=若快 若快注册地址:http://www.ruokuai.com/client/index?6726
|
||||||
|
- 修改is_aotu_code字段为全部是否自动打码字段,也就是说字段为rue,则全部自动打码,为False全部手动打码,包括提交订单,注意centOs不可设置手动打码
|
||||||
|
- 修复bug
|
||||||
|
- 优化抢票功能
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#ticke_peoples: 乘客
|
#ticke_peoples: 乘客
|
||||||
#damatu:打码兔账号,用于自动登录
|
#damatu:打码兔账号,用于自动登录
|
||||||
#is_aotu_code是否自动打码,如果选择Ture,则调用打码兔打码,默认不使用打码兔
|
#is_aotu_code是否自动打码,如果选择Ture,则调用打码兔打码,默认不使用打码兔
|
||||||
|
#aotu_code_type 1为打码兔,2为若快
|
||||||
#is_email: 是否需要邮件通知 ex: True or False 切记,邮箱加完一定到config目录下测试emailConf功能是否正常
|
#is_email: 是否需要邮件通知 ex: True or False 切记,邮箱加完一定到config目录下测试emailConf功能是否正常
|
||||||
|
|
||||||
#邮箱配置 列举163
|
#邮箱配置 列举163
|
||||||
|
@ -41,10 +42,11 @@
|
||||||
set:
|
set:
|
||||||
station_dates:
|
station_dates:
|
||||||
- "2018-01-27"
|
- "2018-01-27"
|
||||||
# - "2018-02-04"
|
# - "2018-01-28"
|
||||||
# - "2018-02-05"
|
# - "2018-02-10"
|
||||||
|
# - "2018-02-09"
|
||||||
station_trains:
|
station_trains:
|
||||||
- "G1303"
|
- "G2365"
|
||||||
# - "K4300"
|
# - "K4300"
|
||||||
# - "K5226"
|
# - "K5226"
|
||||||
# - "K7772"
|
# - "K7772"
|
||||||
|
@ -55,7 +57,7 @@ set:
|
||||||
# - "G1363"
|
# - "G1363"
|
||||||
# - "G4933"
|
# - "G4933"
|
||||||
from_station: "上海"
|
from_station: "上海"
|
||||||
to_station: "广州"
|
to_station: "邵阳"
|
||||||
set_type:
|
set_type:
|
||||||
- "二等座"
|
- "二等座"
|
||||||
is_more_ticket: True
|
is_more_ticket: True
|
||||||
|
@ -72,11 +74,12 @@ select_refresh_interval: 0.1
|
||||||
expect_refresh_interval: 0.3
|
expect_refresh_interval: 0.3
|
||||||
ticket_black_list_time: 3
|
ticket_black_list_time: 3
|
||||||
is_aotu_code: False
|
is_aotu_code: False
|
||||||
|
aotu_code_type: 2
|
||||||
#enable_proxy: False
|
#enable_proxy: False
|
||||||
|
|
||||||
damatu:
|
damatu:
|
||||||
uesr: ""
|
uesr: ""
|
||||||
pwd: "wen1995"
|
pwd: "qazWSX1995"
|
||||||
|
|
||||||
email_conf:
|
email_conf:
|
||||||
is_email: False
|
is_email: False
|
||||||
|
|
|
@ -22,7 +22,7 @@ class DamatuApi():
|
||||||
KEY = 'ca9507e17e8d5ddf7c57cd18d8d33010'
|
KEY = 'ca9507e17e8d5ddf7c57cd18d8d33010'
|
||||||
HOST = 'http://api.dama2.com:7766/app/'
|
HOST = 'http://api.dama2.com:7766/app/'
|
||||||
|
|
||||||
def __init__(self, username, password, file_path):
|
def __init__(self, username, password, file_path=None):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.file_path = file_path
|
self.file_path = file_path
|
||||||
|
@ -108,13 +108,10 @@ class DamatuApi():
|
||||||
return jres['ret']
|
return jres['ret']
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
balance = self.getBalance()
|
|
||||||
if int(balance) > 40:
|
|
||||||
result = self.decode(287)
|
result = self.decode(287)
|
||||||
img_code = result.replace('|', ',') if not isinstance(result, int) else ""
|
img_code = result.replace('|', ',') if not isinstance(result, int) else ""
|
||||||
|
print("验证码识别坐标为{0}".format(img_code))
|
||||||
return img_code
|
return img_code
|
||||||
else:
|
|
||||||
raise balanceException('余额不足,当前余额为: {}'.format(balance))
|
|
||||||
|
|
||||||
# # 调用类型实例:
|
# # 调用类型实例:
|
||||||
# # 1.实例化类型 参数是打码兔用户账号和密码
|
# # 1.实例化类型 参数是打码兔用户账号和密码
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
# coding:utf-8
|
||||||
|
import requests
|
||||||
|
from hashlib import md5
|
||||||
|
|
||||||
|
|
||||||
|
class RClient(object):
|
||||||
|
|
||||||
|
def __init__(self, username, password):
|
||||||
|
self.username = username
|
||||||
|
self.password = md5(password).hexdigest()
|
||||||
|
self.soft_id = '96061'
|
||||||
|
self.soft_key = '6facb9da7bb645ad9c4a229464b2cf89'
|
||||||
|
self.base_params = {
|
||||||
|
'username': self.username,
|
||||||
|
'password': self.password,
|
||||||
|
'softid': self.soft_id,
|
||||||
|
'softkey': self.soft_key,
|
||||||
|
}
|
||||||
|
self.headers = {
|
||||||
|
'Connection': 'Keep-Alive',
|
||||||
|
'Expect': '100-continue',
|
||||||
|
'User-Agent': 'ben',
|
||||||
|
}
|
||||||
|
|
||||||
|
def rk_create(self, im, im_type, timeout=60):
|
||||||
|
"""
|
||||||
|
im: 图片字节
|
||||||
|
im_type: 题目类型
|
||||||
|
"""
|
||||||
|
params = {
|
||||||
|
'typeid': im_type,
|
||||||
|
'timeout': timeout,
|
||||||
|
}
|
||||||
|
params.update(self.base_params)
|
||||||
|
files = {'image': ('a.jpg', im)}
|
||||||
|
r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def rk_report_error(self, im_id):
|
||||||
|
"""
|
||||||
|
im_id:报错题目的ID
|
||||||
|
"""
|
||||||
|
params = {
|
||||||
|
'id': im_id,
|
||||||
|
}
|
||||||
|
params.update(self.base_params)
|
||||||
|
r = requests.post('http://api.ruokuai.com/reporterror.json', data=params, headers=self.headers)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
rc = RClient('931128603', 'qazWSX1995',)
|
||||||
|
im = open('tkcode', 'rb').read()
|
||||||
|
print rc.rk_create(im, 6113)
|
||||||
|
|
|
@ -9,15 +9,19 @@ from time import sleep
|
||||||
from config.ticketConf import _get_yaml
|
from config.ticketConf import _get_yaml
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from damatuCode.damatuWeb import DamatuApi
|
from damatuCode.damatuWeb import DamatuApi
|
||||||
|
from damatuCode.ruokuai import RClient
|
||||||
from myException.UserPasswordException import UserPasswordException
|
from myException.UserPasswordException import UserPasswordException
|
||||||
|
from myException.balanceException import balanceException
|
||||||
from myUrllib import myurllib2
|
from myUrllib import myurllib2
|
||||||
|
|
||||||
|
|
||||||
class GoLogin:
|
class GoLogin:
|
||||||
def __init__(self, httpClint, urlConf):
|
def __init__(self, httpClint, urlConf, is_aotu_code, aotu_code_type):
|
||||||
self.httpClint = httpClint
|
self.httpClint = httpClint
|
||||||
self.randCode = ""
|
self.randCode = ""
|
||||||
self.urlConf = urlConf
|
self.urlConf = urlConf
|
||||||
|
self.is_aotu_code = is_aotu_code
|
||||||
|
self.aotu_code_type = aotu_code_type
|
||||||
|
|
||||||
def cookietp(self):
|
def cookietp(self):
|
||||||
print("正在获取cookie")
|
print("正在获取cookie")
|
||||||
|
@ -28,7 +32,7 @@ class GoLogin:
|
||||||
# for index, c in enumerate(myurllib2.cookiejar):
|
# for index, c in enumerate(myurllib2.cookiejar):
|
||||||
# stoidinput(c)
|
# stoidinput(c)
|
||||||
|
|
||||||
def readImg(self):
|
def readImg(self, code_url):
|
||||||
"""
|
"""
|
||||||
增加手动打码,只是登录接口,完全不用担心提交订单效率
|
增加手动打码,只是登录接口,完全不用担心提交订单效率
|
||||||
思路
|
思路
|
||||||
|
@ -38,27 +42,38 @@ class GoLogin:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
print ("下载验证码...")
|
print ("下载验证码...")
|
||||||
codeimgUrl = self.urlConf["getCodeImg"]["req_url"]
|
codeimgUrl = code_url
|
||||||
img_path = './tkcode'
|
img_path = './tkcode'
|
||||||
result = self.httpClint.send(codeimgUrl)
|
result = self.httpClint.send(codeimgUrl)
|
||||||
try:
|
try:
|
||||||
open(img_path, 'wb').write(result)
|
open(img_path, 'wb').write(result)
|
||||||
if _get_yaml()["is_aotu_code"]:
|
if self.is_aotu_code:
|
||||||
self.randCode = DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"], img_path).main()
|
if self.aotu_code_type == 1:
|
||||||
|
return DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"], img_path).main()
|
||||||
|
elif self.aotu_code_type == 2:
|
||||||
|
rc = RClient(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"])
|
||||||
|
im = open('./tkcode', 'rb').read()
|
||||||
|
Result = rc.rk_create(im, 6113)
|
||||||
|
if "Result" in Result:
|
||||||
|
return self.codexy(Ofset=",".join(list(Result["Result"])), is_raw_input=False)
|
||||||
|
else:
|
||||||
|
if "Error" in Result and Result["Error"]:
|
||||||
|
print Result["Error"]
|
||||||
|
return ""
|
||||||
else:
|
else:
|
||||||
img = Image.open('./tkcode')
|
img = Image.open('./tkcode')
|
||||||
img.show()
|
img.show()
|
||||||
self.codexy()
|
return self.codexy()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print (e)
|
print (e)
|
||||||
pass
|
return ""
|
||||||
|
|
||||||
def codexy(self):
|
def codexy(self, Ofset=None, is_raw_input=True):
|
||||||
"""
|
"""
|
||||||
获取验证码
|
获取验证码
|
||||||
:return: str
|
:return: str
|
||||||
"""
|
"""
|
||||||
|
if is_raw_input:
|
||||||
Ofset = raw_input("请输入验证码: ")
|
Ofset = raw_input("请输入验证码: ")
|
||||||
select = Ofset.split(',')
|
select = Ofset.split(',')
|
||||||
post = []
|
post = []
|
||||||
|
@ -93,7 +108,9 @@ class GoLogin:
|
||||||
pass
|
pass
|
||||||
post.append(offsetsX)
|
post.append(offsetsX)
|
||||||
post.append(offsetsY)
|
post.append(offsetsY)
|
||||||
self.randCode = str(post).replace(']', '').replace('[', '').replace("'", '').replace(' ', '')
|
randCode = str(post).replace(']', '').replace('[', '').replace("'", '').replace(' ', '')
|
||||||
|
print("验证码识别坐标为{0}".format(randCode))
|
||||||
|
return randCode
|
||||||
|
|
||||||
def auth(self):
|
def auth(self):
|
||||||
"""认证"""
|
"""认证"""
|
||||||
|
@ -184,6 +201,10 @@ class GoLogin:
|
||||||
:param passwd: 密码
|
:param passwd: 密码
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if self.is_aotu_code and self.aotu_code_type == 1:
|
||||||
|
balance = DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"]).getBalance()
|
||||||
|
if int(balance) < 40:
|
||||||
|
raise balanceException('余额不足,当前余额为: {}'.format(balance))
|
||||||
user, passwd = _get_yaml()["set"]["12306count"][0]["uesr"], _get_yaml()["set"]["12306count"][1]["pwd"]
|
user, passwd = _get_yaml()["set"]["12306count"][0]["uesr"], _get_yaml()["set"]["12306count"][1]["pwd"]
|
||||||
if not user or not passwd:
|
if not user or not passwd:
|
||||||
raise UserPasswordException("温馨提示: 用户名或者密码为空,请仔细检查")
|
raise UserPasswordException("温馨提示: 用户名或者密码为空,请仔细检查")
|
||||||
|
@ -191,7 +212,7 @@ class GoLogin:
|
||||||
while True:
|
while True:
|
||||||
self.cookietp()
|
self.cookietp()
|
||||||
self.httpClint.set_cookies(_jc_save_wfdc_flag="dc", _jc_save_fromStation="%u4E0A%u6D77%u8679%u6865%2CAOH", _jc_save_toStation="%u5170%u5DDE%u897F%2CLAJ", _jc_save_fromDate="2018-02-14", _jc_save_toDate="2018-01-16", RAIL_DEVICEID="EN_3_EGSe2GWGHXJeCkFQ52kHvNCrNlkz9n1GOqqQ1wR0i98WsD8Gj-a3YHZ-XYKeESWgCiJyyucgSwkFOzVHhHqfpidLPcm2vK9n83uzOPuShO3Pl4lCydAtQu4BdFqz-RVmiduNFixrcrN_Ny43135JiEtqLaI")
|
self.httpClint.set_cookies(_jc_save_wfdc_flag="dc", _jc_save_fromStation="%u4E0A%u6D77%u8679%u6865%2CAOH", _jc_save_toStation="%u5170%u5DDE%u897F%2CLAJ", _jc_save_fromDate="2018-02-14", _jc_save_toDate="2018-01-16", RAIL_DEVICEID="EN_3_EGSe2GWGHXJeCkFQ52kHvNCrNlkz9n1GOqqQ1wR0i98WsD8Gj-a3YHZ-XYKeESWgCiJyyucgSwkFOzVHhHqfpidLPcm2vK9n83uzOPuShO3Pl4lCydAtQu4BdFqz-RVmiduNFixrcrN_Ny43135JiEtqLaI")
|
||||||
self.readImg()
|
self.randCode = self.readImg(self.urlConf["getCodeImg"]["req_url"])
|
||||||
login_num += 1
|
login_num += 1
|
||||||
self.auth()
|
self.auth()
|
||||||
if self.codeCheck():
|
if self.codeCheck():
|
||||||
|
|
|
@ -27,6 +27,8 @@ 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.expect_refresh_interval, 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 = {} # 订单提交时的参数
|
self.order_request_params = {} # 订单提交时的参数
|
||||||
self.ticketInfoForPassengerForm = {} # 初始化当前页面参数
|
self.ticketInfoForPassengerForm = {} # 初始化当前页面参数
|
||||||
self.current_seats = {} # 席别信息
|
self.current_seats = {} # 席别信息
|
||||||
|
@ -38,6 +40,7 @@ class select:
|
||||||
self.is_check_user = dict()
|
self.is_check_user = dict()
|
||||||
self.httpClint = HTTPClient()
|
self.httpClint = HTTPClient()
|
||||||
self.confUrl = urlConf.urls
|
self.confUrl = urlConf.urls
|
||||||
|
self.login = GoLogin(self.httpClint, self.confUrl, self.is_aotu_code, self.aotu_code_type)
|
||||||
|
|
||||||
def get_ticket_info(self):
|
def get_ticket_info(self):
|
||||||
"""
|
"""
|
||||||
|
@ -462,11 +465,7 @@ class select:
|
||||||
print("正在使用自动识别验证码功能")
|
print("正在使用自动识别验证码功能")
|
||||||
checkRandCodeAnsyn = self.confUrl["checkRandCodeAnsyn"]["req_url"]
|
checkRandCodeAnsyn = self.confUrl["checkRandCodeAnsyn"]["req_url"]
|
||||||
codeImgByOrder = self.confUrl["codeImgByOrder"]["req_url"]
|
codeImgByOrder = self.confUrl["codeImgByOrder"]["req_url"]
|
||||||
result = self.httpClint.send(codeImgByOrder)
|
randCode = self.login.readImg(codeImgByOrder)
|
||||||
img_path = './tkcode'
|
|
||||||
open(img_path, 'wb').write(result)
|
|
||||||
randCode = DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"],
|
|
||||||
img_path).main()
|
|
||||||
randData = {
|
randData = {
|
||||||
"randCode": randCode,
|
"randCode": randCode,
|
||||||
"rand": "randp",
|
"rand": "randp",
|
||||||
|
@ -623,16 +622,16 @@ class select:
|
||||||
登录回调方法
|
登录回调方法
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
login = GoLogin(self.httpClint, self.confUrl)
|
|
||||||
if auth:
|
if auth:
|
||||||
return login.auth()
|
return self.login.auth()
|
||||||
else:
|
else:
|
||||||
login.go_login()
|
self.login.go_login()
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
self.call_login()
|
self.call_login()
|
||||||
from_station, to_station = self.station_table(self.from_station, self.to_station)
|
from_station, to_station = self.station_table(self.from_station, self.to_station)
|
||||||
self.check_user()
|
self.check_user()
|
||||||
|
time.sleep(0.1)
|
||||||
num = 1
|
num = 1
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
|
@ -671,7 +670,7 @@ class select:
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print(e.message)
|
print(e.message)
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
print(e.message)
|
print("12306接口无响应,正在重试 {0}".format(e.message))
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
print(e.message)
|
print(e.message)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue