修复后台聊天表情发送易卡住问题\n\n- 将后台表情发送改为异步提交,避免请求线程同步等待导致卡住\n- 增加按 md5 反查历史表情 total_length 的兜底逻辑\n- 为 SendEmoji 增加超时与详细日志,便于定位接口无响应问题
This commit is contained in:
@@ -506,15 +506,26 @@ class MessageMixin(WechatAPIClientBase):
|
||||
if not self.wxid:
|
||||
raise UserLoggedOut("请先登录")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
# 表情发送接口历史上最容易出现“接口长时间不返回,导致整个消息队列被拖住”的问题,
|
||||
# 因此这里单独加总超时和更细的日志,方便区分“参数错误”和“接口无响应”两类故障。
|
||||
timeout = aiohttp.ClientTimeout(total=20)
|
||||
async with aiohttp.ClientSession(timeout=timeout) as session:
|
||||
json_param = {"Wxid": self.wxid, "ToWxid": wxid, "Md5": md5, "TotalLen": total_length}
|
||||
response = await session.post(f'http://{self.ip}:{self.port}/api/Msg/SendEmoji', json=json_param)
|
||||
json_resp = await response.json()
|
||||
try:
|
||||
self.logging.info("开始发送表情消息: 对方wxid:{} md5:{} 总长度:{}", wxid, md5, total_length)
|
||||
response = await session.post(f'http://{self.ip}:{self.port}/api/Msg/SendEmoji', json=json_param)
|
||||
json_resp = await response.json(content_type=None)
|
||||
except asyncio.TimeoutError as exc:
|
||||
self.logging.error("发送表情消息超时: 对方wxid:{} md5:{} 总长度:{}", wxid, md5, total_length)
|
||||
raise TimeoutError("SendEmoji 接口调用超时") from exc
|
||||
|
||||
if json_resp.get("Success"):
|
||||
self.logging.info("发送表情消息: 对方wxid:{} md5:{} 总长度:{}", wxid, md5, total_length)
|
||||
return json_resp.get("Data").get("emojiItem")
|
||||
data = json_resp.get("Data") or {}
|
||||
self.logging.info("发送表情消息成功: 对方wxid:{} md5:{} 总长度:{}", wxid, md5, total_length)
|
||||
return data.get("emojiItem") or data.get("EmojiItem") or data
|
||||
else:
|
||||
self.logging.error("发送表情消息失败: 对方wxid:{} md5:{} 总长度:{} resp:{}",
|
||||
wxid, md5, total_length, json_resp)
|
||||
self.error_handler(json_resp)
|
||||
|
||||
async def send_card_message(self, wxid: str, card_wxid: str, card_nickname: str, card_alias: str = "") -> tuple[
|
||||
|
||||
Reference in New Issue
Block a user