{"record":{"id":"f7177ac6b3b7359d","repo":"JeffreySu/WeiXinMPSDK","slug":"encryptiontype","errorCode":null,"errorMessage":"没有设置证书加密类型（EncryptionType）","messagePattern":"没有设置证书加密类型（EncryptionType）","errorType":"exception","errorClass":"Senparc.Weixin.Exceptions.WeixinException","httpStatus":null,"severity":"critical","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/BasePay/BasePayApis.cs","lineNumber":99,"sourceCode":"\nnamespace Senparc.Weixin.TenPayV3.Apis\n{\n    public partial class BasePayApis\n    {\n\n        private ISenparcWeixinSettingForTenpayV3 _tenpayV3Setting;\n\n        /// <summary>\n        /// 构造函数\n        /// </summary>\n        /// <param name=\"senparcWeixinSettingForTenpayV3\"></param>\n        public BasePayApis(ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null)\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        //private readonly IServiceProvider _serviceProvider;\n\n        //public BasePayApis(IServiceProvider serviceProvider)\n        //{\n        //    this._serviceProvider = serviceProvider;\n        //}\n\n        /// <summary>\n        /// 返回可用的微信支付地址（自动判断是否使用沙箱）\n        /// </summary>\n        /// <param name=\"urlFormat\">如：<code>https://api.mch.weixin.qq.com/{0}pay/unifiedorder</code></param>\n        /// <returns></returns>\n        internal static string GetPayApiUrl(string urlFormat, string sp_mchid = \"\")\n        {\n            //注意：目前微信支付 V3 还没有支持沙箱，此处只是预留","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/BasePay/BasePayApis.cs#L81-L117","documentation":"BasePayApis' constructor validates the TenpayV3SenparcWeixinSetting and throws a WeixinException when the EncryptionType property has no value. EncryptionType (e.g. RSA with public/private key) is required to encrypt sensitive fields for WeChat Pay v3, so the client cannot operate without it.","triggerScenarios":"Instantiating BasePayApis with a settings object where EncryptionType is not assigned — e.g. config JSON/appsettings missing the EncryptionType field, or constructing ISenparcWeixinSettingForTenpayV3 in code without setting it.","commonSituations":"Upgrading from older SDK versions that had no EncryptionType property and not updating config; incomplete appsettings sections; copying config templates that omit the new field.","solutions":["Set EncryptionType in your TenpayV3Setting configuration (e.g. \"EncryptionType\": \"RSA\").","Verify Config.SenparcWeixinSetting.TenpayV3Setting is fully populated before constructing BasePayApis.","If passing a custom ISenparcWeixinSettingForTenpayV3, explicitly assign EncryptionType in the initializer."],"exampleFix":"// before\nvar setting = new TenpayV3SenparcWeixinSetting { AppId = appId, MchId = mchId };\nvar apis = new BasePayApis(setting);\n// after\nvar setting = new TenpayV3SenparcWeixinSetting { AppId = appId, MchId = mchId, EncryptionType = EncryptionTypeEnum.RSA };\nvar apis = new BasePayApis(setting);","handlingStrategy":"validation","validationCode":"if (setting.EncryptionType is null)\n    throw new InvalidOperationException(\"TenpayV3Setting.EncryptionType must be set before creating BasePayApis.\");","typeGuard":"bool encryptionConfigured = setting?.EncryptionType is { };","tryCatchPattern":"try { var apis = new BasePayApis(setting); }\ncatch (WeixinException ex) { logger.Fatal(ex, \"EncryptionType missing from TenpayV3Setting\"); throw; }","preventionTips":["Bind full TenpayV3 config from appsettings with startup-time validation","Set EncryptionType wherever you construct settings in code","Fail fast at application startup by constructing clients once and catching config errors"],"tags":["config","wechat-pay","initialization"],"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"}