//public static OrderQueryMessage OrderQuery(string postData) //{ // var accessToken = AccessToken.Instance; // string url = string.Format(WeiXinConst.WeiXin_Pay_OrderQueryUrl, accessToken.Access_Token); // OrderQueryMessage result = WeiXin.Lib.Core.Helper.HttpClientHelper.PostResponse<OrderQueryMessage>(url, postData); // if (result.TokenExpired) // { // return OrderQueryByNewAccessToken(postData); // } // return result; //} //private static OrderQueryMessage OrderQueryByNewAccessToken(string postData) //{ // var accessToken = AccessToken.NewInstance; // string url = string.Format(WeiXinConst.WeiXin_Pay_OrderQueryUrl, accessToken.Access_Token); // OrderQueryMessage result = WeiXin.Lib.Core.Helper.HttpClientHelper.PostResponse<OrderQueryMessage>(url, postData); // return result; //} #endregion #region V3 订单查询 /// <summary> /// V3 统一订单查询接口 /// </summary> /// <param name="postXml"></param> /// <returns></returns> public static UnifiedOrderQueryMessage UnifiedOrderQuery(string postXml) { string url = WeiXinConst.WeiXin_Pay_UnifiedOrderQueryUrl; UnifiedOrderQueryMessage message = HttpClientHelper.PostXmlResponse <UnifiedOrderQueryMessage>(url, postXml); return(message); }
public static bool SyncPaymentResult(decimal orderId) { IOnlineOrder factory = OnlineOrderFactory.GetFactory(); OnlineOrder order = factory.QueryByOrderId(orderId); if (order.PaymentChannel != PaymentChannel.WeiXinPay && order.PaymentChannel == PaymentChannel.AliPay) { throw new MyException("目前只能同步微信或支付宝的支付结果"); } if (order.Status != OnlineOrderStatus.WaitPay && order.Status != OnlineOrderStatus.Paying) { throw new MyException("只有待支付或支付中的订单才能同步"); } switch (order.PaymentChannel) { case PaymentChannel.WeiXinPay: { UnifiedOrderQueryMessage result = PaymentServices.UnifiedOrderQuery(order.CompanyID, order.SerialNumber, order.OrderID.ToString()); if (result.Success) { DateTime payTime = GetConversionWeiXinPayTime(result.Tiem_End); return(PaySuccess(orderId, result.TransactionId, payTime)); } if (result.Return_Code.ToUpper() != "SUCCESS") { throw new MyException(string.Format("同步失败:{0}", result.Return_Msg)); } if (result.Result_Code.ToUpper() != "SUCCESS") { throw new MyException(string.Format("同步失败:【{0}】{1}", result.Err_Code, result.Err_Code_Des)); } if (result.Trade_State.ToUpper() != "SUCCESS") { throw new MyException(string.Format("同步失败:{0}", GetWeiXinPayOrderErrorStateDes(result.Trade_State))); } break; } case PaymentChannel.AliPay: { DateTime payTime = DateTime.Now; bool result = AliPayApiServices.QueryPayResult(order.CompanyID, order.OrderID.ToString(), order.PrepayId, out payTime); if (result) { return(PaySuccess(orderId, order.PrepayId, payTime)); } else { throw new MyException("该订单未支付"); } } default: throw new MyException("支付通道不正确"); } return(false); }
/// <summary> /// V3 统一订单查询接口 /// </summary> /// <param name="postXml"></param> /// <returns></returns> public static UnifiedOrderQueryMessage UnifiedOrderQuery(string companyId, string transactionId, string orderId) { UnifiedPayModel model = UnifiedPayModel.CreateUnifiedModel(companyId); string postXml = model.CreateOrderQueryXml(transactionId, orderId); string url = WeiXinPayConst.WeiXin_Pay_UnifiedOrderQueryUrl; UnifiedOrderQueryMessage message = HttpHelper.PostXmlResponse <UnifiedOrderQueryMessage>(url, postXml); return(message); }
/// <summary> /// 到微信服务器查询 订单支付的结果 (jsapi支付返回ok,我们要判断下服务器支付状态,如果没有支付成功,到微信服务器查询) /// </summary> /// <param name="orderNo"></param> public bool QueryOrder(string orderNo) { //这里应先判断服务器 订单支付状态,如果接到通知,并已经支付成功,就不用 执行下面的查询了 UnifiedWxPayModel model = UnifiedWxPayModel.CreateUnifiedModel(WeiXinConst.AppId, WeiXinConst.PartnerId, WeiXinConst.PartnerKey); UnifiedOrderQueryMessage message = WeiXinHelper.UnifiedOrderQuery(model.CreateOrderQueryXml(orderNo)); //此处主动查询的结果,只做查询用(不能作为支付成功的依据) return(message.Success); }