{"record":{"id":"72307fa67f54b7d0","repo":"JeffreySu/WeiXinMPSDK","slug":"merchant-id-name","errorCode":null,"errorMessage":"接收方类型为 MERCHANT_ID 时，name 必填。","messagePattern":"接收方类型为 MERCHANT_ID 时，name 必填。","errorType":"validation","errorClass":"TenpayApiRequestException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/ChainBrandProfitsharing/ChainBrandProfitsharingApis.cs","lineNumber":75,"sourceCode":"        /// <para>官方文档：https://pay.weixin.qq.com/doc/v3/partner/4012692975</para>\n        /// </summary>\n        /// <param name=\"data\">品牌主、出资商户、订单和最多 50 个分账接收方。</param>\n        /// <param name=\"timeOut\">代理请求超时时间（毫秒）。</param>\n        /// <returns>分账单和各接收方执行结果。</returns>\n        public async Task<ChainBrandProfitsharingOrderResultJson>\n            CreateOrderAsync(\n                ChainBrandProfitsharingCreateOrderRequestData data,\n                int timeOut = Config.TIME_OUT)\n        {\n            _ = data ?? throw new ArgumentNullException(nameof(data));\n            var receivers = data.receivers ??\n                Array.Empty<ChainBrandProfitsharingReceiverRequestData>();\n            foreach (var receiver in receivers)\n            {\n                if (receiver?.type == \"MERCHANT_ID\" &&\n                    string.IsNullOrWhiteSpace(receiver.name))\n                {\n                    throw new TenpayApiRequestException(\n                        \"接收方类型为 MERCHANT_ID 时，name 必填。\");\n                }\n            }\n\n            var request = await CreateSensitiveRequestAsync(receivers\n                .Where(receiver => receiver != null &&\n                    !string.IsNullOrWhiteSpace(receiver.name))\n                .Cast<object>()).ConfigureAwait(false);\n            const string path = \"v3/brand/profitsharing/orders\";\n            return await request.RequestAsync<\n                ChainBrandProfitsharingOrderResultJson>(GetUrl(path), data,\n                timeOut).ConfigureAwait(false);\n        }\n\n        /// <summary>\n        /// 查询连锁品牌分账结果。\n        /// <para>官方文档：https://pay.weixin.qq.com/doc/v3/partner/4012467002</para>\n        /// </summary>","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/ChainBrandProfitsharing/ChainBrandProfitsharingApis.cs#L57-L93","documentation":"When adding profit-sharing receivers to a chain brand, a receiver whose type is MERCHANT_ID must carry a name (merchant name) per WeChat's API contract. CreateOrderAsync iterates the receivers collection and throws TenpayApiRequestException when any MERCHANT_ID receiver has a null/empty/whitespace name.","triggerScenarios":"Calling CreateOrderAsync with receivers containing an entry where type == \"MERCHANT_ID\" and name is null or empty; constructing receiver objects dynamically from DB rows missing the merchant name column.","commonSituations":"Syncing receivers from an external system where the name field is optional there but mandatory here; template code copying PERSONAL-type receivers (name optional) for MERCHANT_ID.","solutions":["Set the name field on every MERCHANT_ID receiver before calling.","Filter out or fix receivers with missing names in your service layer.","Use PERSONAL type instead of MERCHANT_ID when the receiver is an individual and name is truly unavailable."],"exampleFix":"// before\nnew ChainBrandProfitsharingReceiverRequestData { type = \"MERCHANT_ID\", account = mchId, name = null }\n// after\nnew ChainBrandProfitsharingReceiverRequestData { type = \"MERCHANT_ID\", account = mchId, name = \"商户全称\" }","handlingStrategy":"validation","validationCode":"foreach (var r in receivers.Where(r => r?.type == \"MERCHANT_ID\"))\n    if (string.IsNullOrWhiteSpace(r.name)) throw new ArgumentException($\"Receiver {r.account} needs a name.\");","typeGuard":"bool receiverValid(ChainBrandProfitsharingReceiverRequestData r) =>\n    r?.type != \"MERCHANT_ID\" || !string.IsNullOrWhiteSpace(r.name);","tryCatchPattern":"try { await apis.CreateOrderAsync(brandId, orderData, receivers); }\ncatch (TenpayApiRequestException ex) when (ex.Message.Contains(\"MERCHANT_ID\")) { logger.Warn(ex, \"Receiver missing name\"); throw new BusinessRuleException(\"Fill merchant name for all MERCHANT_ID receivers.\"); }","preventionTips":["Make the name field required in your receiver-creation UI for MERCHANT_ID type","Backfill missing merchant names when syncing receivers","Validate the whole receivers collection before any WeChat call"],"tags":["profitsharing","validation","wechat-pay"],"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"}