{"record":{"id":"6bb8975969911b11","repo":"JeffreySu/WeiXinMPSDK","slug":"encryptiontype-tenpayhttphandler","errorCode":null,"errorMessage":"没有设置证书加密类型（EncryptionType）","messagePattern":"没有设置证书加密类型（EncryptionType）","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayHttpHandler.cs","lineNumber":105,"sourceCode":"        }\n\n        private TenPayHttpHandler(\n            ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3,\n            TenPayBrandApiCredentials brandApiCredentials)\n        {\n            InnerHandler = new HttpClientHandler();\n\n            _brandApiCredentials = brandApiCredentials;\n            if (_brandApiCredentials != null)\n            {\n                return;\n            }\n\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\n        /// <summary>\n        /// 重写 SendAsync 方法\n        /// </summary>\n        /// <param name=\"request\"></param>\n        /// <param name=\"cancellationToken\"></param>\n        /// <returns></returns>\n        protected async override Task<HttpResponseMessage> SendAsync(\n            HttpRequestMessage request,\n            CancellationToken cancellationToken)\n        {\n            var auth = await BuildAuthAsync(request);\n\n            var authorizationValue = _brandApiCredentials != null\n                ? TenPayBrandApiCredentials.AuthorizationType\n                : _tenpayV3Setting.EncryptionType == CertType.SM","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayHttpHandler.cs#L87-L123","documentation":"TenPayHttpHandler's constructor requires the TenpayV3 setting to declare which certificate encryption type (EncryptionType) is used, because it determines how the merchant certificate is encrypted/processed for API v3 requests. If EncryptionType is null, the handler cannot proceed and throws WeixinException.","triggerScenarios":"Constructing TenPayHttpHandler with a SenparcWeixinSettingForTenpayV3 whose EncryptionType property is not set, or relying on the global Config.SenparcWeixinSetting.TenpayV3Setting which lacks EncryptionType.","commonSituations":"Developers migrating from TenPay V2 config blocks, copying old sample configs that predate the EncryptionType field, or forgetting to configure appsettings for TenpayV3Setting.","solutions":["Set EncryptionType on the TenpayV3Setting section (e.g. \"EncryptionType\": \"MD5\" or \"HMAC-SHA256\" per the SDK enum) in configuration","Explicitly pass a fully populated ISenparcWeixinSettingForTenpayV3 to the TenPayHttpHandler constructor","Register TenpayV3Setting via Config.SenparcWeixinSetting before constructing the handler","Check SenparcWeixinSetting.TenpayV3Setting.EncryptionType.HasValue before instantiating the handler"],"exampleFix":"// before\nvar handler = new TenPayHttpHandler();\n// after\nConfig.SenparcWeixinSetting.TenpayV3Setting.EncryptionType = EncryptionType.MD5;\nvar handler = new TenPayHttpHandler();","handlingStrategy":"validation","validationCode":"var setting = Config.SenparcWeixinSetting.TenpayV3Setting;\nif (setting is null || !setting.EncryptionType.HasValue)\n    throw new InvalidOperationException(\"TenpayV3Setting.EncryptionType 未配置。\");","typeGuard":"bool IsTenpayV3SettingValid(ISenparcWeixinSettingForTenpayV3 s) => s != null && s.EncryptionType.HasValue;","tryCatchPattern":null,"preventionTips":["Include EncryptionType in the TenpayV3Setting appsettings section from day one","Validate the whole TenpayV3Setting at application startup (fail fast)","Copy the latest official Senparc sample config when upgrading SDK versions"],"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"}