|
@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
+import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.store.*;
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.lawyer.service.StoreAliPayRefundLogService;
|
|
import shop.alien.lawyer.service.StoreAliPayRefundLogService;
|
|
|
import shop.alien.lawyer.service.StoreAliPayErrorLogService;
|
|
import shop.alien.lawyer.service.StoreAliPayErrorLogService;
|
|
@@ -22,6 +23,7 @@ import shop.alien.util.common.UniqueRandomNumGenerator;
|
|
|
import shop.alien.util.common.UrlEncode;
|
|
import shop.alien.util.common.UrlEncode;
|
|
|
import shop.alien.util.system.OSUtil;
|
|
import shop.alien.util.system.OSUtil;
|
|
|
|
|
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -310,6 +312,100 @@ private final StoreAliPayErrorLogService storeAliPayErrorLogService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+// public R<String> queryPayment(String outTradeNo) {
|
|
|
|
|
+//
|
|
|
|
|
+// try {
|
|
|
|
|
+// AlipayClient alipayClient = new DefaultAlipayClient(setAlipayConfig(null));
|
|
|
|
|
+// // 2. 构造查询请求
|
|
|
|
|
+// AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
|
|
|
|
+// // 设置biz_content(JSON格式)
|
|
|
|
|
+// String bizContent = "{\"out_trade_no\":\" "+outTradeNo+"\"}";
|
|
|
|
|
+// request.setBizContent(bizContent);
|
|
|
|
|
+// // 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 {
|
|
|
|
|
+// System.out.println();
|
|
|
|
|
+//
|
|
|
|
|
+// return R.fail("订单查询失败:" + response.getMsg() + "(" + response.getSubMsg() + ")");
|
|
|
|
|
+// }
|
|
|
|
|
+// } catch (AlipayApiException e) {
|
|
|
|
|
+// e.printStackTrace();
|
|
|
|
|
+// }
|
|
|
|
|
+// return R.fail("支付失败");
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public R<String> queryPayment(String outTradeNo, String tradeNo) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ AlipayClient alipayClient = new DefaultAlipayClient(setAlipayConfig(null));
|
|
|
|
|
+ // 2. 构造查询请求
|
|
|
|
|
+ AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
|
|
|
|
+
|
|
|
|
|
+ // 设置biz_content(JSON格式)
|
|
|
|
|
+ JSONObject bizContent = new JSONObject();
|
|
|
|
|
+ if (StringUtils.isNotBlank(outTradeNo)) {
|
|
|
|
|
+ bizContent.put("out_trade_no", outTradeNo);
|
|
|
|
|
+ }
|
|
|
|
|
+// 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());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 保持原有方法以兼容旧调用
|
|
|
|
|
+ public R<String> queryPayment(String outTradeNo) {
|
|
|
|
|
+ return queryPayment(outTradeNo, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|