|
|
@@ -10,8 +10,10 @@ import com.alipay.api.DefaultAlipayClient;
|
|
|
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
|
|
import com.alipay.api.domain.AlipayTradeRefundModel;
|
|
|
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
|
|
+import com.alipay.api.request.AlipayTradeQueryRequest;
|
|
|
import com.alipay.api.request.AlipayTradeRefundRequest;
|
|
|
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
|
|
+import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeRefundResponse;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -189,7 +191,51 @@ public class AlipayPaymentStrategyImpl implements PaymentStrategy {
|
|
|
|
|
|
@Override
|
|
|
public R<Object> searchOrderByOutTradeNoPath(String transactionId) throws Exception {
|
|
|
- return null;
|
|
|
+ try {
|
|
|
+ AlipayClient alipayClient = new DefaultAlipayClient(setAlipayConfig(null));
|
|
|
+ // 2. 构造查询请求
|
|
|
+ AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
|
|
+
|
|
|
+ // 设置biz_content(JSON格式)
|
|
|
+ JSONObject bizContent = new JSONObject();
|
|
|
+ if (StringUtils.isNotBlank(transactionId)) {
|
|
|
+ bizContent.put("out_trade_no", transactionId);
|
|
|
+ }
|
|
|
+// if (StringUtils.isNotBlank(tradeNo)) {
|
|
|
+// bizContent.put("trade_no", tradeNo);
|
|
|
+// }
|
|
|
+ request.setBizContent(bizContent.toJSONString());
|
|
|
+
|
|
|
+ // 3. 调用接口并获取响应
|
|
|
+ AlipayTradeQueryResponse response = alipayClient.certificateExecute(request);
|
|
|
+ if (response.isSuccess()) {
|
|
|
+ // 4. 解析支付状态
|
|
|
+ String tradeStatus = response.getTradeStatus();
|
|
|
+ log.info("订单查询成功,支付状态:" + tradeStatus);
|
|
|
+
|
|
|
+ // 支付状态说明:
|
|
|
+ // WAIT_BUYER_PAY:等待买家付款
|
|
|
+ // TRADE_CLOSED:交易关闭(超时未支付/已取消)
|
|
|
+ // TRADE_SUCCESS:支付成功(即时到账/普通转账)
|
|
|
+ // TRADE_FINISHED:交易完成(不可退款的场景,如即时到账)
|
|
|
+ if ("TRADE_SUCCESS".equals(tradeStatus)) {
|
|
|
+ return R.success("支付成功");
|
|
|
+ } else if ("TRADE_CLOSED".equals(tradeStatus)) {
|
|
|
+ return R.fail("交易已关闭");
|
|
|
+ } else if ("WAIT_BUYER_PAY".equals(tradeStatus)) {
|
|
|
+ return R.fail("等待买家付款");
|
|
|
+ } else if ("TRADE_FINISHED".equals(tradeStatus)) {
|
|
|
+ return R.success("交易完成");
|
|
|
+ }
|
|
|
+ return R.success("订单状态:" + tradeStatus);
|
|
|
+ } else {
|
|
|
+ return R.fail("订单查询失败:" + response.getMsg() + "(" + response.getSubMsg() + ")");
|
|
|
+ }
|
|
|
+ } catch (AlipayApiException e) {
|
|
|
+ log.error("支付宝订单查询异常", e);
|
|
|
+ return R.fail("查询异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|