Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
janlyn06
12306
提交
ccde9524
1
12306
项目概览
janlyn06
/
12306
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
1
12306
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ccde9524
编写于
4月 03, 2019
作者:
W
wenxianping
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复登录失效问题 #253
上级
8a39a175
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
182 addition
and
33 deletion
+182
-33
README.md
README.md
+3
-3
UnitTest/TestAll.py
UnitTest/TestAll.py
+1
-1
config/urlConf.py
config/urlConf.py
+66
-6
damatuCode/ruokuai.py
damatuCode/ruokuai.py
+19
-0
init/login.py
init/login.py
+50
-20
inter/GetPassCodeNewOrderAndLogin.py
inter/GetPassCodeNewOrderAndLogin.py
+38
-1
inter/GetRandCode.py
inter/GetRandCode.py
+2
-1
myUrllib/MySocketUtils.py
myUrllib/MySocketUtils.py
+1
-1
myUrllib/httpUtils.py
myUrllib/httpUtils.py
+2
-0
未找到文件。
README.md
浏览文件 @
ccde9524
...
...
@@ -7,9 +7,9 @@
#### 依赖库
-
依赖若快 若快注册地址:http://www.ruokuai.com/client/index?6726 推荐用若快,请注册个人账号
```
PS: 现在登录
可以不
不用验证码了,
PS: 现在登录
有一定几率
不用验证码了,
```
-
项目依赖包 requirements.txt
-
项目依赖包
查看
requirements.txt
-
安装方法-Windows:
-
安装方法-Linux:
-
root用户(避免多python环境产生问题): python2 -m pip install -i https://pypi.tuna.tsinghua.e -r requirements.txt
...
...
@@ -107,5 +107,5 @@
#### 如果觉得项目还不错,可以考虑打赏一波
-
!
[
image
](
https://github.com/testerSunshine/12306/blob/master/uml/wx.jpeg?imageMogr2/auto-orient/strip
)
!
[
image
](
https://github.com/testerSunshine/12306/blob/master/uml/zfb.jpeg?imageMogr2/auto-orient/strip
)
!
[
image
](
https://github.com/testerSunshine/12306/blob/master/uml/wx.jpeg?imageMogr2/auto-orient/strip
)
UnitTest/TestAll.py
浏览文件 @
ccde9524
...
...
@@ -45,7 +45,7 @@ class testAll(unittest.TestCase):
实测pushbear是否可用
:return:
"""
sendPushBear
(
"pushbear 微信通知测试一下"
)
sendPushBear
(
u
"pushbear 微信通知测试一下"
)
# def testConfig(self):
# """
...
...
config/urlConf.py
浏览文件 @
ccde9524
...
...
@@ -7,7 +7,19 @@ urls = {
"auth"
:
{
# 登录接口
"req_url"
:
"/passport/web/auth/uamtk"
,
"req_type"
:
"post"
,
"Referer"
:
"https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin"
,
"Referer"
:
"https://kyfw.12306.cn/otn/resources/login.html"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
"re_time"
:
1
,
"s_time"
:
0.1
,
"is_logger"
:
True
,
"is_json"
:
True
,
},
"uamtk-static"
:
{
# 登录接口
"req_url"
:
"/passport/web/auth/uamtk-static"
,
"req_type"
:
"get"
,
"Referer"
:
"https://kyfw.12306.cn/otn/resources/login.html"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
...
...
@@ -19,7 +31,7 @@ urls = {
"login"
:
{
# 登录接口
"req_url"
:
"/passport/web/login"
,
"req_type"
:
"post"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
login/init
"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
resources/login.html
"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
...
...
@@ -32,7 +44,7 @@ urls = {
"left_ticket_init"
:
{
# 登录接口
"req_url"
:
"/otn/leftTicket/init"
,
"req_type"
:
"post"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
login/init
"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
resources/login.html
"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
...
...
@@ -45,7 +57,7 @@ urls = {
"getCodeImg"
:
{
# 登录验证码
"req_url"
:
"/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand&{0}"
,
"req_type"
:
"get"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
login/init
"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
resources/login.html
"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
...
...
@@ -55,17 +67,42 @@ urls = {
"is_json"
:
False
,
"not_decode"
:
True
,
},
"getCodeImg1"
:
{
# 登录验证码
"req_url"
:
"/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand&{0}&callback=jQuery19108016482864806321_1554298927290&_=1554298927293"
,
"req_type"
:
"get"
,
"Referer"
:
"https://kyfw.12306.cn/otn/resources/login.html"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
"re_time"
:
1
,
"s_time"
:
0.1
,
"is_logger"
:
True
,
"is_json"
:
False
,
"not_decode"
:
True
,
},
"codeCheck"
:
{
# 验证码校验
"req_url"
:
"/passport/captcha/captcha-check"
,
"req_type"
:
"post"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
login/init
"
,
"Referer"
:
"https://kyfw.12306.cn/otn/
resources/login.html
"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
"re_time"
:
1
,
"s_time"
:
0.1
,
"is_logger"
:
True
,
"is_json"
:
True
,
"is_json"
:
False
,
},
"codeCheck1"
:
{
# 验证码校验
"req_url"
:
"/passport/captcha/captcha-check?callback=jQuery19108016482864806321_1554298927290&answer={0}&rand=sjrand&login_site=E&_={1}"
,
"req_type"
:
"get"
,
"Referer"
:
"https://kyfw.12306.cn/otn/resources/login.html"
,
"Host"
:
"kyfw.12306.cn"
,
"Content-Type"
:
1
,
"re_try"
:
10
,
"re_time"
:
1
,
"s_time"
:
0.1
,
"is_logger"
:
True
,
"is_json"
:
False
,
},
"loginInit"
:
{
# 登录页面
"req_url"
:
"/otn/login/init"
,
...
...
@@ -90,6 +127,29 @@ urls = {
"is_test_cdn"
:
True
,
"is_json"
:
False
,
},
"loginInitCdn1"
:
{
# 登录页面
"req_url"
:
"/otn/resources/login.html"
,
"req_type"
:
"get"
,
"Referer"
:
"https://kyfw.12306.cn/otn/view/index.html"
,
"Host"
:
"kyfw.12306.cn"
,
"re_try"
:
1
,
"re_time"
:
1
,
"s_time"
:
0.1
,
"is_logger"
:
False
,
"is_test_cdn"
:
False
,
"is_json"
:
False
,
},
"getDevicesId"
:
{
# 获取用户信息
"req_url"
:
"/otn/HttpZF/logdevice?algID=sV3XbAmeRg&hashCode=9JGmYn7tyQpz7ARsg5hs0afNuPy3NlZXSCye9VHEJII&FMQw=0&q4f3=zh-CN&VPIf=1&custID=133&VEek=unknown&dzuS=0&yD16=1&EOQP=1acda25d532249b0b1635671927a47e0&jp76=69f27b80c0ec8437d2a1f4278674e7fb&hAqN=MacIntel&platform=WEB&ks0Q=e848b8c6800147e416e6663782ca3789&TeRS=831x1440&tOHY=24xx900x1440&Fvje=i1l1o1s1&q5aJ=-8&wNLf=99115dfb07133750ba677d055874de87&0aew=Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_13_4)%20AppleWebKit/605.1.15%20(KHTML,%20like%20Gecko)%20Version/11.1%20Safari/605.1.15&E3gR=3492a53db5709ba4cade22e8fe879dc1×tamp=1554304524960"
,
"req_type"
:
"get"
,
"Referer"
:
"https://kyfw.12306.cn/otn/passport?redirect=/otn/"
,
"Host"
:
"kyfw.12306.cn"
,
"re_try"
:
10
,
"re_time"
:
1
,
"s_time"
:
0.01
,
"is_logger"
:
True
,
"is_json"
:
False
,
},
"getUserInfo"
:
{
# 获取用户信息
"req_url"
:
"/otn/index/initMy12306"
,
"req_type"
:
"get"
,
...
...
damatuCode/ruokuai.py
浏览文件 @
ccde9524
# coding:utf-8
import
base64
import
requests
from
hashlib
import
md5
...
...
@@ -40,6 +42,23 @@ class RClient(object):
print
(
r
)
return
r
.
json
()
def
rk_create_base64
(
self
,
im
,
im_type
,
timeout
=
60
):
"""
base64验证码识别
im: 图片字节
im_type: 题目类型
:return:
"""
params
=
{
'typeid'
:
im_type
,
'timeout'
:
timeout
,
'image'
:
im
,
}
params
.
update
(
self
.
base_params
)
r
=
requests
.
post
(
'http://api.ruokuai.com/create.json'
,
data
=
params
,
headers
=
self
.
headers
)
print
(
r
)
return
r
.
json
()
def
rk_report_error
(
self
,
im_id
):
"""
im_id:报错题目的ID
...
...
init/login.py
浏览文件 @
ccde9524
# -*- coding=utf-8 -*-
import
copy
import
random
import
time
from
collections
import
OrderedDict
from
time
import
sleep
from
config.ticketConf
import
_get_yaml
from
inter.GetPassCodeNewOrderAndLogin
import
getPassCodeNewOrderAndLogin
from
inter.GetPassCodeNewOrderAndLogin
import
getPassCodeNewOrderAndLogin
,
getPassCodeNewOrderAndLogin1
from
inter.GetRandCode
import
getRandCode
from
inter.LoginAysnSuggest
import
loginAysnSuggest
from
inter.LoginConf
import
loginConf
...
...
@@ -17,25 +21,41 @@ class GoLogin:
self
.
is_auto_code
=
is_auto_code
self
.
auto_code_type
=
auto_code_type
# def auth(self):
# """
# 认证
# :return:
# """
# authUrl = self.session.urls["auth"]
# authData = {"appid": "otn"}
# tk = self.session.httpClint.send(authUrl, authData)
# return tk
def
auth
(
self
):
"""认证"""
authUrl
=
self
.
session
.
urls
[
"auth"
]
authData
=
{
"appid"
:
"otn"
}
tk
=
self
.
session
.
httpClint
.
send
(
authUrl
,
authData
)
return
tk
"""
:return:
"""
self
.
session
.
httpClint
.
send
(
self
.
session
.
urls
[
"loginInitCdn1"
])
uamtkStaticUrl
=
self
.
session
.
urls
[
"uamtk-static"
]
uamtkStaticData
=
{
"appid"
:
"otn"
}
return
self
.
session
.
httpClint
.
send
(
uamtkStaticUrl
,
uamtkStaticData
)
def
codeCheck
(
self
):
"""
验证码校验
:return:
"""
codeCheck
=
self
.
session
.
urls
[
"codeCheck"
]
codeCheckData
=
{
"answer"
:
self
.
randCode
,
"rand"
:
"sjrand"
,
"login_site"
:
"E"
}
fresult
=
self
.
session
.
httpClint
.
send
(
codeCheck
,
codeCheckData
)
# codeCheck = self.session.urls["codeCheck"]
# codeCheckData = {
# "answer": self.randCode,
# "rand": "sjrand",
# "login_site": "E"
# }
# fresult = self.session.httpClint.send(codeCheck, codeCheckData)
codeCheckUrl
=
copy
.
deepcopy
(
self
.
session
.
urls
[
"codeCheck1"
])
codeCheckUrl
[
"req_url"
]
=
codeCheckUrl
[
"req_url"
].
format
(
self
.
randCode
,
int
(
time
.
time
()
*
1000
))
fresult
=
self
.
session
.
httpClint
.
send
(
codeCheckUrl
)
fresult
=
eval
(
fresult
.
split
(
"("
)[
1
].
split
(
")"
)[
0
])
if
"result_code"
in
fresult
and
fresult
[
"result_code"
]
==
"4"
:
print
(
u
"验证码通过,开始登录.."
)
return
True
...
...
@@ -53,12 +73,14 @@ class GoLogin:
:return: 权限校验码
"""
logurl
=
self
.
session
.
urls
[
"login"
]
logData
=
{
"username"
:
user
,
"password"
:
passwd
,
"appid"
:
"otn"
}
tresult
=
self
.
session
.
httpClint
.
send
(
logurl
,
logData
)
loginData
=
OrderedDict
()
loginData
[
"username"
]
=
user
,
loginData
[
"password"
]
=
passwd
,
loginData
[
"appid"
]
=
"otn"
,
loginData
[
"answer"
]
=
self
.
randCode
,
tresult
=
self
.
session
.
httpClint
.
send
(
logurl
,
loginData
)
if
'result_code'
in
tresult
and
tresult
[
"result_code"
]
==
0
:
print
(
u
"登录成功"
)
tk
=
self
.
auth
()
...
...
@@ -116,7 +138,15 @@ class GoLogin:
login_num
=
0
while
True
:
if
loginConf
(
self
.
session
):
result
=
getPassCodeNewOrderAndLogin
(
session
=
self
.
session
,
imgType
=
"login"
)
# result = getPassCodeNewOrderAndLogin(session=self.session, imgType="login")
self
.
auth
()
devicesIdRsp
=
self
.
session
.
httpClint
.
send
(
self
.
session
.
urls
.
get
(
"getDevicesId"
))
devicesId
=
eval
(
devicesIdRsp
.
split
(
"("
)[
1
].
split
(
")"
)[
0
].
replace
(
"'"
,
""
))[
"dfp"
]
if
devicesId
:
self
.
session
.
httpClint
.
set_cookies
(
RAIL_DEVICEID
=
devicesId
)
result
=
getPassCodeNewOrderAndLogin1
(
session
=
self
.
session
,
imgType
=
"login"
)
if
not
result
:
continue
self
.
randCode
=
getRandCode
(
self
.
is_auto_code
,
self
.
auto_code_type
,
result
)
...
...
inter/GetPassCodeNewOrderAndLogin.py
浏览文件 @
ccde9524
# coding=utf-8
import
copy
import
random
import
time
def
getPassCodeNewOrderAndLogin
(
session
,
imgType
):
...
...
@@ -35,3 +34,41 @@ def getPassCodeNewOrderAndLogin(session, imgType):
return
result
except
OSError
:
print
(
u
"验证码下载失败,可能ip被封,确认请手动请求: {0}"
.
format
(
codeImgUrl
))
def
getPassCodeNewOrderAndLogin1
(
session
,
imgType
):
"""
获取验证码2
:param session:
:param imgType:
:return:
"""
if
imgType
==
"login"
:
codeImgUrl
=
copy
.
deepcopy
(
session
.
urls
[
"getCodeImg1"
])
codeImgUrl
[
"req_url"
]
=
codeImgUrl
[
"req_url"
].
format
(
random
.
random
())
else
:
codeImgUrl
=
copy
.
deepcopy
(
session
.
urls
[
"codeImgByOrder"
])
codeImgUrl
[
"req_url"
]
=
codeImgUrl
[
"req_url"
].
format
(
random
.
random
())
print
(
u
"下载验证码..."
)
img_path
=
'./tkcode.png'
codeImgUrlRsp
=
session
.
httpClint
.
send
(
codeImgUrl
)
result
=
eval
(
codeImgUrlRsp
.
split
(
"("
)[
1
].
split
(
")"
)[
0
]).
get
(
"image"
)
try
:
if
isinstance
(
result
,
dict
):
print
(
u
"下载验证码失败, 请手动检查是否ip被封,或者重试,请求地址:https://kyfw.12306.cn{}"
.
format
(
codeImgUrl
.
get
(
"req_url"
)))
return
False
else
:
print
(
u
"下载验证码成功"
)
try
:
with
open
(
img_path
,
'wb'
,
encoding
=
"utf-8"
)
as
img
:
img
.
write
(
result
)
except
Exception
:
with
open
(
img_path
,
'wb'
)
as
img
:
img
.
write
(
result
)
return
result
except
OSError
:
print
(
u
"验证码下载失败,可能ip被封,确认请手动请求: {0}"
.
format
(
codeImgUrl
))
if
__name__
==
'__main__'
:
pass
inter/GetRandCode.py
浏览文件 @
ccde9524
...
...
@@ -23,7 +23,8 @@ def getRandCode(is_auto_code, auto_code_type, result):
if
auto_code_type
==
2
:
rc
=
RClient
(
_get_yaml
()[
"auto_code_account"
][
"user"
],
_get_yaml
()[
"auto_code_account"
][
"pwd"
])
# im = open('./tkcode', 'rb').read()
Result
=
rc
.
rk_create
(
result
,
6113
)
# Result = rc.rk_create(result, 6113)
Result
=
rc
.
rk_create_base64
(
result
,
6113
)
if
"Result"
in
Result
:
return
codexy
(
Ofset
=
","
.
join
(
list
(
Result
[
"Result"
])),
is_raw_input
=
False
)
else
:
...
...
myUrllib/MySocketUtils.py
浏览文件 @
ccde9524
...
...
@@ -22,7 +22,7 @@ import re
# "Content-Length: 9\r\n"\
# "Cookie: _passport_session=a459aba69761497eb31de76c27795e999613; _passport_ct=9116b2cb0bf443e1a01d22ac8c1ae449t5007; route=9036359bb8a8a461c164a04f8f50b252; BIGipServerpool_passport=200081930.50215.0000; BIGipServerotn=484704778.64545.0000\r\n\n"\
# "appid=otn\r\n"
# # s.sendall(get_str.format("https://kyfw.12306.cn/otn/
login/init
"))
# # s.sendall(get_str.format("https://kyfw.12306.cn/otn/
resources/login.html
"))
# s.sendall(post_str.format("https://kyfw.12306.cn/passport/web/auth/uamtk"))
from
config.urlConf
import
urls
...
...
myUrllib/httpUtils.py
浏览文件 @
ccde9524
...
...
@@ -16,6 +16,8 @@ def _set_header_default():
header_dict
[
"User-Agent"
]
=
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) 12306-electron/1.0.1 Chrome/59.0.3071.115 Electron/1.8.4 Safari/537.36"
header_dict
[
"Content-Type"
]
=
"application/x-www-form-urlencoded; charset=UTF-8"
header_dict
[
"Origin"
]
=
"https://kyfw.12306.cn"
header_dict
[
"Connection"
]
=
"keep-alive"
return
header_dict
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录