新增免费打码

This commit is contained in:
Jalin
2019-01-13 11:56:08 +08:00
parent 25049389ff
commit 70e2c0e736
7 changed files with 48 additions and 5 deletions

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'