{"record":{"id":"d8eb2744e9f0a1fc","repo":"JeffreySu/WeiXinMPSDK","slug":"tenpayv3info","errorCode":null,"errorMessage":"tenPayV3Info 参数不能为空！","messagePattern":"tenPayV3Info 参数不能为空！","errorType":"exception","errorClass":"TenpayApiRequestException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Helpers/TenPaySignHelper.cs","lineNumber":315,"sourceCode":"        /// <param name=\"prepayId\">预支付交易会话标识。</param>\n        /// <param name=\"tenPayV3Info\">微信支付 V3 配置信息。</param>\n        /// <returns></returns>\n        [Obsolete(\"v2.4.0 起该方法已过时，请使用 GetJsApiUiPackage(string prepayId, TenPayV3Info tenPayV3Info, JsApiAppType? appType) 方法。\")]\n        public static JsApiUiPackage GetJsApiUiPackage(string prepayId, TenPayV3Info tenPayV3Info)\n            => GetJsApiUiPackage(prepayId, tenPayV3Info, JsApiAppType.WxOpen);\n\n        /// <summary>\n        /// 获取给 JsApi UI 使用的打包签名信息\n        /// </summary>\n        /// <param name=\"prepayId\">预支付交易会话标识。</param>\n        /// <param name=\"tenPayV3Info\">微信支付 V3 配置信息。</param>\n        /// <param name=\"appType\">应用类型（小程序或原生 App）。</param>\n        /// <returns></returns>\n        public static JsApiUiPackage GetJsApiUiPackage(string prepayId, TenPayV3Info tenPayV3Info, JsApiAppType appType = JsApiAppType.WxOpen)\n        {\n            if (tenPayV3Info == null)\n            {\n                throw new Senparc.Weixin.TenPayV3.TenpayApiRequestException(\"tenPayV3Info 参数不能为空！\");\n            }\n\n            var timeStamp = TenPayV3Util.GetTimestamp();\n            var nonceStr = TenPayV3Util.GetNoncestr();\n            var prepayIdPackage = GetPrepayIdPackage(prepayId, appType);\n            var sign = TenPaySignHelper.CreatePaySign(timeStamp, nonceStr, prepayIdPackage, tenPayV3Info);\n\n            JsApiUiPackage jsApiUiPackage = new(tenPayV3Info.AppId, timeStamp, nonceStr, prepayIdPackage, sign);\n            return jsApiUiPackage;\n        }\n\n        /// <summary>\n        /// 根据微信小程序或原生 APP 定义不同格式的 prepayId 签名字符串\n        /// </summary>\n        /// <param name=\"prepayId\"></param>\n        /// <param name=\"appType\"></param>\n        /// <returns></returns>\n        private static string GetPrepayIdPackage(string prepayId, JsApiAppType appType)","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Helpers/TenPaySignHelper.cs#L297-L333","documentation":"This obsolete overload of GetJsApiUiPackage (deprecated since v2.4.0 in favor of the overload taking JsApiAppType) requires a populated TenPayV3Info configuration object containing appid, mch_id, key etc. to compute the JsApi pay-sign package. It throws when the tenPayV3Info argument is null, since no signature can be produced without the merchant's V3 credentials. The fix is for callers to pass a valid TenPayV3Info instance (e.g. TenPayV3InfoCollection.Data).","triggerScenarios":"Calling GetJsApiUiPackage(prepayId, null) — usually because TenPayV3InfoCollection.Data[key] lookup returned nothing or a variable holding TenPayV3Info was never initialized.","commonSituations":"Merchant info not registered via TenPayV3InfoCollection.Register; using the wrong mchId register key so the lookup path produces null; refactoring code where the info object was removed.","solutions":["Ensure TenPayV3Info is registered/obtained before the call: TenPayV3InfoCollection.Register(...) and fetch from TenPayV3InfoCollection.Data[registerKey]","Add a null check or assertion at the call site","Pass the TenPayV3Info instance from DI or a config-backed factory instead of a local variable"],"exampleFix":"// before\nTenPayV3Info info = null;\nvar package = TenPaySignHelper.GetJsApiUiPackage(prepayId, info);\n// after\nvar info = TenPayV3InfoCollection.Data[TenPayHelper.GetRegisterKey(mchId, subMchId)];\nvar package = TenPaySignHelper.GetJsApiUiPackage(prepayId, info);","handlingStrategy":"validation","validationCode":"if (tenPayV3Info == null)\n    throw new InvalidOperationException(\"TenPayV3Info 未初始化：请先 TenPayV3InfoCollection.Register\");","typeGuard":"bool HasTenpayInfo(string mchId, string subMchId) => TenPayV3InfoCollection.Data.ContainsKey(TenPayHelper.GetRegisterKey(mchId, subMchId));","tryCatchPattern":"try { var pkg = TenPaySignHelper.GetJsApiUiPackage(prepayId, info); }\ncatch (TenpayApiRequestException ex) { log.Error(\"tenPayV3Info 为空\", ex); throw new AppConfigException(\"商户信息未注册\", ex); }","preventionTips":["Register all merchants at app startup with TenPayV3InfoCollection.Register","Fetch TenPayV3Info from TenPayV3InfoCollection.Data by register key, never pass ad-hoc nulls","Enable nullable reference types so null passing is caught at compile time"],"tags":["wechat-pay","tenpay-v3","null-argument"],"backgroundTag":"null-argument","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"}