1、增加若快打码

2、优化提示语
3、修改若干bug
pull/23/head
wenxianping 2018-01-24 10:06:25 +08:00
parent 829ec1163e
commit 0b3d04ace4
7 changed files with 115 additions and 34 deletions

View File

@ -183,5 +183,11 @@
- 注意:如果多日期查询的话,可能查询时间会比较长
- 增加如果排队时间超过一分钟,自动取消订单
- 2018.1.23更新
- 增加若快平台打码yaml新增字段aotu_code_type1=打码兔2=若快 若快注册地址http://www.ruokuai.com/client/index?6726
- 修改is_aotu_code字段为全部是否自动打码字段也就是说字段为rue则全部自动打码为False全部手动打码包括提交订单注意centOs不可设置手动打码
- 修复bug
- 优化抢票功能

View File

@ -22,6 +22,7 @@
#ticke_peoples: 乘客
#damatu打码兔账号用于自动登录
#is_aotu_code是否自动打码如果选择Ture,则调用打码兔打码,默认不使用打码兔
#aotu_code_type 1为打码兔2为若快
#is_email: 是否需要邮件通知 ex: True or False 切记邮箱加完一定到config目录下测试emailConf功能是否正常
#邮箱配置 列举163
@ -41,10 +42,11 @@
set:
station_dates:
- "2018-01-27"
# - "2018-02-04"
# - "2018-02-05"
# - "2018-01-28"
# - "2018-02-10"
# - "2018-02-09"
station_trains:
- "G1303"
- "G2365"
# - "K4300"
# - "K5226"
# - "K7772"
@ -55,7 +57,7 @@ set:
# - "G1363"
# - "G4933"
from_station: "上海"
to_station: "广州"
to_station: "邵阳"
set_type:
- "二等座"
is_more_ticket: True
@ -72,11 +74,12 @@ select_refresh_interval: 0.1
expect_refresh_interval: 0.3
ticket_black_list_time: 3
is_aotu_code: False
aotu_code_type: 2
#enable_proxy: False
damatu:
uesr: ""
pwd: "wen1995"
pwd: "qazWSX1995"
email_conf:
is_email: False

View File

@ -22,7 +22,7 @@ class DamatuApi():
KEY = 'ca9507e17e8d5ddf7c57cd18d8d33010'
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.password = password
self.file_path = file_path
@ -108,13 +108,10 @@ class DamatuApi():
return jres['ret']
def main(self):
balance = self.getBalance()
if int(balance) > 40:
result = self.decode(287)
img_code = result.replace('|', ',') if not isinstance(result, int) else ""
return img_code
else:
raise balanceException('余额不足,当前余额为: {}'.format(balance))
result = self.decode(287)
img_code = result.replace('|', ',') if not isinstance(result, int) else ""
print("验证码识别坐标为{0}".format(img_code))
return img_code
# # 调用类型实例:
# # 1.实例化类型 参数是打码兔用户账号和密码

55
damatuCode/ruokuai.py Normal file
View File

@ -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)

View File

@ -9,15 +9,19 @@ from time import sleep
from config.ticketConf import _get_yaml
from PIL import Image
from damatuCode.damatuWeb import DamatuApi
from damatuCode.ruokuai import RClient
from myException.UserPasswordException import UserPasswordException
from myException.balanceException import balanceException
from myUrllib import myurllib2
class GoLogin:
def __init__(self, httpClint, urlConf):
def __init__(self, httpClint, urlConf, is_aotu_code, aotu_code_type):
self.httpClint = httpClint
self.randCode = ""
self.urlConf = urlConf
self.is_aotu_code = is_aotu_code
self.aotu_code_type = aotu_code_type
def cookietp(self):
print("正在获取cookie")
@ -28,7 +32,7 @@ class GoLogin:
# for index, c in enumerate(myurllib2.cookiejar):
# stoidinput(c)
def readImg(self):
def readImg(self, code_url):
"""
增加手动打码只是登录接口完全不用担心提交订单效率
思路
@ -38,28 +42,39 @@ class GoLogin:
:return:
"""
print ("下载验证码...")
codeimgUrl = self.urlConf["getCodeImg"]["req_url"]
codeimgUrl = code_url
img_path = './tkcode'
result = self.httpClint.send(codeimgUrl)
try:
open(img_path, 'wb').write(result)
if _get_yaml()["is_aotu_code"]:
self.randCode = DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"], img_path).main()
if self.is_aotu_code:
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:
img = Image.open('./tkcode')
img.show()
self.codexy()
return self.codexy()
except OSError as e:
print (e)
pass
return ""
def codexy(self):
def codexy(self, Ofset=None, is_raw_input=True):
"""
获取验证码
:return: str
"""
Ofset = raw_input("请输入验证码: ")
if is_raw_input:
Ofset = raw_input("请输入验证码: ")
select = Ofset.split(',')
post = []
offsetsX = 0 # 选择的答案的left值,通过浏览器点击8个小图的中点得到的,这样基本没问题
@ -93,7 +108,9 @@ class GoLogin:
pass
post.append(offsetsX)
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):
"""认证"""
@ -184,6 +201,10 @@ class GoLogin:
:param passwd: 密码
: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"]
if not user or not passwd:
raise UserPasswordException("温馨提示: 用户名或者密码为空,请仔细检查")
@ -191,7 +212,7 @@ class GoLogin:
while True:
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.readImg()
self.randCode = self.readImg(self.urlConf["getCodeImg"]["req_url"])
login_num += 1
self.auth()
if self.codeCheck():

View File

@ -27,6 +27,8 @@ 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.is_aotu_code = _get_yaml()["is_aotu_code"]
self.aotu_code_type = _get_yaml()["aotu_code_type"]
self.order_request_params = {} # 订单提交时的参数
self.ticketInfoForPassengerForm = {} # 初始化当前页面参数
self.current_seats = {} # 席别信息
@ -38,6 +40,7 @@ class select:
self.is_check_user = dict()
self.httpClint = HTTPClient()
self.confUrl = urlConf.urls
self.login = GoLogin(self.httpClint, self.confUrl, self.is_aotu_code, self.aotu_code_type)
def get_ticket_info(self):
"""
@ -462,11 +465,7 @@ class select:
print("正在使用自动识别验证码功能")
checkRandCodeAnsyn = self.confUrl["checkRandCodeAnsyn"]["req_url"]
codeImgByOrder = self.confUrl["codeImgByOrder"]["req_url"]
result = self.httpClint.send(codeImgByOrder)
img_path = './tkcode'
open(img_path, 'wb').write(result)
randCode = DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"],
img_path).main()
randCode = self.login.readImg(codeImgByOrder)
randData = {
"randCode": randCode,
"rand": "randp",
@ -623,16 +622,16 @@ class select:
登录回调方法
:return:
"""
login = GoLogin(self.httpClint, self.confUrl)
if auth:
return login.auth()
return self.login.auth()
else:
login.go_login()
self.login.go_login()
def main(self):
self.call_login()
from_station, to_station = self.station_table(self.from_station, self.to_station)
self.check_user()
time.sleep(0.1)
num = 1
while 1:
try:
@ -671,7 +670,7 @@ class select:
except KeyError as e:
print(e.message)
except TypeError as e:
print(e.message)
print("12306接口无响应正在重试 {0}".format(e.message))
except socket.error as e:
print(e.message)

BIN
tkcode

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 14 KiB