fix: 企微回调验证 — 返回纯文本而非 JSON
企微后台保存时要求响应为原始解密明文(Content-Type: text/plain), FastAPI 默认 JSON 序列化会加引号导致验证失败。 改用 PlainTextResponse 返回纯文本。 验证: 本地 + 生产域名均返回 text/plain, 解密内容正确 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import base64
|
|||||||
import uuid
|
import uuid
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||||
|
from fastapi.responses import PlainTextResponse
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@@ -73,7 +74,8 @@ async def wecom_callback_verify(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
plaintext = _decrypt_echostr(echostr)
|
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:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"Decrypt failed: {e}")
|
raise HTTPException(status_code=500, detail=f"Decrypt failed: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user