|
|
@@ -2,30 +2,28 @@ package shop.alien.store.strategy.payment.impl;
|
|
|
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
import com.alipay.api.AlipayClient;
|
|
|
-import com.alipay.api.DefaultAlipayClient;
|
|
|
import com.alipay.api.AlipayConfig;
|
|
|
+import com.alipay.api.DefaultAlipayClient;
|
|
|
import com.alipay.api.domain.*;
|
|
|
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
|
|
+import com.alipay.api.request.AlipayTradeQueryRequest;
|
|
|
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
|
|
-
|
|
|
-import com.alipay.api.FileItem;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import shop.alien.entity.result.R;
|
|
|
-import shop.alien.entity.store.AlipayZftCreateRecord;
|
|
|
import shop.alien.mapper.AlipayZftCreateRecordMapper;
|
|
|
-import shop.alien.store.AlienStoreApplication;
|
|
|
import shop.alien.store.strategy.payment.PaymentStrategy;
|
|
|
import shop.alien.util.common.constant.PaymentEnum;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.util.*;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -56,8 +54,8 @@ public class AlipayPartnerPaymentStrategyImpl implements PaymentStrategy {
|
|
|
|
|
|
// 设置订单总金额
|
|
|
// 除以100
|
|
|
- BigDecimal total = new BigDecimal(amount).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
|
|
-// model.setTotalAmount(total.toPlainString());
|
|
|
+ BigDecimal total = new BigDecimal(amount);
|
|
|
+ model.setTotalAmount(total.toPlainString());
|
|
|
|
|
|
// 设置订单标题
|
|
|
model.setSubject(subject);
|
|
|
@@ -121,7 +119,7 @@ public class AlipayPartnerPaymentStrategyImpl implements PaymentStrategy {
|
|
|
// model.setQueryOptions(queryOptions);
|
|
|
SettleInfo settleInfo = new SettleInfo();
|
|
|
SettleDetailInfo settleDetailInfo = new SettleDetailInfo();
|
|
|
- settleDetailInfo.setTransIn("defaultSettle");
|
|
|
+ settleDetailInfo.setTransInType("defaultSettle");
|
|
|
settleDetailInfo.setAmount(total.toString());
|
|
|
List<SettleDetailInfo> settleDetailInfos = new ArrayList<>();
|
|
|
settleDetailInfos.add(settleDetailInfo);
|
|
|
@@ -133,7 +131,7 @@ public class AlipayPartnerPaymentStrategyImpl implements PaymentStrategy {
|
|
|
|
|
|
// 第三方代调用模式下请设置app_auth_token
|
|
|
// request.putOtherTextParam("app_auth_token", "<-- 请填写应用授权令牌 -->");
|
|
|
-
|
|
|
+// model.setProductCode("QUICK_MSECURITY_PAY");
|
|
|
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
|
|
|
String orderStr = response.getBody();
|
|
|
System.out.println(orderStr);
|
|
|
@@ -141,6 +139,7 @@ public class AlipayPartnerPaymentStrategyImpl implements PaymentStrategy {
|
|
|
if (response.isSuccess()) {
|
|
|
Map<String, Object> analyzeRequest = new HashedMap<>();
|
|
|
analyzeRequest.put("orderStr", orderStr);
|
|
|
+ analyzeRequest.put("orderNumber", orderNo);
|
|
|
return R.data(analyzeRequest);
|
|
|
} else {
|
|
|
return R.fail("调用失败");
|
|
|
@@ -185,7 +184,80 @@ public class AlipayPartnerPaymentStrategyImpl implements PaymentStrategy {
|
|
|
|
|
|
@Override
|
|
|
public R searchOrderByOutTradeNoPath(String transactionId) throws Exception {
|
|
|
- return null;
|
|
|
+ try {
|
|
|
+ AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
|
|
|
+ AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
|
|
+ AlipayTradeQueryModel model = new AlipayTradeQueryModel();
|
|
|
+ model.setOutTradeNo(transactionId);
|
|
|
+ List<String> queryOptions = new ArrayList<>();
|
|
|
+ queryOptions.add("trade_settle_info");
|
|
|
+ model.setQueryOptions(queryOptions);
|
|
|
+ request.setBizModel(model);
|
|
|
+
|
|
|
+ AlipayTradeQueryResponse response = alipayClient.execute(request);
|
|
|
+ log.debug("支付宝订单查询 rawBody 长度={}", response.getBody() != null ? response.getBody().length() : 0);
|
|
|
+
|
|
|
+ Map<String, Object> data = buildAlipayTradeQueryData(response);
|
|
|
+ if (response.isSuccess()) {
|
|
|
+ return R.success("订单状态:" + data.get("tradeStatus"));
|
|
|
+ }
|
|
|
+ String sub = response.getSubMsg() != null ? response.getSubMsg() : "";
|
|
|
+ return R.fail("订单查询失败:" + response.getMsg() + "(" + sub + ")");
|
|
|
+ } catch (AlipayApiException e) {
|
|
|
+ log.error("支付宝订单查询异常, transactionId={}", transactionId, e);
|
|
|
+ return R.fail("查询异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将 {@link AlipayTradeQueryResponse} 转为与前端约定一致的 Map(与支付宝网关返回字段对齐,便于序列化为示例 JSON 结构)。
|
|
|
+ */
|
|
|
+ private static Map<String, Object> buildAlipayTradeQueryData(AlipayTradeQueryResponse response) {
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
+ data.put("code", response.getCode());
|
|
|
+ data.put("msg", response.getMsg());
|
|
|
+ data.put("body", response.getBody());
|
|
|
+ if (response.getParams() != null && !response.getParams().isEmpty()) {
|
|
|
+ data.put("params", response.getParams());
|
|
|
+ }
|
|
|
+ data.put("buyerLogonId", response.getBuyerLogonId());
|
|
|
+ data.put("buyerPayAmount", response.getBuyerPayAmount());
|
|
|
+ data.put("buyerUserId", response.getBuyerUserId());
|
|
|
+
|
|
|
+ List<TradeFundBill> fundBillList = response.getFundBillList();
|
|
|
+ if (fundBillList != null && !fundBillList.isEmpty()) {
|
|
|
+ List<Map<String, String>> bills = new ArrayList<>();
|
|
|
+ for (TradeFundBill fb : fundBillList) {
|
|
|
+ if (fb == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, String> row = new LinkedHashMap<>();
|
|
|
+ row.put("amount", fb.getAmount());
|
|
|
+ row.put("fundChannel", fb.getFundChannel());
|
|
|
+ bills.add(row);
|
|
|
+ }
|
|
|
+ data.put("fundBillList", bills);
|
|
|
+ }
|
|
|
+
|
|
|
+ data.put("invoiceAmount", response.getInvoiceAmount());
|
|
|
+ data.put("outTradeNo", response.getOutTradeNo());
|
|
|
+ data.put("pointAmount", response.getPointAmount());
|
|
|
+ data.put("receiptAmount", response.getReceiptAmount());
|
|
|
+ data.put("sendPayDate", response.getSendPayDate());
|
|
|
+ data.put("totalAmount", response.getTotalAmount());
|
|
|
+ data.put("tradeNo", response.getTradeNo());
|
|
|
+
|
|
|
+ TradeSettleInfo tradeSettleInfo = response.getTradeSettleInfo();
|
|
|
+ if (tradeSettleInfo != null) {
|
|
|
+ Map<String, String> settle = new LinkedHashMap<>();
|
|
|
+ settle.put("tradeUnsettledAmount", tradeSettleInfo.getTradeUnsettledAmount());
|
|
|
+ data.put("tradeSettleInfo", settle);
|
|
|
+ }
|
|
|
+
|
|
|
+ data.put("tradeStatus", response.getTradeStatus());
|
|
|
+ data.put("errorCode", response.getCode());
|
|
|
+ data.put("success", response.isSuccess());
|
|
|
+ return data;
|
|
|
}
|
|
|
|
|
|
@Override
|