描述:查询订单状态

This commit is contained in:
SelfRidicule 2024-03-19 11:44:08 +08:00
parent 87e4e33aab
commit 267b06a00c
3 changed files with 65 additions and 2 deletions

View File

@ -82,4 +82,29 @@ public class WxPayController extends BaseController {
return returnParam;
}
/**
* 订单支付后回调
*/
@PostMapping("wxMerchantOrderQuery")
public HashMap wxMerchantOrderQuery(@RequestBody Map<String , String> paramMap) {
HashMap<String, String> resultMap = wxPayCommon.wxMerchantOrderQuery(paramMap.get("outTradeNo"));
// 商户订单号
String out_trade_no = resultMap.get("out_trade_no");
// 微信支付订单号
String transaction_id = resultMap.get("transaction_id");
// 交易状态
// * SUCCESS支付成功
// * REFUND转入退款
// * NOTPAY未支付
// * CLOSED已关闭
// * REVOKED已撤销仅付款码支付会返回
// * USERPAYING用户支付中仅付款码支付会返回
// * PAYERROR支付失败仅付款码支付会返回
String trade_state = resultMap.get("trade_state");
return R.data(resultMap);
}
}

View File

@ -7,6 +7,7 @@ import com.ics.controller.mobile.pay.wx.dto.WxChatPayDto;
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
@ -72,6 +73,20 @@ public class WxPayCommon {
return httpPost;
}
/**
* 获取请求对象Get请求
*
* @return Get请求
*/
public HttpGet getHttpGet(String url) {
// 1.设置请求地址
HttpGet httpGet = new HttpGet(wxPayConfig.getDomain().concat(url));
// 3.设置请求信息
httpGet.setHeader("Accept", "application/json");
return httpGet;
}
/**
* 解析响应数据
*
@ -164,8 +179,6 @@ public class WxPayCommon {
}
/**
* 创建微信支付订单-jsapi方式
*
@ -217,5 +230,24 @@ public class WxPayCommon {
}
/**
* 商户订单号查询订单
*/
public HashMap<String, String> wxMerchantOrderQuery(String outTradeNo) {
// 创建请求
HttpGet httpGet = getHttpGet(WxApiConstants.MERCHANT_ORDER_NUMBER_QUERY + "/" + outTradeNo + "?mchid=" + wxPayConfig.getMchId());
// 完成签名并执行请求
CloseableHttpResponse response = null;
try {
response = wxPayConfig.getWxPayClient().execute(httpGet);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("商户订单号查询订单请求失败");
}
// 解析response对象
HashMap<String, String> resultMap = resolverResponse(response);
return resultMap;
}
}

View File

@ -12,4 +12,10 @@ public class WxApiConstants {
public static final String JSAPI_PAY = "/v3/pay/transactions/jsapi";
/**
* 商户订单号查询订单
*/
public static final String MERCHANT_ORDER_NUMBER_QUERY = "/v3/pay/transactions/out-trade-no";
}