/// <summary> /// 完结支付分订单接口 /// <para>完结微信支付分订单。用户使用服务完成后,商户可通过此接口完结订单。</para> /// <para>特别说明:完结接口调用成功后,微信支付将自动发起免密代扣。 若扣款失败,微信支付将自动再次发起免密代扣(按照一定频次),直到扣成功为止。</para> /// <para>更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_18.shtml </para> /// </summary> /// <param name="data">微信支付需要POST的Data数据</param> /// <param name="timeOut">超时时间,单位为ms</param> /// <returns></returns> public async Task <CompleteServiceOrderReturnJson> CompleteServiceOrderAsync(CompleteServiceOrderRequestData data, int timeOut = Config.TIME_OUT) { var url = ReurnPayApiUrl($"https://api.mch.weixin.qq.com/{{0}}v3/payscore/serviceorder/{data.out_order_no}/complete"); TenPayApiRequest tenPayApiRequest = new(_tenpayV3Setting); return(await tenPayApiRequest.RequestAsync <CompleteServiceOrderReturnJson>(url, data, timeOut)); }
/// <summary> /// 完结支付分订单测试 /// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_18.shtml /// </summary> public void CompleteServiceOrderAsyncTest() { //如果未创建支付分订单 则创建支付分订单 if (createServiceOrderResult is null) { CreateServiceOrderAsyncTest(); } var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; //服务时间段 var time_range = new CompleteServiceOrderRequestData.Time_Range(new TenpayDateTime(DateTime.Now), null, new TenpayDateTime(DateTime.Now.AddDays(1)), null); //付款项目列表 var post_payments = new CompleteServiceOrderRequestData.Post_Payment[] { new CompleteServiceOrderRequestData.Post_Payment("SenparcUnitTest名称测试", 1, "单元测试1分", null) }; var requestData = new CompleteServiceOrderRequestData(createServiceOrderResult.out_order_no, TenPayV3Info.AppId, createServiceOrderResult.service_id, post_payments, null, 1, time_range, null, null, null); PayScoreApis payScoreApis = new PayScoreApis(); var result = payScoreApis.CompleteServiceOrderAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 完结支付分订单测试:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }