From 27d43affc74b07388dc71d9ff6654def691cacec Mon Sep 17 00:00:00 2001 From: jieyuu <645634619@qq.com> Date: Sat, 28 Sep 2024 17:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/jieyuu/component/AlipayStrategy.java | 36 ++++++++++++++++++- .../jieyuu/component/WechatPayStrategy.java | 4 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/xdclass-order-service/src/main/java/net/jieyuu/component/AlipayStrategy.java b/xdclass-order-service/src/main/java/net/jieyuu/component/AlipayStrategy.java index 79cc14f..5492d4e 100644 --- a/xdclass-order-service/src/main/java/net/jieyuu/component/AlipayStrategy.java +++ b/xdclass-order-service/src/main/java/net/jieyuu/component/AlipayStrategy.java @@ -3,8 +3,10 @@ package net.jieyuu.component; import com.alibaba.fastjson.JSON; import com.alipay.api.AlipayApiException; import com.alipay.api.request.AlipayTradePagePayRequest; +import com.alipay.api.request.AlipayTradeQueryRequest; import com.alipay.api.request.AlipayTradeWapPayRequest; import com.alipay.api.response.AlipayTradePagePayResponse; +import com.alipay.api.response.AlipayTradeQueryResponse; import com.alipay.api.response.AlipayTradeWapPayResponse; import lombok.extern.slf4j.Slf4j; import net.jieyuu.config.AlipayConfig; @@ -98,8 +100,40 @@ public class AlipayStrategy implements PayStrategy { return PayStrategy.super.refund(payInfoVO); } + /** + * 查询订单状态 + * 成功返回非空 + * 其他返回空 + * + * @param payInfoVO + * @return + */ @Override public String queryPaySuccess(PayInfoVO payInfoVO) { - return PayStrategy.super.queryPaySuccess(payInfoVO); + + AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); + HashMap content = new HashMap<>(); + + // 订单商位号,64位 + content.put("out_trade_no", payInfoVO.getOutTradeNo()); + request.setBizContent(JSON.toJSONString(content)); + + AlipayTradeQueryResponse response = null; + try { + response = AlipayConfig.getInstance().execute(request); + log.info("支付宝订单查询响应:{}", response.getBody()); + + } catch (AlipayApiException e) { + log.error("支付宝订单查询异常:{}", e); + + } + + if (response.isSuccess()) { + log.info("支付宝订单状态查询成功:{}", payInfoVO); + return response.getTradeStatus(); + } else { + log.info("支付宝订单状态查询失败:{}", payInfoVO); + return ""; + } } } diff --git a/xdclass-order-service/src/main/java/net/jieyuu/component/WechatPayStrategy.java b/xdclass-order-service/src/main/java/net/jieyuu/component/WechatPayStrategy.java index 90d11ce..99bb585 100644 --- a/xdclass-order-service/src/main/java/net/jieyuu/component/WechatPayStrategy.java +++ b/xdclass-order-service/src/main/java/net/jieyuu/component/WechatPayStrategy.java @@ -6,6 +6,10 @@ import net.jieyuu.vo.PayInfoVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +/** + * todo 完善微信支付 + */ @Slf4j @Service public class WechatPayStrategy implements PayStrategy {