v3.1 + 批次0: 智能回复重构基线 - ApprovalMatcher + 关键词降级 + 文档速修 + v4.0任务书面化

This commit is contained in:
Simon
2026-07-17 23:08:59 +08:00
parent 5a77a89ab1
commit 3ed86d5fb3
181 changed files with 19738 additions and 2655 deletions
+48
View File
@@ -1325,6 +1325,54 @@ class WecomService:
logger.error(f"上传临时素材网络错误: type={media_type}, error={e}")
raise Exception(f"上传临时素材网络错误: {e}") from e
# --------------------------------------------------------------------------
# 下载临时素材
# --------------------------------------------------------------------------
async def download_temp_media(self, media_id: str) -> bytes:
"""下载临时素材(图片/文件/语音),返回二进制数据。
对应企微API:
GET https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=TOKEN&media_id=MEDIA_ID
用于将企微回调中的图片/文件下载到本地服务器保存。
Args:
media_id: 媒体文件ID(企微回调中的 MediaId)
Returns:
bytes: 媒体文件的二进制数据
Raises:
Exception: 下载失败
"""
access_token = await self.get_access_token()
url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"
params = {
"access_token": access_token,
"media_id": media_id,
}
try:
logger.info(f"开始下载临时素材: media_id={media_id}")
response = await self.client.get(url, params=params)
# 检查返回的是否是JSON错误响应
content_type = response.headers.get("content-type", "")
if "application/json" in content_type:
result = response.json()
if result.get("errcode") != 0:
errmsg = result.get("errmsg", "未知错误")
logger.error(f"下载临时素材失败: media_id={media_id}, errcode={result.get('errcode')}, errmsg={errmsg}")
raise Exception(f"下载临时素材失败: {errmsg}")
# 返回二进制数据
logger.info(f"下载临时素材成功: media_id={media_id}, size={len(response.content)} bytes")
return response.content
except httpx.HTTPError as e:
logger.error(f"下载临时素材网络错误: media_id={media_id}, error={e}")
raise Exception(f"下载临时素材网络错误: {e}") from e
# --------------------------------------------------------------------------
# OAuth2 授权换算用户身份
# --------------------------------------------------------------------------