{"record":{"id":"0bcfd57e28175574","repo":"JeffreySu/WeiXinMPSDK","slug":"encryptiontype-tenpaysignhelper","errorCode":null,"errorMessage":"没有设置证书加密类型（EncryptionType）","messagePattern":"没有设置证书加密类型（EncryptionType）","errorType":"exception","errorClass":"WeixinException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Helpers/TenPaySignHelper.cs","lineNumber":144,"sourceCode":"            return CreatePaySign(timeStamp, nonceStr, package, new TenPayV3Info(senparcWeixinSettingForTenpayV3));\n        }\n\n        /// <summary>\n        /// 获取调起支付所需的签名\n        /// </summary>\n        /// <param name=\"timeStamp\">时间戳</param>\n        /// <param name=\"nonceStr\">随机串</param>\n        /// <param name=\"package\">格式：prepay_id={0}</param>\n        /// <param name=\"tenPayV3Info\">支付配置信息（TenPayV3Info）</param>\n        /// <returns></returns>\n        public static string CreatePaySign(string timeStamp, string nonceStr, string package, TenPayV3Info tenPayV3Info)\n        {\n            var appId = tenPayV3Info.AppId;\n            var privateKey = tenPayV3Info.TenPayV3_PrivateKey;\n\n            if (!tenPayV3Info.TenPayV3_CertType.HasValue)\n            {\n                throw new Senparc.Weixin.Exceptions.WeixinException(\"没有设置证书加密类型（EncryptionType）\");\n            }\n\n            return CreatePaySign(timeStamp, nonceStr, package, appId, privateKey, tenPayV3Info.TenPayV3_CertType.Value);\n        }\n\n        /// <summary>\n        /// 获取调起支付所需的签名\n        /// </summary>\n        /// <param name=\"timeStamp\">时间戳</param>\n        /// <param name=\"nonceStr\">随机串</param>\n        /// <param name=\"package\">格式：prepay_id={0}</param>\n        /// <param name=\"privateKey\">商户证书私钥</param>\n        /// <returns></returns>\n        public static string CreatePaySign(string timeStamp, string nonceStr, string package, string appId, string privateKey, CertType certType)\n        {\n            string contentForSign = $\"{appId}\\n{timeStamp}\\n{nonceStr}\\n{package}\\n\";\n            return CreateSign(certType, contentForSign, privateKey);\n        }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Helpers/TenPaySignHelper.cs#L126-L162","documentation":"TenPaySignHelper.CreatePaySign builds JSAPI pay signatures and needs to know the certificate/encryption type (TenPayV3_CertType, e.g. RSA vs SM2). If TenPayV3Info.TenPayV3_CertType is not set, a WeixinException is thrown.","triggerScenarios":"Calling CreatePaySign when the TenPayV3Setting/TenPayV3Info used to construct tenPayV3Info was created without specifying TenPayV3_CertType (null), typically after upgrading to a Senparc version where CertType became mandatory.","commonSituations":"Older configuration code that predates the CertType field, or config loaded from legacy sources that don't include the certificate type.","solutions":["Set TenPayV3_CertType on your TenPayV3Setting (e.g. TenPayV3CertType.RSA) when initializing config.","Update configuration initialization code to the current Senparc TenPayV3 setup API.","If using SM2 merchant, set the corresponding cert type so signing uses the right algorithm."],"exampleFix":"// before\nvar tenPayV3Info = new TenPayV3Info(appId, mchId, key, appSecret, certPath, certPassword);\n// after\nvar tenPayV3Info = new TenPayV3Info(appId, mchId, key, appSecret, certPath, certPassword);\ntenPayV3Info.TenPayV3_CertType = TenPayV3CertType.RSA;","handlingStrategy":"try-catch","validationCode":"if (tenPayV3Info.TenPayV3_CertType == null)\n    throw new InvalidOperationException(\"请先设置 TenPayV3_CertType (RSA/SM2)\");","typeGuard":null,"tryCatchPattern":"try { var sign = TenPaySignHelper.CreatePaySign(timeStamp, nonceStr, package, tenPayV3Info); }\ncatch (WeixinException ex) { logger.Error(ex, \"证书类型未配置\"); }","preventionTips":["Set TenPayV3_CertType when constructing TenPayV3Setting","Update legacy config builders after Senparc upgrades","Validate TenPayV3Info completeness at application startup"],"tags":["configuration","wechat-pay","signing","missing-config"],"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"}