u
This commit is contained in:
@@ -1189,6 +1189,7 @@ def run_main_process():
|
|||||||
try:
|
try:
|
||||||
name_input = page.ele('@name=name', timeout=20)
|
name_input = page.ele('@name=name', timeout=20)
|
||||||
name_input.input(real_name)
|
name_input.input(real_name)
|
||||||
|
log_progress(f"姓名: {real_name}")
|
||||||
|
|
||||||
# 使用 Tab 键切换到生日字段
|
# 使用 Tab 键切换到生日字段
|
||||||
page.actions.key_down('Tab').key_up('Tab')
|
page.actions.key_down('Tab').key_up('Tab')
|
||||||
@@ -1211,21 +1212,40 @@ def run_main_process():
|
|||||||
# =======================================================
|
# =======================================================
|
||||||
log_status("订阅", "等待进入 ChatGPT 主页...")
|
log_status("订阅", "等待进入 ChatGPT 主页...")
|
||||||
|
|
||||||
# 等待 URL 变成 chatgpt.com(不含 auth 路径)
|
# 等待页面跳转完成
|
||||||
for _ in range(30):
|
time.sleep(5)
|
||||||
|
|
||||||
|
entered_main = False
|
||||||
|
for i in range(30):
|
||||||
current_url = page.url
|
current_url = page.url
|
||||||
if 'chatgpt.com' in current_url and 'auth' not in current_url and 'login' not in current_url:
|
# 更宽松的判断:只要不在 auth/login 页面就认为进入了主页
|
||||||
log_progress(f"✓ 已进入主页: {current_url[:50]}...")
|
if 'chatgpt.com' in current_url:
|
||||||
|
if '/auth' not in current_url and '/login' not in current_url and 'auth0' not in current_url:
|
||||||
|
log_progress(f"✓ 已进入主页: {current_url[:60]}...")
|
||||||
|
entered_main = True
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
if i % 10 == 0 and i > 0:
|
||||||
|
log_progress(f"等待中... ({i}秒)")
|
||||||
|
|
||||||
|
if not entered_main:
|
||||||
log_progress("⚠ 等待主页超时,尝试继续...")
|
log_progress("⚠ 等待主页超时,尝试继续...")
|
||||||
|
# 尝试直接访问主页
|
||||||
|
page.get("https://chatgpt.com/")
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
# 额外等待页面稳定
|
# 额外等待页面稳定
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
log_status("订阅", "执行 JS 跳转到支付页...")
|
log_status("订阅", "执行 JS 跳转到支付页...")
|
||||||
|
|
||||||
|
# 先检查是否已登录
|
||||||
|
try:
|
||||||
|
session_check = page.run_js('return fetch("/api/auth/session").then(r => r.json())')
|
||||||
|
time.sleep(1)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# 直接执行 JS 跳转到支付页
|
# 直接执行 JS 跳转到支付页
|
||||||
checkout_js = '''
|
checkout_js = '''
|
||||||
(async function(){
|
(async function(){
|
||||||
@@ -1274,6 +1294,9 @@ def run_main_process():
|
|||||||
result = page.run_js(checkout_js)
|
result = page.run_js(checkout_js)
|
||||||
log_progress(f"JS 执行结果: {result}")
|
log_progress(f"JS 执行结果: {result}")
|
||||||
|
|
||||||
|
# 等待 JS 执行完成
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
# 等待跳转到支付页(使用 URL 检测代替固定等待)
|
# 等待跳转到支付页(使用 URL 检测代替固定等待)
|
||||||
try:
|
try:
|
||||||
page.wait.url_change('pay.openai.com', timeout=15)
|
page.wait.url_change('pay.openai.com', timeout=15)
|
||||||
@@ -1471,6 +1494,7 @@ def run_single_registration(progress_callback=None, step_callback=None) -> dict:
|
|||||||
log_status("步骤 4/5", "进入信息填写页...")
|
log_status("步骤 4/5", "进入信息填写页...")
|
||||||
name_input = page.ele('@name=name', timeout=20)
|
name_input = page.ele('@name=name', timeout=20)
|
||||||
name_input.input(real_name)
|
name_input.input(real_name)
|
||||||
|
log_progress(f"姓名: {real_name}")
|
||||||
page.actions.key_down('Tab').key_up('Tab')
|
page.actions.key_down('Tab').key_up('Tab')
|
||||||
|
|
||||||
birth_year, birth_month, birth_day = generate_random_birthday()
|
birth_year, birth_month, birth_day = generate_random_birthday()
|
||||||
@@ -1484,23 +1508,46 @@ def run_single_registration(progress_callback=None, step_callback=None) -> dict:
|
|||||||
final_reg_btn = page.ele('css:button[type="submit"]', timeout=20)
|
final_reg_btn = page.ele('css:button[type="submit"]', timeout=20)
|
||||||
final_reg_btn.click()
|
final_reg_btn.click()
|
||||||
|
|
||||||
# 等待进入主页
|
# 等待进入主页 - 改进检测逻辑
|
||||||
step_cb("等待进入主页...")
|
step_cb("等待进入主页...")
|
||||||
log_status("订阅", "等待进入 ChatGPT 主页...")
|
log_status("订阅", "等待进入 ChatGPT 主页...")
|
||||||
for _ in range(30):
|
|
||||||
|
# 等待页面跳转完成
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
entered_main = False
|
||||||
|
for i in range(30):
|
||||||
current_url = page.url
|
current_url = page.url
|
||||||
if 'chatgpt.com' in current_url and 'auth' not in current_url and 'login' not in current_url:
|
# 更宽松的判断:只要不在 auth/login 页面就认为进入了主页
|
||||||
log_progress(f"✓ 已进入主页: {current_url[:50]}...")
|
if 'chatgpt.com' in current_url:
|
||||||
|
if '/auth' not in current_url and '/login' not in current_url and 'auth0' not in current_url:
|
||||||
|
log_progress(f"✓ 已进入主页: {current_url[:60]}...")
|
||||||
|
entered_main = True
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
if i % 10 == 0 and i > 0:
|
||||||
log_progress("⚠ 等待主页超时,尝试继续...")
|
log_progress(f"等待中... ({i}秒)")
|
||||||
|
|
||||||
|
if not entered_main:
|
||||||
|
log_progress("⚠ 等待主页超时,尝试继续...")
|
||||||
|
# 尝试直接访问主页
|
||||||
|
page.get("https://chatgpt.com/")
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
# 额外等待页面稳定
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
# 跳转到支付页
|
# 跳转到支付页
|
||||||
step_cb("跳转到支付页...")
|
step_cb("跳转到支付页...")
|
||||||
log_status("订阅", "执行 JS 跳转到支付页...")
|
log_status("订阅", "执行 JS 跳转到支付页...")
|
||||||
|
|
||||||
|
# 先检查是否已登录
|
||||||
|
try:
|
||||||
|
session_check = page.run_js('return fetch("/api/auth/session").then(r => r.json())')
|
||||||
|
time.sleep(1)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
checkout_js = '''
|
checkout_js = '''
|
||||||
(async function(){
|
(async function(){
|
||||||
try {
|
try {
|
||||||
@@ -1527,6 +1574,9 @@ def run_single_registration(progress_callback=None, step_callback=None) -> dict:
|
|||||||
result = page.run_js(checkout_js)
|
result = page.run_js(checkout_js)
|
||||||
log_progress(f"JS 执行结果: {result}")
|
log_progress(f"JS 执行结果: {result}")
|
||||||
|
|
||||||
|
# 等待 JS 执行完成
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
page.wait.url_change('pay.openai.com', timeout=15)
|
page.wait.url_change('pay.openai.com', timeout=15)
|
||||||
log_progress("✓ 已跳转到支付页")
|
log_progress("✓ 已跳转到支付页")
|
||||||
|
|||||||
Reference in New Issue
Block a user