/// <summary> /// 同步服务订单信息接口 /// <para>由于收款商户进行的某些“线下操作”会导致微信支付侧的订单状态与实际情况不符。例如,用户通过线下付款的方式已经完成支付,而微信支付侧并未支付成功,此时可能导致用户重复支付。因此商户需要通过订单同步接口将订单状态同步给微信支付,修改订单在微信支付系统中的状态。</para> /// <para>特别说明:待支付(USER_PAYING)状态下,当用户正在尝试通过收银台主动支付订单金额时,同步服务订单信息API无法调用成功,可等待3min后重试</para> /// <para>更多详细请参考 https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_20.shtml </para> /// </summary> /// <param name="data">微信支付需要POST的Data数据</param> /// <param name="timeOut">超时时间,单位为ms</param> /// <returns></returns> public async Task <SyncPayServiceOrderReturnJson> SyncPayServiceOrderAsync(SyncPayServiceOrderRequestData data, int timeOut = Config.TIME_OUT) { if (data.type == "Order_Paid" && data.detail is null) { throw new TenpayApiRequestException($"{nameof(data.type)}为'Order_Paid'与{nameof(data.detail)}"); } var url = ReurnPayApiUrl($"https://api.mch.weixin.qq.com/{{0}}v3/payscore/serviceorder/{data.out_order_no}/sync"); TenPayApiRequest tenPayApiRequest = new(_tenpayV3Setting); return(await tenPayApiRequest.RequestAsync <SyncPayServiceOrderReturnJson>(url, data, timeOut)); }
/// <summary> /// 同步服务订单信息测试 /// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_20.shtml /// </summary> public void SyncPayServiceOrderAsyncTest() { //如果未创建支付分订单 则创建支付分订单 if (createServiceOrderResult is null) { CreateServiceOrderAsyncTest(); } var key = TenPayHelper.GetRegisterKey(Config.SenparcWeixinSetting); var TenPayV3Info = TenPayV3InfoCollection.Data[key]; var requestData = new SyncPayServiceOrderRequestData(createServiceOrderResult.out_order_no, TenPayV3Info.AppId, createServiceOrderResult.service_id, "Order_Paid", null); PayScoreApis payScoreApis = new PayScoreApis(); try { // 场景类型为Order_Paid时,为必填项。 _ = payScoreApis.QueryServiceOrderAsync(null, null, createServiceOrderResult.service_id, TenPayV3Info.AppId).GetAwaiter().GetResult(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(TenpayApiRequestException)); Console.WriteLine(ex.Message); Assert.IsTrue(ex.Message.Contains("必填")); } //修正参数 requestData.detail = new(new TenpayDateTime(DateTime.Now)); var result = payScoreApis.SyncPayServiceOrderAsync(requestData).GetAwaiter().GetResult(); Console.WriteLine("微信支付 V3 同步服务订单信息测试:" + result.ToJson(true)); Assert.IsNotNull(result); Assert.IsTrue(result.ResultCode.Success); Assert.IsTrue(result.VerifySignSuccess == true);//通过验证 }