JeffreySu/WeiXinMPSDK · error · TenpayApiRequestException
当 为 时, 必填!
Error message
当 {nameof(each.type)} 为 {each.type} 时,{nameof(each.name)} 必填! What it means
CreateProfitsharingAsync validates each entry in data.receivers before the profit-sharing request. When a receiver's type is "MERCHANT_ID", WeChat Pay requires the merchant name; if name is null a TenpayApiRequestException is thrown naming the type and field.
Solutions
- Set each.receiver.name to the merchant's registered name when type is "MERCHANT_ID".
- Filter or fix receivers entries before constructing CreateProfitsharingRequestData.
- Wrap the call in try-catch for TenpayApiRequestException if receivers are user-supplied.
Example fix
// before
receivers: new[] { new CreateProfitsharingReceiver { type = "MERCHANT_ID", account = "819321922", amount = 100 } }
// after
receivers: new[] { new CreateProfitsharingReceiver { type = "MERCHANT_ID", account = "819321922", name = "商户全称", amount = 100 } } Defensive patterns
Strategy: validation
Validate before calling
foreach (var r in receivers)
if (r.type == "MERCHANT_ID" && string.IsNullOrEmpty(r.name))
throw new InvalidOperationException($"receiver {r.account} 需要填写 name (MERCHANT_ID)"); Try / catch
try { await apis.CreateProfitsharingAsync(data); }
catch (TenpayApiRequestException ex) { logger.Error(ex, "分账参数校验失败"); } Prevention
- Validate receiver DTOs at your API boundary before calling the SDK
- Keep merchant full name stored alongside merchant ID in your DB
- Remember name is only required for MERCHANT_ID type
When it happens
Trigger: Calling CreateProfitsharingAsync with a receivers array containing an item with type="MERCHANT_ID" and name==null; note other types (e.g. "PERSONAL_OPENID") do not require name.
Common situations: Building CreateProfitsharingRequestData dynamically where name is only filled for personal receivers, or copying sample code that omits the merchant name field.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/cd22295806dbbc56.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/Profitsharing/ProfitsharingApis.cs:108
#region 分账接口
/// <summary>
/// 请求分账接口
/// <para>微信订单支付成功后,商户发起分账请求,将结算后的资金分到分账接收方</para>
/// <para>普通商户 更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_1.shtml </para>
/// <para>服务商 更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_1.shtml </para>
/// <para>服务商连锁商户 更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_7_1.shtml </para>
/// </summary>
/// <param name="data">微信支付请求数据</param>
/// <param name="timeOut">超时时间,单位为ms</param>
/// <returns></returns>
public async Task<CreateProfitsharingReturnJson> CreateProfitsharingAsync(CreateProfitsharingRequestData data, int timeOut = Config.TIME_OUT)
{
foreach (var each in data.receivers)
{
if (each.type == "MERCHANT_ID" && each.name == null)
{
throw new TenpayApiRequestException($"当 {nameof(each.type)} 为 {each.type} 时,{nameof(each.name)} 必填!");
}
}
// name加密
var basePayApis = new BasePayApis(_tenpayV3Setting);
var publicKeys = await basePayApis.GetPublicKeysAsync();
var publicKeyKv = publicKeys.FirstOrDefault();
foreach (var each in data.receivers)
{
SecurityHelper.FieldEncrypt(each, publicKeyKv.Value, _tenpayV3Setting.EncryptionType.Value, _tenpayV3Setting.TenPayV3_TenPayPubKeyEnable);
}
//string algorithmType = _tenpayV3Setting.EncryptionType == CertType.SM.ToString() ? "SM2" : "RSA";
//var certificateResponse = await basePayApis.CertificatesAsync(algorithmType);
//foreach (var each in data.receivers)
//{
// SecurityHelper.FieldEncrypt(each, certificateResponse, _tenpayV3Setting.TenPayV3_APIv3Key, _tenpayV3Setting.EncryptionType);
//}View on GitHub (pinned to be573f6f94)