四个平台接入

This commit is contained in:
jjz
2025-09-13 19:54:30 +08:00
parent 22122660df
commit 08613313d3
5 changed files with 1250 additions and 768 deletions

View File

@@ -9,6 +9,7 @@ from WebSocket.BackendClient import BackendClient
from Utils.JD.JdUtils import JDListenerForGUI as JDListenerForGUI_WS
from Utils.Dy.DyUtils import DouYinListenerForGUI as DYListenerForGUI_WS
from Utils.Pdd.PddUtils import PddListenerForGUI as PDDListenerForGUI_WS
from Utils.QianNiu.QianNiuUtils import QianNiuListenerForGUI as QNListenerForGUI_WS
_backend_client = None
@@ -123,20 +124,50 @@ class WebSocketManager:
return False
def _handle_platform_login(self, platform_name: str, store_id: str, cookies: str):
"""处理平台登录逻辑"""
"""处理平台登录请求"""
try:
if platform_name == "京东" and store_id and cookies:
self._start_jd_listener(store_id, cookies)
elif platform_name == "抖音" and store_id and cookies:
self._start_douyin_listener(store_id, cookies)
elif platform_name == "千牛" and store_id and cookies:
# 平台名称映射
platform_map = {
"淘宝": "千牛",
"QIANNIU": "千牛",
"京东": "京东",
"JD": "京东",
"抖音": "抖音",
"DY": "抖音",
"DOUYIN": "抖音",
"拼多多": "拼多多",
"PDD": "拼多多",
"PINDUODUO": "拼多多"
}
# 标准化平台名称
normalized_platform = platform_map.get(platform_name.upper(), platform_name)
self._log(f"处理平台登录: {platform_name} -> {normalized_platform}, 店铺={store_id}", "INFO")
# 🔧 关键修改:确保每个平台都能独立处理自己的登录请求
if normalized_platform == "千牛":
if cookies == "login_success":
self._log("⚠️ 千牛平台收到空cookies但允许启动监听器", "WARNING")
cookies = "" # 清空cookies千牛不需要真实cookies
self._start_qianniu_listener(store_id, cookies)
elif platform_name == "拼多多" and store_id and cookies:
elif normalized_platform == "京东":
self._start_jd_listener(store_id, cookies)
elif normalized_platform == "抖音":
self._start_douyin_listener(store_id, cookies)
elif normalized_platform == "拼多多":
self._start_pdd_listener(store_id, cookies)
else:
self._log(f"不支持的平台或参数不全: {platform_name}", "WARNING")
self._log(f"不支持的平台: {platform_name}", "ERROR")
except Exception as e:
self._log(f"启动平台监听失败: {e}", "ERROR")
self._log(f"处理平台登录失败: {e}", "ERROR")
import traceback
self._log(f"错误详情: {traceback.format_exc()}", "DEBUG")
def _start_jd_listener(self, store_id: str, cookies: str):
"""启动京东平台监听"""
@@ -199,7 +230,7 @@ class WebSocketManager:
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))
return result
except Exception as e:
@@ -250,13 +281,64 @@ class WebSocketManager:
self._log(f"失败状态下报抖音平台连接状态也失败: {send_e}", "ERROR")
def _start_qianniu_listener(self, store_id: str, cookies: str):
"""启动千牛平台监听"""
"""启动千牛平台监听(单连接多店铺架构)"""
try:
# 这里可以添加千牛监听逻辑
self._log("千牛平台监听功能待实现", "INFO")
# 获取用户token从后端客户端获取
exe_token = None
if self.backend_client:
exe_token = getattr(self.backend_client, 'token', None)
if not exe_token:
self._log("❌ 缺少exe_token无法启动千牛监听器", "ERROR")
return
def _runner():
try:
listener = QNListenerForGUI_WS()
# 千牛平台使用新架构传递store_id和exe_token
asyncio.run(listener.start_listening_with_store(store_id, exe_token))
except Exception as e:
self._log(f"千牛监听器运行异常: {e}", "ERROR")
# 在新线程中启动监听器
thread = Thread(target=_runner, daemon=True)
thread.start()
# 保存监听器引用
self.platform_listeners[f"千牛:{store_id}"] = {
'thread': thread,
'platform': '千牛',
'store_id': store_id,
'exe_token': exe_token
}
# 上报连接状态给后端
if self.backend_client:
try:
self.backend_client.send_message({
"type": "connect_message",
"store_id": store_id,
"status": True
})
except Exception as e:
self._log(f"上报连接状态失败: {e}", "WARNING")
self._log("已启动千牛平台监听(单连接多店铺架构)", "SUCCESS")
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")
def _start_pdd_listener(self, store_id: str, data: str):
"""启动拼多多平台监听"""
try: