This commit is contained in:
2026-01-20 21:09:54 +08:00
parent a7835170f7
commit 6559e4b84a
4 changed files with 64 additions and 34 deletions

View File

@@ -34,6 +34,12 @@ from s2a_service import (
)
from logger import log
# 进度更新 (Telegram Bot 使用)
try:
from bot_notifier import progress_update
except ImportError:
def progress_update(account=None, phase=None, step=None, role=None): pass
# ==================== 停止检查 ====================
class ShutdownRequested(Exception):
@@ -1106,6 +1112,7 @@ def register_openai_account(page, email: str, password: str) -> bool:
# 步骤1: 输入邮箱 (在 log-in-or-create-account 页面)
if "auth.openai.com/log-in-or-create-account" in current_url:
progress_update(phase="注册", step="输入邮箱...")
log.step("等待邮箱输入框...")
email_input = wait_for_element(page, 'css:input[type="email"]', timeout=15)
if not email_input:
@@ -1129,6 +1136,7 @@ def register_openai_account(page, email: str, password: str) -> bool:
# 步骤2: 输入密码 (在密码页面: log-in/password 或 create-account/password)
if "auth.openai.com/log-in/password" in current_url or "auth.openai.com/create-account/password" in current_url:
progress_update(phase="注册", step="输入密码...")
# 先检查是否有密码错误提示,如果有则使用一次性验证码登录
try:
error_text = page.ele('text:Incorrect email address or password', timeout=1)
@@ -1229,6 +1237,7 @@ def register_openai_account(page, email: str, password: str) -> bool:
# 检测到姓名/年龄输入页面 (账号已存在,只需补充信息)
if "auth.openai.com/about-you" in current_url:
progress_update(phase="注册", step="补充个人信息...")
log_current_url(page, "个人信息页面")
log.info("检测到姓名输入页面,账号已存在,补充信息...")
@@ -1282,6 +1291,7 @@ def register_openai_account(page, email: str, password: str) -> bool:
return False
# 获取验证码
progress_update(phase="注册", step="等待验证码...")
log.step("等待验证码邮件...")
verification_code, error, email_time = unified_get_verification_code(email)
@@ -1296,6 +1306,7 @@ def register_openai_account(page, email: str, password: str) -> bool:
max_code_retries = 3
for code_attempt in range(max_code_retries):
# 输入验证码
progress_update(phase="注册", step="输入验证码...")
log.step(f"输入验证码: {verification_code}")
while check_and_handle_error(page):
time.sleep(1)
@@ -2473,6 +2484,7 @@ def perform_s2a_authorization(page, email: str, password: str) -> bool:
bool: 授权是否成功
"""
log.info(f"开始 S2A 授权: {email}", icon="code")
progress_update(phase="授权", step="开始 S2A 授权...")
# 生成授权 URL
auth_url, session_id = s2a_generate_auth_url()
@@ -2481,6 +2493,7 @@ def perform_s2a_authorization(page, email: str, password: str) -> bool:
return False
# 打开授权页面
progress_update(phase="授权", step="打开授权页面...")
log.step("打开 S2A 授权页面...")
log.info(f"[URL] S2A授权URL: {auth_url}", icon="browser")
page.get(auth_url)
@@ -2492,6 +2505,7 @@ def perform_s2a_authorization(page, email: str, password: str) -> bool:
try:
# 输入邮箱
progress_update(phase="授权", step="输入邮箱...")
log.step("输入邮箱...")
email_input = wait_for_element(page, 'css:input[type="email"]', timeout=10)
if not email_input:
@@ -2516,6 +2530,7 @@ def perform_s2a_authorization(page, email: str, password: str) -> bool:
current_url = page.url
if "/password" in current_url:
try:
progress_update(phase="授权", step="输入密码...")
log.step("输入密码...")
password_input = wait_for_element(page, 'css:input[type="password"]', timeout=10)
@@ -2540,6 +2555,7 @@ def perform_s2a_authorization(page, email: str, password: str) -> bool:
callback_url = None
progress_shown = False
last_url_in_loop = None
progress_update(phase="授权", step="等待回调...")
log.step(f"等待 S2A 授权回调 (最多 {max_wait}s)...")
while time.time() - start_time < max_wait:
@@ -2604,6 +2620,7 @@ def perform_s2a_authorization(page, email: str, password: str) -> bool:
return False
# S2A 特有流程: 用授权码创建账号 (传入完整邮箱用于验证)
progress_update(phase="授权", step="提交授权码...")
log.step("正在提交 S2A 授权码...")
result = s2a_create_account_from_oauth(code, session_id, name=email)
if result: