/// <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); }