{"record":{"id":"bcda7a488f26baf9","repo":"JeffreySu/WeiXinMPSDK","slug":"nameof-data-type-data-type-nameof-data-name","errorCode":null,"errorMessage":"当 {nameof(data.type)} 为 {data.type} 时，{nameof(data.name)} 必填！","messagePattern":"当 (.+?) 为 (.+?) 时，(.+?) 必填！","errorType":"validation","errorClass":"TenpayApiRequestException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/Profitsharing/ProfitsharingApis.cs","lineNumber":320,"sourceCode":"            TenPayApiRequest tenPayApiRequest = new(_tenpayV3Setting);\n            return await tenPayApiRequest.RequestAsync<FinishProfitsharingReturnJson>(url, data, timeOut);\n        }\n\n        /// <summary>\n        /// 添加分账接收方接口\n        /// <para>商户发起添加分账接收方请求，建立分账接收方列表。后续可通过发起分账请求，将分账方商户结算后的资金，分到该分账接收方</para>\n        /// <para>普通商户 更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_8.shtml </para>\n        /// <para>服务商 更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_8.shtml </para>\n        /// <para>服务商连锁品牌 更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_7_7.shtml</para>\n        /// </summary>\n        /// <param name=\"data\">微信支付请求数据</param>\n        /// <param name=\"timeOut\">超时时间，单位为ms </param>\n        /// <returns></returns>\n        public async Task<AddProfitsharingReceiverReturnJson> AddProfitsharingReceiverAsync(AddProfitsharingReceiverRequestData data, int timeOut = Config.TIME_OUT)\n        {\n            if (data.type == \"MERCHANT_ID\" && data.name == null)\n            {\n                throw new TenpayApiRequestException($\"当 {nameof(data.type)} 为 {data.type} 时，{nameof(data.name)} 必填！\");\n            }\n\n            // name加密\n            var basePayApis = new BasePayApis(_tenpayV3Setting);\n            var publicKeys = await basePayApis.GetPublicKeysAsync();\n            var publicKeyKv = publicKeys.FirstOrDefault();\n            SecurityHelper.FieldEncrypt(data, publicKeyKv.Value, _tenpayV3Setting.EncryptionType.Value, _tenpayV3Setting.TenPayV3_TenPayPubKeyEnable);\n\n            //string algorithmType = _tenpayV3Setting.EncryptionType == CertType.SM.ToString() ? \"SM2\" : \"RSA\";\n            //var certificateResponse = await basePayApis.CertificatesAsync(algorithmType);\n            //SecurityHelper.FieldEncrypt(data, certificateResponse, _tenpayV3Setting.TenPayV3_APIv3Key, _tenpayV3Setting.EncryptionType);\n\n            var url = ReurnPayApiUrl(Senparc.Weixin.Config.TenPayV3Host + \"/{0}v3/{1}profitsharing/receivers/add\", data.brand_mchid);\n            TenPayApiRequest tenPayApiRequest = new(_tenpayV3Setting, httpClient =>\n            {\n                httpClient.DefaultRequestHeaders.Add(\"Wechatpay-Serial\", publicKeyKv.Key);\n            });\n            return await tenPayApiRequest.RequestAsync<AddProfitsharingReceiverReturnJson>(url, data, timeOut);","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/Profitsharing/ProfitsharingApis.cs#L302-L338","documentation":"AddProfitsharingReceiverAsync validates the AddProfitsharingReceiverRequestData: if type is \"MERCHANT_ID\" the merchant name (name) is mandatory; when it is null, TenpayApiRequestException is thrown indicating data.name must be filled.","triggerScenarios":"Calling AddProfitsharingReceiverAsync to register a profit-sharing receiver with type=\"MERCHANT_ID\" and name==null. Types like \"PERSONAL_OPENID\" don't trigger this check.","commonSituations":"Onboarding sub-merchants for profit sharing where the DB record lacks the merchant full name, or using deserialized request data where name was not supplied by the client.","solutions":["Provide data.name with the merchant's full registered name when type is \"MERCHANT_ID\".","Add pre-call validation on your request DTO before invoking the API.","Only omit name for receiver types that don't require it (e.g. PERSONAL_OPENID)."],"exampleFix":"// before\nvar data = new AddProfitsharingReceiverRequestData { type = \"MERCHANT_ID\", account = \"819321922\" };\n// after\nvar data = new AddProfitsharingReceiverRequestData { type = \"MERCHANT_ID\", account = \"819321922\", name = \"商户全称\" };","handlingStrategy":"validation","validationCode":"if (data.type == \"MERCHANT_ID\" && string.IsNullOrEmpty(data.name))\n    throw new InvalidOperationException(\"MERCHANT_ID 分账接收方必须提供 name\");","typeGuard":null,"tryCatchPattern":"try { await apis.AddProfitsharingReceiverAsync(data); }\ncatch (TenpayApiRequestException ex) { logger.Error(ex, \"添加分账接收方失败\"); }","preventionTips":["Fill name for MERCHANT_ID receivers when onboarding sub-merchants","Add unit tests covering receiver validation rules","Reject incomplete receiver payloads before reaching the SDK"],"tags":["validation","profitsharing","required-field","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"}