Skip to content

Commit

Permalink
新增免费打码
Browse files Browse the repository at this point in the history
  • Loading branch information
pjialin committed Jan 13, 2019
1 parent 2504938 commit 70e2c0e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [x] 动态修改配置文件
- [x] 邮件通知
- [ ] Web 管理页面
- [ ] 微信消息通知

## 使用
py12306 需要运行在 python 3.6 以上版本(其它版本暂未测试)
Expand All @@ -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) 注册一个账号后填写到配置中

语音通知

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion env.docker.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions env.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -64,7 +65,7 @@ EMAIL_SERVER_PASSWORD = ''

# Web 管理
WEB_ENABLE = 1 # 是否打开 Web 管理
WEB_USER = { # 登录信息
WEB_USER = { # 登录信息
'username': 'admin',
'password': 'password'
}
Expand Down
2 changes: 2 additions & 0 deletions py12306/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def register_sign(self):
signal.signal(sign, self.handler_exit)

pass

def handler_exit(self, *args, **kwargs):
"""
程序退出
Expand All @@ -79,6 +80,7 @@ def handler_exit(self, *args, **kwargs):

@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
Expand Down
1 change: 1 addition & 0 deletions py12306/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions py12306/helpers/OCR.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
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

Expand All @@ -10,6 +12,10 @@ class OCR:
"""
图片识别
"""
session = None

def __init__(self):
self.session = Request()

@classmethod
def get_img_position(cls, img):
Expand All @@ -19,6 +25,8 @@ def get_img_position(cls, img):
: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):
Expand Down Expand Up @@ -46,6 +54,28 @@ def get_image_position_by_offset(self, offsets):
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
Expand Down
3 changes: 3 additions & 0 deletions py12306/helpers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@

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'

0 comments on commit 70e2c0e

Please sign in to comment.