From 7312d3f91a5810eae8c6d41688bdc735def78459 Mon Sep 17 00:00:00 2001 From: Gitea Actions Bot Date: Tue, 14 Oct 2025 17:26:53 +0800 Subject: [PATCH] =?UTF-8?q?[patch]=20=E4=BF=AE=E6=AD=A3=E4=BA=AC=E4=B8=9C?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E5=AE=A2=E6=9C=8D=E5=88=97=E8=A1=A8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Utils/JD/JdUtils.py | 81 +++++++++++++++++++++++++++++++++++++++++++++ config.py | 2 +- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/Utils/JD/JdUtils.py b/Utils/JD/JdUtils.py index 2ae17ba..d819a3f 100644 --- a/Utils/JD/JdUtils.py +++ b/Utils/JD/JdUtils.py @@ -210,6 +210,80 @@ class FixJdCookie: } await ws.send(json.dumps(message)) + async def get_all_customer(self, ws, aid, pin_zj): + """异步获取商家组织架构(客服列表)""" + id_str = hashlib.md5(str(int(time.time() * 1000) + 300).encode()).hexdigest() + message = { + "id": id_str, + "aid": aid, + "lang": "zh_CN", + "timestamp": int(time.time() * 1000), + "from": { + "app": "im.waiter", "pin": pin_zj, "art": "customerGroupMsg", "clientType": "comet" + }, + "type": "org_new", + "body": {"param": pin_zj, "paramtype": "ByPin"} + } + await ws.send(json.dumps(message)) + while True: + response = await ws.recv() + data = json.loads(response) + if data.get("id") == id_str and data.get("body", {}).get("groupname") == "商家组织架构": + group = data.get("body", {}).get("group") + if group: + try: + # 与旧实现保持一致的数据路径 + self.customer_list = group[0].get("group")[0].get("users") + except Exception: + self.customer_list = [] + return + + async def send_staff_list_to_backend(self, store_id): + """发送客服列表到后端(通过统一后端连接)""" + try: + if not hasattr(self, 'customer_list') or not self.customer_list: + self._log("⚠️ 客服列表为空", "WARNING") + return False + + # 转换客服数据格式 + staff_infos = [] + for staff in self.customer_list: + staff_info = { + "staff_id": staff.get("pin", ""), + "name": staff.get("nickname", ""), + "status": staff.get("status", 0), + "department": staff.get("department", ""), + "online": staff.get("online", True) + } + staff_infos.append(staff_info) + + # 通过后端统一连接发送 + try: + from WebSocket.backend_singleton import get_backend_client + backend_client = get_backend_client() + if not backend_client or not getattr(backend_client, 'is_connected', False): + self._log("❌ 统一后端连接不可用", "ERROR") + return False + + message = { + "type": "staff_list", + "content": "客服列表更新", + "data": { + "staff_list": staff_infos, + "total_count": len(staff_infos) + }, + "store_id": str(store_id) + } + backend_client.send_message(message) + self._log(f"✅ 成功发送客服列表到后端,共 {len(staff_infos)} 个客服", "SUCCESS") + return True + except Exception as e: + self._log(f"❌ 发送客服列表到后端失败: {e}", "ERROR") + return False + except Exception as e: + self._log(f"❌ 发送客服列表到后端异常: {e}", "ERROR") + return False + async def transfer_customer(self, ws, aid, pin, pin_zj, chat_name): """异步客服转接 在发送的消息为客服转接的关键词的时候""" message = { @@ -506,6 +580,13 @@ class FixJdCookie: # print(f"✅ 连接状态: open={ws.open}, closed={ws.closed}") print(f"🖥️ 服务端地址: {ws.remote_address}") + # 连接成功后,获取并上报一次客服列表(最小改动恢复) + try: + await self.get_all_customer(ws, aid, pin_zj) + await self.send_staff_list_to_backend(store.get('id', '')) + except Exception as e: + self._log(f"❌ 获取或发送客服列表失败: {e}", "ERROR") + # --- 注册连接信息到全局管理 shop_key = f"京东:{store['id']}" loop = asyncio.get_running_loop() diff --git a/config.py b/config.py index 14ca22c..fd39418 100644 --- a/config.py +++ b/config.py @@ -9,7 +9,7 @@ import json # 用于将令牌保存为 JSON 格式 # 后端服务器配置 # BACKEND_HOST = "192.168.5.233" -BACKEND_HOST = "192.168.5.12" +BACKEND_HOST = "192.168.5.106" # BACKEND_HOST = "shuidrop.com" # BACKEND_HOST = "test.shuidrop.com" BACKEND_PORT = "8000"