新增免费打码

This commit is contained in:
Jalin
2019-01-13 11:56:08 +08:00
parent 751c01298f
commit 047024d239
7 changed files with 48 additions and 5 deletions

View File

@@ -17,6 +17,7 @@
- [x] 动态修改配置文件
- [x] 邮件通知
- [ ] Web 管理页面
- [ ] 微信消息通知
## 使用
py12306 需要运行在 python 3.6 以上版本(其它版本暂未测试)
@@ -34,7 +35,9 @@ cp env.py.example env.py
```
自动打码
打码依赖于若快平台,需要先到 [http://www.ruokuai.com](http://www.ruokuai.com/login) 注册一个账号后填写到配置中
目前支持免费打码,和若快打码
注:免费打码无法保证持续可用,如失效请手动切换到若快平台,需要先到 [http://www.ruokuai.com](http://www.ruokuai.com/login) 注册一个账号后填写到配置中
语音通知
@@ -102,6 +105,8 @@ docker run -d -v $(pwd):/config -v py12306:/data pjialin/py12306
* 支持分布式集群
### 19-01-11
* 配置文件支持动态修改
### 19-01-12
* 新增免费打码
## 下单成功截图
![下单成功图片](./data/images/order_success.png)

View File

@@ -27,7 +27,8 @@ USER_HEARTBEAT_INTERVAL = 120
QUERY_JOB_THREAD_ENABLED = 0 # 是否开启多线程查询,开启后第个任务会单独分配线程处理
# 打码平台账号
# 目前只支持若快打码注册地址http://www.ruokuai.com/login
# 目前只支持免费打码接口 和 若快打码注册地址http://www.ruokuai.com/login
AUTO_CODE_PLATFORM = 'free' # 免费填写 free 若快 ruokuai # 免费打码无法保证持续可用,如失效请手动切换
AUTO_CODE_ACCOUNT = {
'user': 'your user name',
'pwd': 'your password'

View File

@@ -27,8 +27,9 @@ USER_HEARTBEAT_INTERVAL = 120
QUERY_JOB_THREAD_ENABLED = 0 # 是否开启多线程查询,开启后第个任务会单独分配线程处理
# 打码平台账号
# 目前只支持若快打码注册地址http://www.ruokuai.com/login
AUTO_CODE_ACCOUNT = {
# 目前只支持免费打码接口 和 若快打码注册地址http://www.ruokuai.com/login
AUTO_CODE_PLATFORM = 'free' # 免费填写 free 若快 ruokuai # 免费打码无法保证持续可用,如失效请手动切换
AUTO_CODE_ACCOUNT = { # 使用 free 可用省略
'user': 'your user name',
'pwd': 'your password'
}
@@ -64,7 +65,7 @@ EMAIL_SERVER_PASSWORD = ''
# Web 管理
WEB_ENABLE = 1 # 是否打开 Web 管理
WEB_USER = { # 登录信息
WEB_USER = { # 登录信息
'username': 'admin',
'password': 'password'
}

View File

@@ -64,6 +64,7 @@ class App:
signal.signal(sign, self.handler_exit)
pass
def handler_exit(self, *args, **kwargs):
"""
程序退出
@@ -79,6 +80,7 @@ class App:
@classmethod
def check_auto_code(cls):
if Config().AUTO_CODE_PLATFORM == 'free': return True
if not Config().AUTO_CODE_ACCOUNT.get('user') or not Config().AUTO_CODE_ACCOUNT.get('pwd'):
return False
return True

View File

@@ -20,6 +20,7 @@ class Config:
# 多线程查询
QUERY_JOB_THREAD_ENABLED = 0
# 打码平台账号
AUTO_CODE_PLATFORM = ''
AUTO_CODE_ACCOUNT = {'user': '', 'pwd': ''}
# 输出日志到文件
OUT_PUT_LOG_TO_FILE_ENABLED = 0

View File

@@ -2,6 +2,8 @@ import math
import random
from py12306.config import Config
from py12306.helpers.api import *
from py12306.helpers.request import Request
from py12306.log.common_log import CommonLog
from py12306.vender.ruokuai.main import RKClient
@@ -10,6 +12,10 @@ class OCR:
"""
图片识别
"""
session = None
def __init__(self):
self.session = Request()
@classmethod
def get_img_position(cls, img):
@@ -19,6 +25,8 @@ class OCR:
:return:
"""
self = cls()
if Config().AUTO_CODE_PLATFORM == 'free':
return self.get_image_by_free_site(img)
return self.get_img_position_by_ruokuai(img)
def get_img_position_by_ruokuai(self, img):
@@ -46,6 +54,28 @@ class OCR:
positions.append(int(y))
return positions
def get_image_by_free_site(self, img):
data = {
'base64': img
}
response = self.session.post(API_FREE_CODE_QCR_API, json=data)
result = response.json()
if result.get('success') and result.get('check'):
check_data = {
'check': result.get('check'),
'img_buf': img,
'logon': 1,
'type': 'D'
}
check_response = self.session.post(API_FREE_CODE_QCR_API_CHECK, json=check_data)
check_result = check_response.json()
if check_result.get('res'):
position = check_result.get('res')
return position.replace('(', '').replace(')', '').split(',')
CommonLog.print_auto_code_fail(result.get("Error", '-'))
return None
if __name__ == '__main__':
pass

View File

@@ -44,3 +44,6 @@ API_QUERY_ORDER_WAIT_TIME = BASE_URL_OF_12306 + '/otn/confirmPassenger/queryOrde
API_NOTIFICATION_BY_VOICE_CODE = 'http://ali-voice.showapi.com/sendVoice?'
API_FREE_CODE_QCR_API = 'http://60.205.200.159/api'
API_FREE_CODE_QCR_API_CHECK = 'http://check.huochepiao.360.cn/img_vcode'