实现pdd抖音平台cookie登录
This commit is contained in:
@@ -302,9 +302,19 @@ class WebSocketManager:
|
||||
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")
|
||||
# 🔥 修复:尝试JSON解析,失败时用ast.literal_eval解析Python字典字符串
|
||||
if isinstance(cookies, str):
|
||||
try:
|
||||
cookie_dict = json.loads(cookies)
|
||||
except json.JSONDecodeError:
|
||||
# 后端发送的是Python字典字符串格式,使用ast.literal_eval
|
||||
import ast
|
||||
cookie_dict = ast.literal_eval(cookies)
|
||||
self._log("✅ 使用ast.literal_eval成功解析cookies", "DEBUG")
|
||||
else:
|
||||
cookie_dict = cookies
|
||||
except (json.JSONDecodeError, ValueError, SyntaxError) as e:
|
||||
self._log(f"❌ Cookie解析失败: {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")
|
||||
@@ -314,26 +324,9 @@ class WebSocketManager:
|
||||
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")
|
||||
# 🔥 移除:不再在backend_singleton中发送connect_message
|
||||
# 抖音的连接状态报告应该在DyUtils中的DyLogin类中发送,与拼多多保持一致
|
||||
# 所有特殊状态通知都已经在DyLogin中发送过了,这里不需要重复发送
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
@@ -360,16 +353,8 @@ class WebSocketManager:
|
||||
except Exception as e:
|
||||
self._log(f"启动抖音平台监听失败: {e}", "ERROR")
|
||||
|
||||
# 确保失败时也上报状态
|
||||
if self.backend_client:
|
||||
try:
|
||||
self.backend_client.send_message({
|
||||
"type": "connect_message",
|
||||
"store_id": store_id,
|
||||
"status": False
|
||||
})
|
||||
except Exception as send_e:
|
||||
self._log(f"失败状态下报抖音平台连接状态也失败: {send_e}", "ERROR")
|
||||
# 🔥 移除:确保失败时也不在这里上报状态
|
||||
# 失败状态应该在DyLogin中处理,与拼多多保持一致
|
||||
|
||||
def _start_qianniu_listener(self, store_id: str, cookies: str):
|
||||
"""启动千牛平台监听(单连接多店铺架构)"""
|
||||
|
||||
Reference in New Issue
Block a user