拼多多实现加密参数登录+京东客服转接
This commit is contained in:
@@ -657,6 +657,67 @@ class BackendClient:
|
||||
except Exception as e:
|
||||
print(f"[PDD Transfer] 拼多多转接失败: {e}")
|
||||
|
||||
def _transfer_to_jd(self, customer_service_id: str, user_id: str, store_id: str):
|
||||
"""执行京东平台转接操作"""
|
||||
try:
|
||||
from Utils.JD.JdUtils import WebsocketManager as JDWSManager
|
||||
jd_mgr = JDWSManager()
|
||||
shop_key = f"京东:{store_id}"
|
||||
entry = jd_mgr.get_connection(shop_key)
|
||||
|
||||
if not entry:
|
||||
print(f"[JD Transfer] 未找到京东连接: {shop_key}")
|
||||
return
|
||||
|
||||
platform_info = entry.get('platform', {})
|
||||
ws = platform_info.get('ws')
|
||||
aid = platform_info.get('aid')
|
||||
pin_zj = platform_info.get('pin_zj')
|
||||
loop = platform_info.get('loop')
|
||||
|
||||
print(f"[JD Transfer] 找到京东连接,准备执行转接: user_id={user_id}, cs_id={customer_service_id}")
|
||||
print(f"[JD Transfer] 连接参数: has_ws={bool(ws)}, aid={aid}, pin_zj={pin_zj}, has_loop={bool(loop)}")
|
||||
|
||||
if ws and aid and pin_zj and loop:
|
||||
# 在事件循环中执行转接
|
||||
def transfer_in_loop():
|
||||
try:
|
||||
# 导入FixJdCookie类来调用转接方法
|
||||
from Utils.JD.JdUtils import FixJdCookie
|
||||
jd_utils = FixJdCookie()
|
||||
|
||||
# 在事件循环中执行转接
|
||||
future = asyncio.run_coroutine_threadsafe(
|
||||
jd_utils.transfer_customer(ws, aid, user_id, pin_zj, customer_service_id),
|
||||
loop
|
||||
)
|
||||
|
||||
# 等待转接结果
|
||||
try:
|
||||
result = future.result(timeout=10) # 京东转接超时时间
|
||||
if result:
|
||||
print(f"[JD Transfer] ✅ 转接成功: user_id={user_id} -> cs_id={customer_service_id}")
|
||||
else:
|
||||
print(f"[JD Transfer] ❌ 转接失败: user_id={user_id}")
|
||||
except Exception as fe:
|
||||
print(f"[JD Transfer] 转接执行失败: {fe}")
|
||||
except Exception as e:
|
||||
print(f"[JD Transfer] 转接过程异常: {e}")
|
||||
|
||||
# 在新线程中执行转接操作
|
||||
import threading
|
||||
transfer_thread = threading.Thread(target=transfer_in_loop, daemon=True)
|
||||
transfer_thread.start()
|
||||
|
||||
else:
|
||||
print("[JD Transfer] 条件不足,未转接:",
|
||||
{
|
||||
'has_ws': bool(ws), 'has_aid': bool(aid), 'has_pin_zj': bool(pin_zj),
|
||||
'has_loop': bool(loop)
|
||||
})
|
||||
except Exception as e:
|
||||
print(f"[JD Transfer] 京东转接失败: {e}")
|
||||
|
||||
def _handle_transfer(self, message: Dict[str, Any]):
|
||||
"""处理转接消息"""
|
||||
# 新版转接消息格式: {"type": "transfer", "content": "客服ID", "receiver": {"id": "用户ID"}, "store_id": "店铺ID"}
|
||||
@@ -672,8 +733,7 @@ class BackendClient:
|
||||
platform_type = self._get_platform_by_store_id(store_id)
|
||||
|
||||
if platform_type == "京东":
|
||||
# 京东转接逻辑 - 待实现
|
||||
print(f"[JD Transfer] 京东平台转接功能待实现")
|
||||
self._transfer_to_jd(customer_service_id, user_id, store_id)
|
||||
elif platform_type == "抖音":
|
||||
# 抖音转接逻辑 - 待实现
|
||||
print(f"[DY Transfer] 抖音平台转接功能待实现")
|
||||
@@ -711,13 +771,26 @@ class BackendClient:
|
||||
self.get_store()
|
||||
|
||||
def _handle_login(self, message: Dict[str, Any]):
|
||||
"""处理平台登录消息(新版:type=login, cookies, store_id, platform_name)"""
|
||||
"""处理平台登录消息(新版:type=login, cookies/login_params, store_id, platform_name)"""
|
||||
cookies = message.get('cookies', '')
|
||||
store_id = message.get('store_id', '')
|
||||
platform_name = message.get('platform_name', '')
|
||||
print(f"收到登录指令: 平台={platform_name}, 店铺={store_id}, cookies_len={len(cookies) if cookies else 0}")
|
||||
if self.login_callback:
|
||||
self.login_callback(platform_name, store_id, cookies)
|
||||
content = message.get('content', '')
|
||||
data = message.get('data', {})
|
||||
|
||||
# 判断是拼多多登录参数还是普通Cookie
|
||||
if platform_name == "拼多多" and content == "pdd_login_params" and data.get('login_params'):
|
||||
# 拼多多登录参数模式
|
||||
import json
|
||||
login_params_str = json.dumps({"data": data})
|
||||
print(f"收到拼多多登录参数: 平台={platform_name}, 店铺={store_id}, params_len={len(login_params_str)}")
|
||||
if self.login_callback:
|
||||
self.login_callback(platform_name, store_id, login_params_str)
|
||||
else:
|
||||
# 普通Cookie模式
|
||||
print(f"收到登录指令: 平台={platform_name}, 店铺={store_id}, cookies_len={len(cookies) if cookies else 0}")
|
||||
if self.login_callback:
|
||||
self.login_callback(platform_name, store_id, cookies)
|
||||
|
||||
def _handle_error_message(self, message: Dict[str, Any]):
|
||||
"""处理错误消息"""
|
||||
|
||||
Reference in New Issue
Block a user