{"record":{"id":"9370bd268b7ca8df","repo":"JeffreySu/WeiXinMPSDK","slug":"encryptiontype-tenpaynotifyhandler","errorCode":null,"errorMessage":"没有设置证书加密类型（EncryptionType）","messagePattern":"没有设置证书加密类型（EncryptionType）","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayNotifyHandler.cs","lineNumber":138,"sourceCode":"            : this(\n                httpContext,\n                senparcWeixinSettingForTenpayV3,\n                ReadBodyAsync(httpContext, maxBodyBytes, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult())\n        {\n        }\n\n        private TenPayNotifyHandler(\n            HttpContext httpContext,\n            ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3,\n            NotificationBody notificationBody)\n        {\n            _ = httpContext ?? throw new ArgumentNullException(nameof(httpContext));\n            _httpContext = httpContext;\n            _tenpayV3Setting = senparcWeixinSettingForTenpayV3 ?? Senparc.Weixin.Config.SenparcWeixinSetting.TenpayV3Setting;\n\n            if (!_tenpayV3Setting.EncryptionType.HasValue)\n            {\n                throw new Senparc.Weixin.Exceptions.WeixinException(\"没有设置证书加密类型（EncryptionType）\");\n            }\n\n            Body = notificationBody.Body;\n            NotifyRequest = notificationBody.NotifyRequest;\n        }\n\n        /// <summary>\n        /// 异步创建通知处理器，支持请求取消并限制请求体大小。\n        /// </summary>\n        public static async Task<TenPayNotifyHandler> CreateAsync(\n            HttpContext httpContext,\n            ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null,\n            int maxBodyBytes = DefaultMaxBodyBytes,\n            CancellationToken cancellationToken = default)\n        {\n            var notificationBody = await ReadBodyAsync(httpContext, maxBodyBytes, cancellationToken).ConfigureAwait(false);\n            return new TenPayNotifyHandler(httpContext, senparcWeixinSettingForTenpayV3, notificationBody);\n        }","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayNotifyHandler.cs#L120-L156","documentation":"Like the HttpHandler, TenPayNotifyHandler requires the TenpayV3 EncryptionType to know how to decrypt the notification resource; a null value throws WeixinException \"没有设置证书加密类型（EncryptionType）\" during handler construction.","triggerScenarios":"Creating a TenPayNotifyHandler (via its factory taking httpContext, settings and NotificationBody) while the effective TenpayV3Setting has no EncryptionType set.","commonSituations":"Same as error 150: missing or legacy appsettings TenpayV3Setting block, incomplete SenparcWeixinSetting registration in a notify callback controller.","solutions":["Set EncryptionType in the TenpayV3Setting configuration section before handling callbacks","Pass a complete ISenparcWeixinSettingForTenpayV3 (with EncryptionType) to the notify handler factory","Verify Config.SenparcWeixinSetting.TenpayV3Setting is populated at startup (fail fast in Program.cs)","Log the loaded setting object at startup to confirm EncryptionType binds correctly"],"exampleFix":"// before\n\"TenpayV3Setting\": { \"AppId\": \"wx123\", \"MerchantId\": \"mch1\" }\n// after\n\"TenpayV3Setting\": { \"AppId\": \"wx123\", \"MerchantId\": \"mch1\", \"EncryptionType\": \"MD5\" }","handlingStrategy":"validation","validationCode":"if (!Config.SenparcWeixinSetting.TenpayV3Setting.EncryptionType.HasValue)\n    throw new InvalidOperationException(\"请先在 TenpayV3Setting 中设置 EncryptionType。\");","typeGuard":"bool NotifySettingReady(ISenparcWeixinSettingForTenpayV3 s) => s?.EncryptionType.HasValue == true;","tryCatchPattern":"try { var handler = TenPayNotifyHandler.Create(httpContext, settings, body); ... }\ncatch (WeixinException ex) { logger.LogError(ex, \"TenpayV3 配置不完整\"); return StatusCode(500); }","preventionTips":["Run a settings completeness check at startup","Keep TenpayV3Setting JSON in sync with the SDK's setting model on upgrades"],"tags":["config","tenpay","missing-config-field"],"backgroundTag":"missing-required-config-field","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}