修改查询订单状态封装
This commit is contained in:
@@ -2,10 +2,7 @@ package com.czg;
|
||||
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.NativeMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.third.alipay.AlipayIsvPayManager;
|
||||
import com.czg.third.wechat.WechatPayManager;
|
||||
|
||||
@@ -52,11 +49,11 @@ public class PayManager {
|
||||
/**
|
||||
* 查询订单状态
|
||||
*/
|
||||
public static Map<String, Object> queryOrderStatus(String platform, String orderNo, String subMerchantId) {
|
||||
public static QueryOrderRespDTO queryOrderStatus(String platform, String orderNo, NativeMerchantDTO merchantDTO) {
|
||||
if (SystemConstants.PayType.WECHAT.equals(platform)) {
|
||||
return WechatPayManager.queryOrder(null, orderNo, subMerchantId);
|
||||
return WechatPayManager.queryOrder(null, orderNo, merchantDTO);
|
||||
} else if (SystemConstants.PayType.ALIPAY.equals(platform)) {
|
||||
return AlipayIsvPayManager.queryOrder(null, orderNo, subMerchantId);
|
||||
return AlipayIsvPayManager.queryOrder(null, orderNo, merchantDTO);
|
||||
} else {
|
||||
throw new CzgException("不支持的支付平台");
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import com.alipay.v3.model.ExtendParams;
|
||||
import com.alipay.v3.util.model.CustomizedParams;
|
||||
import com.czg.PayCst;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.NativeMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.third.alipay.dto.config.AlipayConfigDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -104,8 +101,8 @@ public class AlipayIsvPayManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Object> queryOrder(AlipayConfigDto configDto, String orderNo, String subMerchantId) {
|
||||
return new HashMap<>();
|
||||
public static QueryOrderRespDTO queryOrder(AlipayConfigDto configDto, String orderNo, NativeMerchantDTO merchantDTO) {
|
||||
return new QueryOrderRespDTO();
|
||||
}
|
||||
|
||||
public static RefundRespDTO refundOrder(AlipayConfigDto configDto, CzgRefundReq paramsDto, String notifyUrl, NativeMerchantDTO merchantDTO) {
|
||||
|
||||
@@ -6,10 +6,7 @@ import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.PayCst;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.NativeMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.cipher.Signer;
|
||||
@@ -205,7 +202,7 @@ public class WechatPayManager {
|
||||
*
|
||||
* @param configDto 配置
|
||||
* @param orderNo 订单号
|
||||
* @param subMerchantId 子商户号
|
||||
* @param merchantDTO 支付商户信息
|
||||
* SUCCESS:支付成功
|
||||
* REFUND:转入退款
|
||||
* NOTPAY:未支付
|
||||
@@ -214,34 +211,35 @@ public class WechatPayManager {
|
||||
* USERPAYING:用户支付中(仅付款码支付会返回)
|
||||
* PAYERROR:支付失败(仅付款码支付会返回)
|
||||
*/
|
||||
public static Map<String, Object> queryOrder(WechatPayConfigDto configDto, String orderNo, String subMerchantId) {
|
||||
public static QueryOrderRespDTO queryOrder(WechatPayConfigDto configDto, String orderNo, NativeMerchantDTO merchantDTO) {
|
||||
try {
|
||||
if (configDto == null) {
|
||||
configDto = WechatPayConfigDto.getDefaultConfig();
|
||||
}
|
||||
|
||||
String resp = WechatReqUtils.getReq(configDto, "/v3/pay/partner/transactions/out-trade-no/" + orderNo,
|
||||
Map.of("sp_mchid", configDto.getMerchantId(), "sub_mchid", subMerchantId));
|
||||
Map.of("sp_mchid", configDto.getMerchantId(), "sub_mchid", merchantDTO.getWechatMerchantId()));
|
||||
log.info("微信查询订单,订单号:{}, 响应:{}", orderNo, resp);
|
||||
|
||||
JSONObject res = new JSONObject();
|
||||
res.put("orderNo", orderNo);
|
||||
QueryOrderRespDTO queryOrderRespDTO = new QueryOrderRespDTO()
|
||||
.setOrderNo(orderNo)
|
||||
.setOriginResp(resp);
|
||||
|
||||
JSONObject object = JSONObject.parseObject(resp);
|
||||
String tradeState = object.getString("trade_state");
|
||||
res.put("message", object.getString("trade_state_desc"));
|
||||
queryOrderRespDTO.setErrorMsg(object.getString("trade_state_desc"));
|
||||
if (PAY_SUCCESS.equals(tradeState)) {
|
||||
res.put("status", "TRADE_SUCCESS");
|
||||
return res;
|
||||
queryOrderRespDTO.setStatus("TRADE_SUCCESS");
|
||||
return queryOrderRespDTO;
|
||||
}
|
||||
|
||||
if ("USERPAYING".equals(tradeState)) {
|
||||
res.put("status", "TRADE_AWAIT");
|
||||
return res;
|
||||
queryOrderRespDTO.setStatus("TRADE_AWAIT");
|
||||
return queryOrderRespDTO;
|
||||
}
|
||||
|
||||
res.put("status", "TRADE_FAIL");
|
||||
return res;
|
||||
queryOrderRespDTO.setStatus("TRADE_FAIL");
|
||||
return queryOrderRespDTO;
|
||||
} catch (Exception e) {
|
||||
log.error("微信查询订单异常: orderNo = {}, e = {}", orderNo, e.getMessage());
|
||||
throw new CzgException("微信查询订单异常");
|
||||
|
||||
Reference in New Issue
Block a user