public void AddProfitsharingReceiverAsyncTest() { var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; var openId = "{openId}";//TODO: 此处填入分账接受个人的openid var requestData = new AddProfitsharingReceiverRequestData(TenPayV3Info.AppId, "MERCHANT_ID", openId, null, "CUSTOM", "SenparcUnitTest"); var profitsharingApis = new ProfitsharingApis(); try { // receiver.type为MERCHANT_ID时,receiver.name必填 _ = profitsharingApis.AddProfitsharingReceiverAsync(requestData).GetAwaiter().GetResult(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(TenpayApiRequestException)); Console.WriteLine(ex.Message); Assert.IsTrue(ex.Message.Contains("必填")); } // 修改数据 requestData.type = "PERSONAL_OPENID"; var result = profitsharingApis.AddProfitsharingReceiverAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 添加分账接收方接口测试结果:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }
/// <summary> /// 添加分账接收方接口 /// <para>商户发起添加分账接收方请求,建立分账接收方列表。后续可通过发起分账请求,将分账方商户结算后的资金,分到该分账接收方</para> /// <para>更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_8.shtml </para> /// </summary> /// <param name="data">微信支付需要POST的Data数据</param> /// <param name="timeOut">超时时间,单位为ms </param> /// <returns></returns> public async Task <AddProfitsharingReceiverReturnJson> AddProfitsharingReceiverAsync(AddProfitsharingReceiverRequestData data, int timeOut = Config.TIME_OUT) { // TODO: name 敏感信息加密 if (data.type == "MERCHANT_ID" && data.name == null) { throw new TenpayApiRequestException($"当 {nameof(data.type)} 为 {data.type} 时,{nameof(data.name)} 必填!"); } var url = ReurnPayApiUrl("https://api.mch.weixin.qq.com/{0}v3/profitsharing/receivers/add"); TenPayApiRequest tenPayApiRequest = new(_tenpayV3Setting); return(await tenPayApiRequest.RequestAsync <AddProfitsharingReceiverReturnJson>(url, data, timeOut)); }