//查询订单 private static bool QueryOrder(WxPayData notifyData) { string transaction_id = notifyData.GetValue("transaction_id").ToString(); string appid = notifyData.GetValue("appid").ToString(); string mch_id = notifyData.GetValue("mch_id").ToString(); string nonce_str = notifyData.GetValue("nonce_str").ToString(); WxPayData req = new WxPayData(); req.SetValue("transaction_id", transaction_id); req.SetValue("appid", appid); req.SetValue("mch_id", mch_id); req.SetValue("nonce_str", nonce_str); req.SetValue("sign", req.MakeSign()); WxPayData res = WxPayApi.OrderQuery(req); if (res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS") { return(true); } else { return(true); } }
/// <summary> /// 查询订单情况 /// </summary> /// <param name="out_trade_no">商户订单号</param> /// <param name="succCode">查询订单结果:0表示订单不成功,1表示订单成功,2表示继续查询</param> /// <returns></returns> public static WxPayData Query(WxPayData queryOrderInput, string key, out int succCode) { WxPayData queryOrder = new WxPayData(); queryOrder.SetValue("out_trade_no", queryOrderInput.GetValue("out_trade_no")); queryOrder.SetValue("appid", queryOrderInput.GetValue("appid")); queryOrder.SetValue("mch_id", queryOrderInput.GetValue("mch_id")); queryOrder.SetValue("nonce_str", GenerateNonceStr()); queryOrder.SetValue("sign", queryOrder.MakeSign(key)); WxPayData result = WxPayApi.OrderQuery(queryOrder); 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); }