/// <summary> /// 查询订单 /// ResultNotify.QueryOrder /// </summary> /// <param name="transaction_id"></param> /// <returns></returns> private static bool QueryResultOrder(string transaction_id) { WxPayData req = new WxPayData(); req.SetValue("transaction_id", transaction_id); WxPayData res = WxPayApi.OrderQuery(req); return(res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS"); }
/// <summary> /// 订单查询完整业务流程逻辑 /// OrderQuery.Run /// </summary> /// <param name="transaction_id">微信订单号(优先使用)</param> /// <param name="out_trade_no">商户订单号</param> /// <returns>订单查询结果(xml格式)</returns> public static string OrderQuery(string transaction_id, string out_trade_no) { WxPayLog.Info("OrderQuery", "OrderQuery is processing..."); WxPayData data = new WxPayData(); if (!string.IsNullOrEmpty(transaction_id))//如果微信订单号存在,则以微信订单号为准 { data.SetValue("transaction_id", transaction_id); } else//微信订单号不存在,才根据商户订单号去查单 { data.SetValue("out_trade_no", out_trade_no); } WxPayData result = WxPayApi.OrderQuery(data);//提交订单查询请求给API,接收返回数据 WxPayLog.Info("OrderQuery", "OrderQuery process complete, result : " + result.ToXml()); return(result.ToPrintStr()); }
/// <summary> /// 查询订单情况 /// MicroPay.Query /// </summary> /// <param name="out_trade_no">商户订单号</param> /// <param name="succCode">查询订单结果:0表示订单不成功,1表示订单成功,2表示继续查询</param> /// <returns>订单查询接口返回的数据,参见协议接口</returns> public static WxPayData MicroPayQuery(string out_trade_no, out int succCode) { WxPayData queryOrderInput = new WxPayData(); queryOrderInput.SetValue("out_trade_no", out_trade_no); WxPayData result = WxPayApi.OrderQuery(queryOrderInput); if (result.GetValue("return_code").ToString() == "SUCCESS" && result.GetValue("result_code").ToString() == "SUCCESS") { //支付成功 if (result.GetValue("trade_state").ToString() == "SUCCESS") { succCode = 1; return(result); } //用户支付中,需要继续查询 else if (result.GetValue("trade_state").ToString() == "USERPAYING") { succCode = 2; return(result); } } //如果返回错误码为“此交易订单号不存在”则直接认定失败 if (result.GetValue("err_code").ToString() == "ORDERNOTEXIST") { succCode = 0; } else { //如果是系统错误,则后续继续 succCode = 2; } return(result); }