mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 09:40:30 +08:00
fix: wecom adapter returning json instead of plain text (#9107)
* Fix wecom adapter returning json instead of plain text * Fix handle_verify return class
This commit is contained in:
@@ -8,6 +8,7 @@ from pathlib import Path
|
|||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
|
from fastapi.responses import Response as FastAPIResponse
|
||||||
from requests import Response
|
from requests import Response
|
||||||
from wechatpy.enterprise import WeChatClient, parse_message
|
from wechatpy.enterprise import WeChatClient, parse_message
|
||||||
from wechatpy.enterprise.crypto import WeChatCrypto
|
from wechatpy.enterprise.crypto import WeChatCrypto
|
||||||
@@ -97,7 +98,7 @@ class WecomServer:
|
|||||||
"""内部服务器的 GET 验证入口"""
|
"""内部服务器的 GET 验证入口"""
|
||||||
return await self.handle_verify(request)
|
return await self.handle_verify(request)
|
||||||
|
|
||||||
async def handle_verify(self, request) -> str:
|
async def handle_verify(self, request) -> FastAPIResponse:
|
||||||
"""处理验证请求,可被统一 webhook 入口复用
|
"""处理验证请求,可被统一 webhook 入口复用
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -116,7 +117,7 @@ class WecomServer:
|
|||||||
args.get("echostr"),
|
args.get("echostr"),
|
||||||
)
|
)
|
||||||
logger.info("验证请求有效性成功。")
|
logger.info("验证请求有效性成功。")
|
||||||
return echo_str
|
return FastAPIResponse(content=echo_str, media_type="text/plain")
|
||||||
except InvalidSignatureException:
|
except InvalidSignatureException:
|
||||||
logger.error("验证请求有效性失败,签名异常,请检查配置。")
|
logger.error("验证请求有效性失败,签名异常,请检查配置。")
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, Request
|
from fastapi import APIRouter, Depends, Request
|
||||||
|
from fastapi.responses import Response
|
||||||
|
|
||||||
from astrbot.dashboard.asgi_runtime import DashboardRequest
|
from astrbot.dashboard.asgi_runtime import DashboardRequest
|
||||||
from astrbot.dashboard.async_utils import run_maybe_async
|
from astrbot.dashboard.async_utils import run_maybe_async
|
||||||
@@ -50,6 +51,8 @@ def _model_dict(payload) -> dict[str, Any]:
|
|||||||
async def _run(operation):
|
async def _run(operation):
|
||||||
try:
|
try:
|
||||||
result = await run_maybe_async(operation)
|
result = await run_maybe_async(operation)
|
||||||
|
if isinstance(result, Response):
|
||||||
|
return result
|
||||||
return ok(result)
|
return ok(result)
|
||||||
except PlatformServiceError as exc:
|
except PlatformServiceError as exc:
|
||||||
_raise_platform_error(exc)
|
_raise_platform_error(exc)
|
||||||
|
|||||||
Reference in New Issue
Block a user