From eae7fdafb826c7e137a826cfb4a7a603cface1fa Mon Sep 17 00:00:00 2001 From: v6ole Date: Fri, 26 Jun 2026 09:46:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=81=E5=BE=AE=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=20=E2=80=94=20=E8=BF=94=E5=9B=9E=E7=BA=AF?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E8=80=8C=E9=9D=9E=20JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 企微后台保存时要求响应为原始解密明文(Content-Type: text/plain), FastAPI 默认 JSON 序列化会加引号导致验证失败。 改用 PlainTextResponse 返回纯文本。 验证: 本地 + 生产域名均返回 text/plain, 解密内容正确 Co-Authored-By: Claude --- backend/app/api/wecom.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/app/api/wecom.py b/backend/app/api/wecom.py index eddbd14..1b34add 100644 --- a/backend/app/api/wecom.py +++ b/backend/app/api/wecom.py @@ -4,6 +4,7 @@ import base64 import uuid from typing import Optional from fastapi import APIRouter, Depends, HTTPException, Query, Request +from fastapi.responses import PlainTextResponse from pydantic import BaseModel from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy import select @@ -73,7 +74,8 @@ async def wecom_callback_verify( try: plaintext = _decrypt_echostr(echostr) - return plaintext + # Must return raw plaintext (not JSON) — WeChat Work requires exact match + return PlainTextResponse(content=plaintext, status_code=200) except Exception as e: raise HTTPException(status_code=500, detail=f"Decrypt failed: {e}")