实现抖音验证码登录
This commit is contained in:
@@ -275,15 +275,66 @@ class WebSocketManager:
|
||||
def _runner():
|
||||
try:
|
||||
import json
|
||||
self._log("🚀 开始创建抖音监听器实例", "DEBUG")
|
||||
listener = DYListenerForGUI_WS()
|
||||
# 将JSON字符串格式的cookies解析为字典
|
||||
try:
|
||||
cookie_dict = json.loads(cookies) if isinstance(cookies, str) else cookies
|
||||
except json.JSONDecodeError as e:
|
||||
self._log(f"❌ Cookie JSON解析失败: {e}", "ERROR")
|
||||
return False
|
||||
|
||||
result = asyncio.run(listener.start_with_cookies(store_id=store_id, cookie_dict=cookie_dict))
|
||||
self._log("✅ 抖音监听器实例创建成功", "DEBUG")
|
||||
|
||||
# 🔥 检查是否为登录参数模式(与拼多多保持一致)
|
||||
if cookies and ('"login_flow"' in cookies or '"phone_number"' in cookies):
|
||||
# 使用登录参数模式
|
||||
self._log("📋 使用登录参数启动抖音监听器", "INFO")
|
||||
self._log("🔄 开始执行 start_with_login_params", "DEBUG")
|
||||
result = asyncio.run(listener.start_with_login_params(store_id=store_id, login_params=cookies))
|
||||
self._log(f"📊 start_with_login_params 执行结果: {result}", "DEBUG")
|
||||
|
||||
# 🔥 详细的结果分析(与拼多多完全一致)
|
||||
if result == "need_verification_code":
|
||||
self._log("✅ [DY] 登录流程正常,已发送验证码需求通知给后端", "SUCCESS")
|
||||
elif result == "verification_code_error":
|
||||
self._log("⚠️ [DY] 验证码错误,已发送错误通知给后端", "WARNING")
|
||||
elif result:
|
||||
self._log("✅ [DY] 登录成功,平台连接已建立", "SUCCESS")
|
||||
self._notify_platform_connected("抖音")
|
||||
else:
|
||||
self._log("❌ [DY] 登录失败", "ERROR")
|
||||
else:
|
||||
# 传统cookie模式(保留兼容性)
|
||||
self._log("🍪 使用Cookie启动抖音监听器", "INFO")
|
||||
self._log("🔄 开始执行 start_with_cookies", "DEBUG")
|
||||
try:
|
||||
cookie_dict = json.loads(cookies) if isinstance(cookies, str) else cookies
|
||||
except json.JSONDecodeError as e:
|
||||
self._log(f"❌ Cookie JSON解析失败: {e}", "ERROR")
|
||||
return False
|
||||
result = asyncio.run(listener.start_with_cookies(store_id=store_id, cookie_dict=cookie_dict))
|
||||
self._log(f"📊 start_with_cookies 执行结果: {result}", "DEBUG")
|
||||
|
||||
# Cookie启动成功时也要通知GUI
|
||||
if result:
|
||||
self._log("✅ [DY] Cookie启动成功,平台连接已建立", "SUCCESS")
|
||||
self._notify_platform_connected("抖音")
|
||||
|
||||
# 🔥 根据实际登录结果上报状态给后端(与拼多多完全一致)
|
||||
if self.backend_client and result not in ["need_verification_code", "verification_code_error", "login_failure"]:
|
||||
# 如果是特殊状态,说明通知已经在DyLogin中发送了,不需要重复发送
|
||||
try:
|
||||
message = {
|
||||
"type": "connect_message",
|
||||
"store_id": store_id,
|
||||
"status": bool(result)
|
||||
}
|
||||
self.backend_client.send_message(message)
|
||||
status_text = "成功" if result else "失败"
|
||||
self._log(f"上报抖音平台连接状态{status_text}: {message}", "SUCCESS" if result else "ERROR")
|
||||
except Exception as send_e:
|
||||
self._log(f"上报抖音平台连接状态失败: {send_e}", "ERROR")
|
||||
elif result == "need_verification_code":
|
||||
self._log("需要验证码,验证码通知已由DyLogin发送,等待后端重新下发登录参数", "INFO")
|
||||
elif result == "verification_code_error":
|
||||
self._log("验证码错误,错误通知已由DyLogin发送,等待后端处理", "INFO")
|
||||
elif result == "login_failure":
|
||||
self._log("登录失败,失败通知已由DyLogin发送,等待后端处理", "INFO")
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
self._log(f"抖音监听器运行异常: {e}", "ERROR")
|
||||
@@ -304,20 +355,7 @@ class WebSocketManager:
|
||||
if f"抖音:{store_id}" in self.platform_listeners:
|
||||
self.platform_listeners[f"抖音:{store_id}"]['status'] = 'success'
|
||||
|
||||
# 上报连接状态给后端
|
||||
if self.backend_client:
|
||||
try:
|
||||
self.backend_client.send_message({
|
||||
"type": "connect_message",
|
||||
"store_id": store_id,
|
||||
"status": True
|
||||
})
|
||||
self._log("已上报抖音平台连接状态: 成功", "INFO")
|
||||
except Exception as e:
|
||||
self._log(f"上报抖音平台连接状态失败: {e}", "WARNING")
|
||||
|
||||
self._log("已启动抖音平台监听", "SUCCESS")
|
||||
self._notify_platform_connected("抖音") # ← 新增
|
||||
|
||||
except Exception as e:
|
||||
self._log(f"启动抖音平台监听失败: {e}", "ERROR")
|
||||
|
||||
Reference in New Issue
Block a user