Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
py12306
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
python
py12306
Commits
da469f3e
Commit
da469f3e
authored
Jan 10, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改验证码为 image64 方式
parent
247c46db
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
17 deletions
+20
-17
README.md
README.md
+0
-1
OCR.py
py12306/helpers/OCR.py
+4
-5
api.py
py12306/helpers/api.py
+1
-0
auth_code.py
py12306/helpers/auth_code.py
+11
-7
main.py
py12306/vender/ruokuai/main.py
+4
-4
No files found.
README.md
View file @
da469f3e
...
...
@@ -83,7 +83,6 @@ python main.py
## Docker 使用
!!发现请求会有问题,正在调试中 01-10 18:54
**1. 将配置文件下载到本地**
*
```
bash
docker run
--rm
pjialin/py12306
cat
/config/env.py
>
env.py
...
...
py12306/helpers/OCR.py
View file @
da469f3e
...
...
@@ -12,22 +12,21 @@ class OCR:
"""
@
classmethod
def
get_img_position
(
cls
,
img
_path
):
def
get_img_position
(
cls
,
img
):
"""
获取图像坐标
:param img_path:
:return:
"""
self
=
cls
()
return
self
.
get_img_position_by_ruokuai
(
img
_path
)
return
self
.
get_img_position_by_ruokuai
(
img
)
def
get_img_position_by_ruokuai
(
self
,
img
_path
):
def
get_img_position_by_ruokuai
(
self
,
img
):
ruokuai_account
=
Config
()
.
AUTO_CODE_ACCOUNT
soft_id
=
'119671'
soft_key
=
'6839cbaca1f942f58d2760baba5ed987'
rc
=
RKClient
(
ruokuai_account
.
get
(
'user'
),
ruokuai_account
.
get
(
'pwd'
),
soft_id
,
soft_key
)
im
=
open
(
img_path
,
'rb'
)
.
read
()
result
=
rc
.
rk_create
(
im
,
6113
)
result
=
rc
.
rk_create
(
img
,
6113
)
if
"Result"
in
result
:
return
self
.
get_image_position_by_offset
(
list
(
result
[
'Result'
]))
CommonLog
.
print_auto_code_fail
(
result
.
get
(
"Error"
,
'-'
))
...
...
py12306/helpers/api.py
View file @
da469f3e
...
...
@@ -20,6 +20,7 @@ API_USER_CHECK = {
API_AUTH_CODE_DOWNLOAD
=
{
'url'
:
BASE_URL_OF_12306
+
'/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand&_={random}'
}
API_AUTH_CODE_BASE64_DOWNLOAD
=
BASE_URL_OF_12306
+
'/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand&_={random}'
API_AUTH_CODE_CHECK
=
{
'url'
:
BASE_URL_OF_12306
+
'/passport/captcha/captcha-check?answer={answer}&rand=sjrand&login_site=E&_={random}'
}
...
...
py12306/helpers/auth_code.py
View file @
da469f3e
...
...
@@ -5,7 +5,7 @@ from requests.exceptions import SSLError
from
py12306.config
import
Config
from
py12306.helpers.OCR
import
OCR
from
py12306.helpers.api
import
API_AUTH_CODE_DOWNLOAD
,
API_AUTH_CODE_CHECK
from
py12306.helpers.api
import
*
from
py12306.helpers.request
import
Request
from
py12306.helpers.func
import
*
from
py12306.log.common_log
import
CommonLog
...
...
@@ -27,8 +27,8 @@ class AuthCode:
@
classmethod
def
get_auth_code
(
cls
,
session
):
self
=
cls
(
session
)
img
_path
=
self
.
download_code
()
position
=
OCR
.
get_img_position
(
img
_path
)
img
=
self
.
download_code
()
position
=
OCR
.
get_img_position
(
img
)
if
not
position
:
# 打码失败
return
self
.
retry_get_auth_code
()
...
...
@@ -43,17 +43,21 @@ class AuthCode:
return
self
.
get_auth_code
(
self
.
session
)
def
download_code
(
self
):
url
=
API_AUTH_CODE_
DOWNLOAD
.
get
(
'url'
)
.
format
(
random
=
random
.
random
())
code_path
=
self
.
data_path
+
'code.png'
url
=
API_AUTH_CODE_
BASE64_DOWNLOAD
.
format
(
random
=
random
.
random
())
#
code_path = self.data_path + 'code.png'
try
:
UserLog
.
add_quick_log
(
UserLog
.
MESSAGE_DOWNLAODING_THE_CODE
)
.
flush
()
response
=
self
.
session
.
save_to_file
(
url
,
code_path
)
# TODO 返回错误情况
# response = self.session.save_to_file(url, code_path) # TODO 返回错误情况
response
=
self
.
session
.
get
(
url
)
result
=
response
.
json
()
if
result
.
get
(
'image'
):
return
result
.
get
(
'image'
)
raise
SSLError
except
SSLError
as
e
:
UserLog
.
add_quick_log
(
UserLog
.
MESSAGE_DOWNLAOD_AUTH_CODE_FAIL
.
format
(
e
,
self
.
retry_time
))
.
flush
()
time
.
sleep
(
self
.
retry_time
)
return
self
.
download_code
()
return
code_path
def
check_code
(
self
,
answer
):
"""
...
...
py12306/vender/ruokuai/main.py
View file @
da469f3e
...
...
@@ -21,7 +21,7 @@ class RKClient(object):
'User-Agent'
:
'ben'
,
}
def
rk_create
(
self
,
im
,
im_type
,
timeout
=
6
0
):
def
rk_create
(
self
,
im
age
,
im_type
,
timeout
=
2
0
):
"""
im: 图片字节
im_type: 题目类型
...
...
@@ -29,10 +29,10 @@ class RKClient(object):
params
=
{
'typeid'
:
im_type
,
'timeout'
:
timeout
,
'image'
:
image
}
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
)
r
=
requests
.
post
(
'http://api.ruokuai.com/create.json'
,
data
=
params
,
timeout
=
timeout
)
return
r
.
json
()
def
rk_report_error
(
self
,
im_id
):
...
...
@@ -49,6 +49,6 @@ class RKClient(object):
if
__name__
==
'__main__'
:
rc
=
RKClient
(
'username'
,
'password'
,
'soft_id'
,
'soft_key'
)
im
=
open
(
'a.jpg'
,
'rb'
)
.
read
()
#
im = open('a.jpg', 'rb').read()
# print rc.rk_create(im, 3040)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment