[patch] 修改适中心跳机制 JD的平台登录抢占 提示弹框优化 并下发连接断开通知 托盘右击提示小标题显示精炼 增加store_name入回调方法做店铺名称定位

This commit is contained in:
2025-10-17 15:21:03 +08:00
parent 90bf763bde
commit c32d326c69
5 changed files with 282 additions and 90 deletions

View File

@@ -177,6 +177,11 @@ class FixJdCookie:
"""初始化 socket"""
await self.send_heartbeat(ws, aid, pin_zj)
print("开始监听初始化")
# 🔧 修复生成唯一设备ID避免多端互踢
import uuid
unique_device_id = f"shuidrop_gui_{uuid.uuid4().hex[:16]}"
auth = {
"id": hashlib.md5(str(int(time.time() * 1000)).encode()).hexdigest(),
"aid": aid,
@@ -185,8 +190,9 @@ class FixJdCookie:
"type": "auth",
"body": {"presence": 1, "clientVersion": "2.6.3"},
"to": {"app": "im.waiter"},
"from": {"app": "im.waiter", "pin": pin_zj, "clientType": "comet", "dvc": "device1234"}
"from": {"app": "im.waiter", "pin": pin_zj, "clientType": "comet", "dvc": unique_device_id}
}
print(f"[DEBUG] 使用唯一设备ID: {unique_device_id}")
await ws.send(json.dumps(auth))
@@ -611,10 +617,42 @@ class FixJdCookie:
print(f"等待监听消息-{datetime.now()}")
response = await asyncio.wait_for(ws.recv(), timeout=1)
print(f"原始消息类型:{type(response)}, 消息体为: {response}")
await self.process_incoming_message(response, ws, aid, pin_zj, vender_id, store)
# 安全解析消息
# 🔧 修复:检测被踢下线消息
json_resp = json.loads(response) if isinstance(response, (str, bytes)) else response
# 检查是否为server_msg类型且code=5被踢下线
if json_resp.get("type") == "server_msg":
body = json_resp.get("body", {})
if body.get("code") == 5:
msgtext = body.get("msgtext", "账号在其他设备登录")
self._log(f"⚠️ 收到被踢下线消息: {msgtext}", "WARNING")
self._log("⚠️ 检测到多端登录冲突,请确保:", "WARNING")
self._log(" 1. 关闭网页版京东咚咚", "WARNING")
self._log(" 2. 关闭其他客户端", "WARNING")
self._log(" 3. 确认只有本客户端连接", "WARNING")
# 通知GUI显示弹窗
try:
from WebSocket.backend_singleton import get_websocket_manager
ws_manager = get_websocket_manager()
if ws_manager:
# 从platform_listeners获取店铺名称
store_name = "京东店铺"
for key, info in ws_manager.platform_listeners.items():
if info.get('store_id') == store:
store_name = info.get('store_name', '') or "京东店铺"
break
# 传递 store_id 参数,用于通知后端
ws_manager.notify_platform_kicked("京东", store_name, msgtext, store_id=store)
except Exception as notify_error:
self._log(f"通知GUI失败: {notify_error}", "ERROR")
# 不再自动重连,等待用户处理
stop_event.set()
break
await self.process_incoming_message(response, ws, aid, pin_zj, vender_id, store)
print(json_resp)
@@ -660,9 +698,8 @@ class FixJdCookie:
if not await self.handle_reconnect(e):
break
# 关闭后端服务连接
# 关闭后端服务连接JDBackendService没有close方法跳过
if self.backend_connected:
await self.backend_service.close()
self.backend_connected = False
self._log("🛑 消息监听已停止", "INFO")