From d168a21e965f071a42b46c3759723111cf79a2da Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Wed, 1 Jul 2026 15:25:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(wechat):=20=E5=85=AC=E4=BC=97=E5=8F=B7?= =?UTF-8?q?=E9=AA=8C=E7=AD=BE=E6=8E=A5=E5=8F=A3=E5=A7=8B=E7=BB=88=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20HTTP=20200=EF=BC=8C=E9=81=BF=E5=85=8D=20BusinessExc?= =?UTF-8?q?eption=20=E5=AF=BC=E8=87=B4=E9=9D=9E=20200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- src/SimpleAdmin.Api/WeChat/WeChatMpCallbackSupport.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/SimpleAdmin.Api/WeChat/WeChatMpCallbackSupport.cs b/src/SimpleAdmin.Api/WeChat/WeChatMpCallbackSupport.cs index eb80f40..98d0ef3 100644 --- a/src/SimpleAdmin.Api/WeChat/WeChatMpCallbackSupport.cs +++ b/src/SimpleAdmin.Api/WeChat/WeChatMpCallbackSupport.cs @@ -15,9 +15,10 @@ internal static class WeChatMpCallbackSupport string? nonce, string? echostr) { + // 微信服务器要求 HTTP 200 + 纯文本 echostr,不可抛 BusinessException(会变成 JSON 非 200) if (string.IsNullOrWhiteSpace(options.Value.Token)) { - throw new BusinessException("未配置微信公众号 Token"); + return PlainText("error"); } if (string.IsNullOrWhiteSpace(signature) @@ -90,8 +91,8 @@ internal static class WeChatMpCallbackSupport } private static ContentResult PlainText(string content) => - new() { Content = content, ContentType = "text/plain; charset=utf-8" }; + new() { Content = content, ContentType = "text/plain; charset=utf-8", StatusCode = StatusCodes.Status200OK }; private static ContentResult Xml(string content) => - new() { Content = content, ContentType = "application/xml; charset=utf-8" }; + new() { Content = content, ContentType = "application/xml; charset=utf-8", StatusCode = StatusCodes.Status200OK }; }