[patch] 新增JD图片视频类型数据发送方法编写(强化send_message方法) 新增下载视频临时处理存储逻辑
This commit is contained in:
@@ -729,7 +729,8 @@ class BackendClient:
|
||||
platform_type = self._get_platform_by_store_id(store_id)
|
||||
|
||||
if platform_type == "京东":
|
||||
self._forward_to_jd(store_id, recv_pin, content)
|
||||
# 🔥 传递msg_type参数,支持图片/视频等类型
|
||||
self._forward_to_jd(store_id, recv_pin, content, msg_type)
|
||||
elif platform_type == "抖音":
|
||||
# 传递msg_type参数,支持图片/视频等类型
|
||||
self._forward_to_douyin(store_id, recv_pin, content, msg_type)
|
||||
@@ -761,8 +762,15 @@ class BackendClient:
|
||||
print(f"获取平台类型失败: {e}")
|
||||
return ""
|
||||
|
||||
def _forward_to_jd(self, store_id: str, recv_pin: str, content: str):
|
||||
"""转发消息到京东平台"""
|
||||
def _forward_to_jd(self, store_id: str, recv_pin: str, content: str, msg_type: str = "text"):
|
||||
"""转发消息到京东平台(支持文本/图片/视频)
|
||||
|
||||
Args:
|
||||
store_id: 店铺ID
|
||||
recv_pin: 接收者pin
|
||||
content: 消息内容(文本内容或URL)
|
||||
msg_type: 消息类型(text/image/video)
|
||||
"""
|
||||
try:
|
||||
from Utils.JD.JdUtils import WebsocketManager as JDWSManager
|
||||
jd_mgr = JDWSManager()
|
||||
@@ -778,49 +786,52 @@ class BackendClient:
|
||||
pin_zj = platform_info.get('pin_zj')
|
||||
vender_id = platform_info.get('vender_id')
|
||||
loop = platform_info.get('loop')
|
||||
cookies_str = platform_info.get('cookies_str') # 🔥 获取cookies用于文件上传
|
||||
|
||||
print(
|
||||
f"[JD Forward] shop_key={shop_key} has_ws={bool(ws)} aid={aid} pin_zj={pin_zj} vender_id={vender_id} has_loop={bool(loop)} recv_pin={recv_pin}")
|
||||
f"[JD Forward] shop_key={shop_key} has_ws={bool(ws)} aid={aid} pin_zj={pin_zj} vender_id={vender_id} has_loop={bool(loop)} has_cookies={bool(cookies_str)} recv_pin={recv_pin} msg_type={msg_type}")
|
||||
|
||||
if ws and aid and pin_zj and vender_id and loop and content:
|
||||
# 🔥 获取 FixJdCookie 实例,使用其 send_message 方法(支持多媒体)
|
||||
async def _send():
|
||||
import hashlib as _hashlib
|
||||
import time as _time
|
||||
import json as _json
|
||||
msg = {
|
||||
"ver": "4.3",
|
||||
"type": "chat_message",
|
||||
"from": {"pin": pin_zj, "app": "im.waiter", "clientType": "comet"},
|
||||
"to": {"app": "im.customer", "pin": recv_pin},
|
||||
"id": _hashlib.md5(str(int(_time.time() * 1000)).encode()).hexdigest(),
|
||||
"lang": "zh_CN",
|
||||
"aid": aid,
|
||||
"timestamp": int(_time.time() * 1000),
|
||||
"readFlag": 0,
|
||||
"body": {
|
||||
"content": content,
|
||||
"translated": False,
|
||||
"param": {"cusVenderId": vender_id},
|
||||
"type": "text"
|
||||
}
|
||||
}
|
||||
await ws.send(_json.dumps(msg))
|
||||
from Utils.JD.JdUtils import FixJdCookie
|
||||
# 创建临时实例用于发送
|
||||
jd_instance = FixJdCookie()
|
||||
# 🔥 设置认证信息(用于图片/视频上传)
|
||||
jd_instance.cookies_str = cookies_str
|
||||
jd_instance.current_aid = aid
|
||||
jd_instance.current_pin_zj = pin_zj
|
||||
# 调用支持多媒体的 send_message 方法
|
||||
await jd_instance.send_message(
|
||||
ws=ws,
|
||||
pin=recv_pin,
|
||||
aid=aid,
|
||||
pin_zj=pin_zj,
|
||||
vender_id=vender_id,
|
||||
content=content,
|
||||
msg_type=msg_type
|
||||
)
|
||||
|
||||
import asyncio as _asyncio
|
||||
_future = _asyncio.run_coroutine_threadsafe(_send(), loop)
|
||||
try:
|
||||
_future.result(timeout=2)
|
||||
print(f"[JD Forward] 已转发到平台: pin={recv_pin}, content_len={len(content)}")
|
||||
_future.result(timeout=60) # 图片/视频需要更长时间
|
||||
print(f"[JD Forward] 已转发到平台: pin={recv_pin}, type={msg_type}, content_len={len(content)}")
|
||||
except Exception as fe:
|
||||
print(f"[JD Forward] 转发提交失败: {fe}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
else:
|
||||
print("[JD Forward] 条件不足,未转发:",
|
||||
{
|
||||
'has_ws': bool(ws), 'has_aid': bool(aid), 'has_pin_zj': bool(pin_zj),
|
||||
'has_vender_id': bool(vender_id), 'has_loop': bool(loop), 'has_content': bool(content)
|
||||
'has_vender_id': bool(vender_id), 'has_loop': bool(loop), 'has_cookies': bool(cookies_str),
|
||||
'has_content': bool(content)
|
||||
})
|
||||
except Exception as e:
|
||||
print(f"[JD Forward] 转发失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def _forward_to_douyin(self, store_id: str, recv_pin: str, content: str, msg_type: str = "text"):
|
||||
"""转发消息到抖音平台
|
||||
|
||||
Reference in New Issue
Block a user