fix(tencent): 修复扫码成功判定——登录后停在 /platform 首页也视为成功;扫码/过期状态实时推给前端

This commit is contained in:
Qiufeng
2026-08-21 16:42:38 +08:00
parent cb785b2ce3
commit d34711062d
2 changed files with 38 additions and 17 deletions
+3
View File
@@ -764,6 +764,9 @@ def _qrcode_to_queue(status_queue):
if isinstance(payload, dict):
data_url = payload.get("image_data_url") or ""
image_path = payload.get("image_path") or ""
status_text = payload.get("status_text") or ""
if status_text:
status_queue.put(status_text)
if data_url:
status_queue.put(data_url)
elif image_path and os.path.exists(image_path):
+34 -16
View File
@@ -236,6 +236,38 @@ async def _save_tencent_qrcode(page: Page, account_file: str, previous_qrcode_pa
async def _is_tencent_login_completed(page: Page) -> bool:
# 仍在登录页(含扫码 iframe)=> 未登录
current_url = page.url or ""
if "login.html" in current_url:
return False
# 页面内还存在微信扫码登录 iframe => 未登录
try:
for fr in page.frames:
if "open.weixin.qq.com/connect/qrconnect" in (fr.url or ""):
return False
except Exception:
pass
# 页面内还存在登录二维码容器 => 未登录
login_markers = [
page.locator("div.login-qrcode-wrap").first,
page.locator("div.qrcode-wrap").first,
page.locator('span:has-text("微信扫码登录 视频号助手")').first,
]
for marker in login_markers:
try:
if await marker.count() and await marker.is_visible():
return False
except Exception:
continue
# 已离开登录页且登录框/二维码均消失 => 视为登录成功
# (视频号登录后通常停在 /platform 首页,不一定跳到 post/create 或 post/list)
if current_url.startswith(TENCENT_HOME_URL) or current_url.startswith(TENCENT_UPLOAD_URL) or current_url.startswith(TENCENT_MANAGE_URL):
return True
# 兜底:出现发布相关按钮也视为成功
publish_markers = [
page.locator('div:has-text("发表视频")').first,
page.locator('button:has-text("发表")').first,
@@ -248,24 +280,8 @@ async def _is_tencent_login_completed(page: Page) -> bool:
except Exception:
continue
if not (page.url.startswith(TENCENT_UPLOAD_URL) or page.url.startswith(TENCENT_MANAGE_URL)):
return False
login_markers = [
page.locator("div.login-qrcode-wrap").first,
page.locator("div.qrcode-wrap").first,
page.locator("img.qrcode").first,
page.locator('span:has-text("微信扫码登录 视频号助手")').first,
]
for marker in login_markers:
try:
if await marker.count() and await marker.is_visible():
return False
except Exception:
continue
return True
async def _is_tencent_qrcode_expired(page: Page) -> bool:
tip_selectors = [
@@ -360,9 +376,11 @@ async def _wait_for_tencent_login(
if not scanned_logged and await _is_tencent_qrcode_scanned(page):
tencent_logger.info(_msg("📱", "已经扫码啦,还差手机端确认一下"))
scanned_logged = True
await _emit_qrcode_callback(qrcode_callback, {"status_text": "已扫码,请在手机上确认登录"})
if await _is_tencent_qrcode_expired(page):
tencent_logger.warning(_msg("😵", "二维码失效了,小人马上去刷新"))
await _emit_qrcode_callback(qrcode_callback, {"status_text": "二维码已过期,正在刷新..."})
await _refresh_tencent_qrcode(page)
await asyncio.sleep(1)
try: