Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
doudian-py
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiquan
doudian-py
Commits
6001cdb3
Commit
6001cdb3
authored
Aug 29, 2025
by
baiquan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(login): 重构登录验证逻辑
- 优化 is_logged_in 函数,通过监听网络请求判断登录状态 - 修改登录流程,确保仅在登录成功后设置认证令牌
parent
b669d184
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
service/page_login.py
+14
-7
No files found.
service/page_login.py
View file @
6001cdb3
...
@@ -30,11 +30,18 @@ def click_button(tab, loc, retry_limit=5, delay=2):
...
@@ -30,11 +30,18 @@ def click_button(tab, loc, retry_limit=5, delay=2):
def
is_logged_in
(
tab
):
def
is_logged_in
(
tab
):
"""检查是否已登录的多种方式"""
"""检查是否已登录的多种方式"""
if
tab
.
title
==
"首页"
:
check_result
=
False
logger
.
info
(
"已处于登录状态"
)
for
packet
in
tab
.
listen
.
steps
(
timeout
=
5
):
return
True
if
'/aff/check_login'
in
packet
.
url
and
packet
.
response
.
body
:
cookies
=
tab
.
cookies
()
.
as_dict
()
login_res
=
packet
.
response
.
body
return
bool
(
cookies
.
get
(
'PHPSESSID'
))
logger
.
info
(
f
'获取确认登录数据:{login_res}'
)
if
(
login_res
[
'deputy_has_login'
]
and
login_res
[
'subject_has_login'
]
and
login_res
[
'error_code'
]
==
0
and
login_res
.
get
(
'sec_subject_uid'
)
and
login_res
.
get
(
'sec_user_id'
)):
check_result
=
True
if
check_result
:
if
tab
.
title
!=
"首页"
:
return
False
return
check_result
def
set_auth_token
(
tab
):
def
set_auth_token
(
tab
):
...
@@ -143,7 +150,7 @@ async def page_login(browser_id, max_retries=3):
...
@@ -143,7 +150,7 @@ async def page_login(browser_id, max_retries=3):
co
=
ChromiumOptions
()
.
set_local_port
(
port
)
co
=
ChromiumOptions
()
.
set_local_port
(
port
)
browser
=
Chromium
(
co
)
browser
=
Chromium
(
co
)
tab
=
browser
.
latest_tab
tab
=
browser
.
latest_tab
tab
.
set
.
cookies
.
clear
()
#
tab.set.cookies.clear()
tab
.
set
.
load_mode
.
eager
()
tab
.
set
.
load_mode
.
eager
()
tab
.
listen
.
start
([
"account_login/v2/"
,
"captcha/verify"
,
"/aff/check_login"
,
"/loginv1/callback"
])
tab
.
listen
.
start
([
"account_login/v2/"
,
"captcha/verify"
,
"/aff/check_login"
,
"/loginv1/callback"
])
# 访问登录页
# 访问登录页
...
@@ -187,7 +194,7 @@ async def page_login(browser_id, max_retries=3):
...
@@ -187,7 +194,7 @@ async def page_login(browser_id, max_retries=3):
# 验证登录结果
# 验证登录结果
for
_
in
range
(
20
):
# 最多等待30秒
for
_
in
range
(
20
):
# 最多等待30秒
logger
.
debug
(
f
"等待登录结果..."
)
logger
.
debug
(
f
"等待登录结果..."
)
if
is_logged_in
(
tab
)
and
set_auth_token
(
tab
):
if
tab
.
title
==
"首页"
and
set_auth_token
(
tab
):
cookies
=
tab
.
cookies
()
.
as_dict
()
cookies
=
tab
.
cookies
()
.
as_dict
()
PHPSESSID
=
cookies
.
get
(
'PHPSESSID'
,
''
)
PHPSESSID
=
cookies
.
get
(
'PHPSESSID'
,
''
)
return
PHPSESSID
return
PHPSESSID
...
...
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