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 }; }