{"record":{"id":"7c8cf50bc69064a3","repo":"JeffreySu/WeiXinMPSDK","slug":"out-trade-no-transaction-id-sub-order-no-sub-order-id","errorCode":null,"errorMessage":"out_trade_no、transaction_id、sub_order_no 和 sub_order_id 至少填写一个。","messagePattern":"out_trade_no、transaction_id、sub_order_no 和 sub_order_id 至少填写一个。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/CustomsRequestData.cs","lineNumber":190,"sourceCode":"        /// <summary>微信支付订单号，与其他订单标识至少填写一个。</summary>\n        public string transaction_id { get; set; }\n\n        /// <summary>商户子订单号，与其他订单标识至少填写一个。</summary>\n        public string sub_order_no { get; set; }\n\n        /// <summary>微信子订单号，与其他订单标识至少填写一个。</summary>\n        public string sub_order_id { get; set; }\n\n        /// <inheritdoc />\n        protected override void Validate(string key)\n        {\n            base.Validate(key);\n            if (string.IsNullOrWhiteSpace(out_trade_no) &&\n                string.IsNullOrWhiteSpace(transaction_id) &&\n                string.IsNullOrWhiteSpace(sub_order_no) &&\n                string.IsNullOrWhiteSpace(sub_order_id))\n            {\n                throw new ArgumentException(\n                    \"out_trade_no、transaction_id、sub_order_no 和 sub_order_id 至少填写一个。\");\n            }\n        }\n\n        /// <inheritdoc />\n        protected override void SetParameters(RequestHandler handler)\n        {\n            base.SetParameters(handler);\n            handler.SetParameterWhenNotNull(\"sign_type\", sign_type);\n            handler.SetParameterWhenNotNull(\"out_trade_no\", out_trade_no);\n            handler.SetParameterWhenNotNull(\"transaction_id\", transaction_id);\n            handler.SetParameterWhenNotNull(\"sub_order_no\", sub_order_no);\n            handler.SetParameterWhenNotNull(\"sub_order_id\", sub_order_id);\n        }\n    }\n\n    /// <summary>\n    /// 海关重新申报请求。","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/CustomsRequestData.cs#L172-L208","documentation":"Validate() on the base customs request data requires at least one order identifier: out_trade_no, transaction_id, sub_order_no, or sub_order_id. If all four are null/empty, an ArgumentException with this message is thrown. WeChat Pay's customs APIs identify the order by at least one of these keys.","triggerScenarios":"Constructing a customs declare/query/redeclare request and calling the API (Validate runs before SetParameters) without populating any of the four order identifier fields.","commonSituations":"Developers intend to query by WeChat transaction_id but the value came back null from their own order system, or they only set order fields for the domestic side (sub-order fields) and none of the four accepted identifiers.","solutions":["Set out_trade_no (merchant order number) — the most common identifier.","Alternatively set transaction_id (WeChat payment transaction id), or sub_order_no/sub_order_id for split orders.","Ensure at least one is non-whitespace before calling the customs API."],"exampleFix":"// before\nvar data = new CustomsDeclareQueryRequestData(key, appid, mch_id, mch_customs_no, null, null, null, null);\n// after\nvar data = new CustomsDeclareQueryRequestData(key, appid, mch_id, mch_customs_no, outTradeNo /* out_trade_no */, null, null, null);","handlingStrategy":"validation","validationCode":"// C#\nbool hasOrderKey = new[]{ outTradeNo, transactionId, subOrderNo, subOrderId }.Any(s => !string.IsNullOrWhiteSpace(s));\nif (!hasOrderKey) throw new InvalidOperationException(\"Provide at least one order identifier for customs request\");","typeGuard":null,"tryCatchPattern":"try { await tenPayV3.CustomsDeclareQueryAsync(data); }\ncatch (ArgumentException ex) { log.LogWarning(\"Customs request missing order identifier: {Msg}\", ex.Message); }","preventionTips":["Persist at least out_trade_no for every paid order before customs declaration","Prefer out_trade_no as the canonical identifier","Assert identifier presence in your payment-success handler"],"tags":["argument-validation","weixin-tenpay","customs"],"backgroundTag":"missing-required-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"}