/// <summary> /// 轮询查询用户是否支付 /// </summary> /// <param name="outTradeNo">订单号</param> /// <param name="pollTime">轮询间隔</param> /// <param name="pollCount">轮询次数</param> /// <returns></returns> private QueryResponse PollQueryTradeState(string outTradeNo, int pollTime, int pollCount) { for (int i = 0; i < pollCount; i++) { var queryRequest = new QueryRequest(); queryRequest.AddGatewayData(new QueryModel { OutTradeNo = outTradeNo }); var queryResponse = SubmitProcess.Execute(_merchant, queryRequest); if (queryResponse.TradeState == "SUCCESS") { return(queryResponse); } Thread.Sleep(pollTime); } //支付超时,取消订单 var cancelRequest = new CancelRequest(); cancelRequest.AddGatewayData(new CancelModel { OutTradeNo = outTradeNo }); SubmitProcess.Execute(_merchant, cancelRequest); return(null); }
/// <summary> /// 轮询查询用户是否支付 /// </summary> /// <param name="outTradeNo">订单号</param> /// <param name="pollTime">轮询间隔</param> /// <param name="pollCount">轮询次数</param> /// <returns></returns> private QueryResponse PollQueryTradeState(string outTradeNo, int pollTime, int pollCount) { for (var i = 0; i < pollCount; i++) { var queryRequest = new QueryRequest(); queryRequest.AddGatewayData(new QueryModel { OutTradeNo = outTradeNo }); var queryResponse = SubmitProcess.Execute(_merchant, queryRequest); if (queryResponse.TradeStatus == "0000") { return(queryResponse); } Thread.Sleep(pollTime); } return(null); }