2024-11-08 17:36:24 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
2024-12-18 14:05:18 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
|
|
|
import com.huifu.adapay.model.PaymentReverse;
|
|
|
|
|
|
import com.huifu.adapay.model.Refund;
|
|
|
|
|
|
import com.jsowell.JsowellApplication;
|
2025-03-28 10:10:49 +08:00
|
|
|
|
import com.jsowell.adapay.common.DivMember;
|
2024-12-26 10:04:39 +08:00
|
|
|
|
import com.jsowell.adapay.common.PaymentConfirmInfo;
|
2025-04-15 17:04:17 +08:00
|
|
|
|
import com.jsowell.adapay.dto.PaymentConfirmParam;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
import com.jsowell.adapay.dto.QueryConfirmReverseDTO;
|
|
|
|
|
|
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
|
|
|
|
|
|
import com.jsowell.adapay.operation.PaymentReverseOperation;
|
|
|
|
|
|
import com.jsowell.adapay.response.ConfirmReverseResponse;
|
2024-12-18 14:05:18 +08:00
|
|
|
|
import com.jsowell.adapay.response.PaymentConfirmResponse;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
import com.jsowell.adapay.response.PaymentReverseResponse;
|
|
|
|
|
|
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
|
|
|
|
|
|
import com.jsowell.adapay.service.AdapayService;
|
2024-12-19 16:47:40 +08:00
|
|
|
|
import com.jsowell.adapay.vo.OrderSplitResult;
|
2025-04-16 11:49:26 +08:00
|
|
|
|
import com.jsowell.common.constant.CacheConstants;
|
2025-04-15 17:04:17 +08:00
|
|
|
|
import com.jsowell.common.constant.Constants;
|
2025-04-16 11:49:26 +08:00
|
|
|
|
import com.jsowell.common.core.redis.RedisCache;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
import com.jsowell.common.enums.ykc.ScenarioEnum;
|
2025-04-15 17:04:17 +08:00
|
|
|
|
import com.jsowell.common.util.AdapayUtil;
|
2025-04-16 13:12:03 +08:00
|
|
|
|
import com.jsowell.common.util.DateUtils;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
import com.jsowell.common.util.StringUtils;
|
2024-12-18 14:05:18 +08:00
|
|
|
|
import com.jsowell.pile.domain.AdapayMemberAccount;
|
2025-04-16 13:12:03 +08:00
|
|
|
|
import com.jsowell.pile.domain.OrderUnsplitRecord;
|
2024-12-19 16:47:40 +08:00
|
|
|
|
import com.jsowell.pile.service.OrderBasicInfoService;
|
2025-04-16 11:49:26 +08:00
|
|
|
|
import com.jsowell.pile.service.OrderUnsplitRecordService;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
2025-04-16 11:49:26 +08:00
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import java.math.BigDecimal;
|
2025-04-16 13:12:03 +08:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
2025-04-16 11:49:26 +08:00
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2024-11-08 17:36:24 +08:00
|
|
|
|
|
2024-11-08 17:36:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 专用处理汇付支付相关
|
|
|
|
|
|
*/
|
2025-03-28 10:10:49 +08:00
|
|
|
|
@ActiveProfiles("dev")
|
2024-11-08 17:36:24 +08:00
|
|
|
|
@SpringBootTest(classes = JsowellApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
|
|
public class PaymentTestController {
|
|
|
|
|
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
String wechatAppId1 = "wxbb3e0d474569481d"; // 万车充
|
|
|
|
|
|
|
|
|
|
|
|
String wechatAppId2 = "wx20abc5210391649c"; // 嘉佳充电
|
|
|
|
|
|
|
2025-04-15 17:04:17 +08:00
|
|
|
|
String adapayAppId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa";
|
|
|
|
|
|
|
2025-04-16 11:49:26 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderUnsplitRecordService orderUnsplitRecordService;
|
|
|
|
|
|
|
2024-11-08 17:36:24 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private AdapayService adapayService;
|
|
|
|
|
|
|
2024-12-19 16:47:40 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderBasicInfoService orderBasicInfoService;
|
|
|
|
|
|
|
2024-11-08 17:36:24 +08:00
|
|
|
|
public List<String> getPaymentIdList() {
|
|
|
|
|
|
List<String> resultList = Lists.newArrayList();
|
|
|
|
|
|
// List<String> paymentIdList1 = getPaymentIdList1();
|
|
|
|
|
|
List<String> paymentIdListForFile = getPaymentIdListForFile();
|
|
|
|
|
|
resultList.addAll(paymentIdListForFile);
|
|
|
|
|
|
return resultList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 从文件中读取paymentId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws IOException
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<String> getPaymentIdListForFile() {
|
|
|
|
|
|
List<String> list =new ArrayList<String>();
|
|
|
|
|
|
try {
|
|
|
|
|
|
String path = "src/test/resources/payment_ids";
|
2025-04-15 17:04:17 +08:00
|
|
|
|
FileReader fileReader = new FileReader(path);
|
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
|
|
|
|
|
String str = null;
|
|
|
|
|
|
while ((str = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
if (str.trim().length() > 2) {
|
2024-11-08 17:36:24 +08:00
|
|
|
|
list.add(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
// System.out.println(list);
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-28 11:37:30 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取分账参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
public Map<String, Object> getPaymentConfirmParam() {
|
|
|
|
|
|
Map<String, Object> paramMap = Maps.newHashMap();
|
|
|
|
|
|
|
|
|
|
|
|
// 待分账汇付会员id, 如需分给对应商户就填写正确的汇付会员id
|
|
|
|
|
|
String adapayMemberId = "AM44542905";
|
|
|
|
|
|
|
2025-03-28 11:39:06 +08:00
|
|
|
|
// 待分账订单信息, 需要重新分账的订单信息(针对未分账的订单)
|
2025-03-28 11:37:30 +08:00
|
|
|
|
String jsonArrayString = "[" +
|
2025-04-02 09:21:29 +08:00
|
|
|
|
"{\"orderCode\":\"C27490025494\", \"settleAmount\":\"12.95\", \"paymentId\":\"002212025040121085510753131992504455168\"}" +
|
2025-03-28 11:37:30 +08:00
|
|
|
|
"]";
|
|
|
|
|
|
JSONArray jsonArray = JSONArray.parseArray(jsonArrayString);
|
|
|
|
|
|
|
|
|
|
|
|
paramMap.put("adapayMemberId", adapayMemberId);
|
|
|
|
|
|
paramMap.put("paymentList", jsonArray);
|
|
|
|
|
|
return paramMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-15 17:04:17 +08:00
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
List<String> orderCodeList = Lists.newArrayList();
|
|
|
|
|
|
orderCodeList.add("C44107428110");
|
|
|
|
|
|
orderCodeList.add("877828180449136640");
|
|
|
|
|
|
orderCodeList.add("OP86761657642_20231110055438");
|
|
|
|
|
|
orderCodeList.add("C80813283397_20231110055123");
|
|
|
|
|
|
for (String orderCode : orderCodeList) {
|
|
|
|
|
|
// 如果orderCode长度大于12并且有下划线, 则根据下划线切割只取第一部分
|
|
|
|
|
|
if (orderCode.length() > 12 && orderCode.contains("_")) {
|
|
|
|
|
|
orderCode = orderCode.substring(0, orderCode.indexOf("_"));
|
|
|
|
|
|
}
|
|
|
|
|
|
System.out.println(orderCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 从文件中读取paymentId和未分帐金额
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<Map<String, String>> getPaymentIdListAndAmountForFile() {
|
|
|
|
|
|
List<Map<String, String>> list = Lists.newArrayList();
|
|
|
|
|
|
try {
|
|
|
|
|
|
String path = "src/test/resources/paymentIdAndAmount";
|
|
|
|
|
|
FileReader fileReader = new FileReader(path);
|
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
2025-04-16 13:12:03 +08:00
|
|
|
|
String str;
|
2025-04-15 17:04:17 +08:00
|
|
|
|
while ((str = bufferedReader.readLine()) != null) {
|
|
|
|
|
|
if (str.trim().length() > 2) {
|
2025-04-16 13:12:03 +08:00
|
|
|
|
// str根据逗号切割 002212023102515344310563156645282902016,C88208113664,20.0,2.15,17.85,2023-10-25 15:34:49
|
2025-04-15 17:04:17 +08:00
|
|
|
|
String[] strArr = str.split(",");
|
|
|
|
|
|
String paymentId = strArr[0];
|
2025-04-16 13:12:03 +08:00
|
|
|
|
String orderCode = strArr[1];
|
|
|
|
|
|
String payAmount = strArr[2];
|
|
|
|
|
|
String refundAmount = strArr[3];
|
|
|
|
|
|
String settleAmount = strArr[4];
|
|
|
|
|
|
String orderTime = strArr[5];
|
|
|
|
|
|
|
2025-04-15 17:04:17 +08:00
|
|
|
|
// 如果orderCode长度大于12并且有下划线, 则根据下划线切割只取第一部分
|
|
|
|
|
|
if (orderCode.length() > 12 && orderCode.contains("_")) {
|
|
|
|
|
|
orderCode = orderCode.substring(0, orderCode.indexOf("_"));
|
|
|
|
|
|
}
|
2025-04-16 13:12:03 +08:00
|
|
|
|
|
|
|
|
|
|
Map<String, String> map = Maps.newHashMap();
|
|
|
|
|
|
map.put("paymentId", paymentId);
|
|
|
|
|
|
map.put("orderCode", orderCode);
|
|
|
|
|
|
map.put("payAmount", payAmount);
|
|
|
|
|
|
map.put("refundAmount", refundAmount);
|
|
|
|
|
|
map.put("settleAmount", settleAmount);
|
|
|
|
|
|
map.put("orderTime", orderTime);
|
|
|
|
|
|
list.add(map);
|
2025-04-15 17:04:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
// System.out.println(list);
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-16 13:12:03 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void saveOrderUnsplitRecordTest() {
|
|
|
|
|
|
List<Map<String, String>> mapList = getPaymentIdListAndAmountForFile();
|
|
|
|
|
|
|
|
|
|
|
|
List<OrderUnsplitRecord> orderUnsplitRecordList = Lists.newArrayList();
|
|
|
|
|
|
for (Map<String, String> stringMap : mapList) {
|
|
|
|
|
|
OrderUnsplitRecord orderUnsplitRecord = new OrderUnsplitRecord();
|
|
|
|
|
|
orderUnsplitRecord.setPaymentId(stringMap.get("paymentId"));
|
|
|
|
|
|
orderUnsplitRecord.setStatus("");
|
|
|
|
|
|
orderUnsplitRecord.setOrderCode(stringMap.get("orderCode"));
|
|
|
|
|
|
orderUnsplitRecord.setPayAmount(new BigDecimal(stringMap.get("payAmount")));
|
|
|
|
|
|
orderUnsplitRecord.setRefundAmount(new BigDecimal(stringMap.get("refundAmount")));
|
|
|
|
|
|
orderUnsplitRecord.setSettleAmount(new BigDecimal(stringMap.get("settleAmount")));
|
|
|
|
|
|
orderUnsplitRecord.setOrderTime(DateUtils.parseDate(stringMap.get("orderTime")));
|
|
|
|
|
|
orderUnsplitRecordList.add(orderUnsplitRecord);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
orderUnsplitRecordService.batchInsert(orderUnsplitRecordList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-15 17:04:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 从文件获取分账参数
|
|
|
|
|
|
*/
|
|
|
|
|
|
public Map<String, Object> getPaymentConfirmParamFromFile() {
|
|
|
|
|
|
Map<String, Object> paramMap = Maps.newHashMap();
|
|
|
|
|
|
|
|
|
|
|
|
// 待分账汇付会员id, 如需分给对应商户就填写正确的汇付会员id
|
|
|
|
|
|
String adapayMemberId = "0";
|
|
|
|
|
|
|
|
|
|
|
|
// 待分账订单信息, 需要重新分账的订单信息(针对未分账的订单)
|
|
|
|
|
|
List<Map<String, String>> mapList = getPaymentIdListAndAmountForFile();
|
|
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
|
|
for (Map<String, String> map : mapList) {
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
jsonObject.put("orderCode", map.get("orderCode"));
|
|
|
|
|
|
jsonObject.put("settleAmount", map.get("settleAmount"));
|
|
|
|
|
|
jsonObject.put("paymentId", map.get("paymentId"));
|
|
|
|
|
|
jsonArray.add(jsonObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
paramMap.put("adapayMemberId", adapayMemberId);
|
|
|
|
|
|
paramMap.put("paymentList", jsonArray);
|
|
|
|
|
|
return paramMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-18 14:05:18 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 批量执行分账
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void batchCreatePaymentConfirm() {
|
2025-03-28 11:37:30 +08:00
|
|
|
|
// 获取分账参数
|
2025-04-15 17:04:17 +08:00
|
|
|
|
// Map<String, Object> confirmParam = getPaymentConfirmParam();
|
|
|
|
|
|
Map<String, Object> confirmParam = getPaymentConfirmParamFromFile();
|
2025-03-28 11:37:30 +08:00
|
|
|
|
// 分账到指定汇付会员账户中
|
2024-12-18 14:05:18 +08:00
|
|
|
|
AdapayMemberAccount adapayMemberAccount = new AdapayMemberAccount();
|
2025-03-28 11:37:30 +08:00
|
|
|
|
adapayMemberAccount.setAdapayMemberId((String) confirmParam.get("adapayMemberId"));
|
|
|
|
|
|
// 分账订单信息
|
|
|
|
|
|
JSONArray paymentList = (JSONArray) confirmParam.get("paymentList");
|
2025-04-15 17:04:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 请求参数list
|
|
|
|
|
|
List<PaymentConfirmParam> paramList = new ArrayList<>();
|
2024-12-18 14:05:18 +08:00
|
|
|
|
for (int i = 0; i < paymentList.size(); i++) {
|
|
|
|
|
|
JSONObject jsonObject = (JSONObject) paymentList.get(i);
|
|
|
|
|
|
BigDecimal confirmAmt = jsonObject.getBigDecimal("settleAmount"); // 确认金额就是结算金额
|
|
|
|
|
|
String paymentId = jsonObject.getString("paymentId"); // 支付id
|
|
|
|
|
|
String orderCode = jsonObject.getString("orderCode"); // 订单编号
|
2025-04-15 17:04:17 +08:00
|
|
|
|
System.out.println("paymentId:" + paymentId + ", orderCode:" + orderCode + ", settleAmount:" + confirmAmt);
|
|
|
|
|
|
|
|
|
|
|
|
DivMember divMember = new DivMember();
|
|
|
|
|
|
divMember.setMemberId(adapayMemberAccount.getAdapayMemberId());
|
|
|
|
|
|
divMember.setAmount(AdapayUtil.formatAmount(confirmAmt));
|
|
|
|
|
|
divMember.setFeeFlag(Constants.Y);
|
|
|
|
|
|
|
|
|
|
|
|
PaymentConfirmParam param = PaymentConfirmParam.builder()
|
|
|
|
|
|
.paymentId(paymentId)
|
|
|
|
|
|
.divMemberList(Lists.newArrayList(divMember))
|
|
|
|
|
|
.confirmAmt(confirmAmt)
|
|
|
|
|
|
.orderCode(orderCode)
|
|
|
|
|
|
.wechatAppId(wechatAppId1)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
paramList.add(param);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 执行分账方法
|
|
|
|
|
|
if (!paramList.isEmpty()) {
|
|
|
|
|
|
for (PaymentConfirmParam paymentConfirmParam : paramList) {
|
|
|
|
|
|
// 延时分账,使用确认交易API
|
|
|
|
|
|
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentConfirmParam);
|
|
|
|
|
|
// status为failed, error_code为payment_over_time_doing, error_msg为数据正在处理中,请稍后再试, 则重试最多重试2次
|
|
|
|
|
|
if (paymentConfirmResponse.isFailed()) {
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
while (count < 2) {
|
|
|
|
|
|
count++;
|
|
|
|
|
|
System.out.println("第" + count + "次重试");
|
|
|
|
|
|
paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentConfirmParam);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-18 14:05:18 +08:00
|
|
|
|
}
|
2025-04-16 11:49:26 +08:00
|
|
|
|
|
|
|
|
|
|
// 执行分账并处理重试
|
|
|
|
|
|
// for (PaymentConfirmParam param : paramList) {
|
|
|
|
|
|
// executeWithRetry(param, 0); // 初始重试次数为0
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 执行分账并处理重试逻辑
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void executeWithRetry(PaymentConfirmParam param, int retryCount) {
|
|
|
|
|
|
PaymentConfirmResponse response = adapayService.createPaymentConfirmRequest(param);
|
|
|
|
|
|
if (!response.isFailed()) {
|
|
|
|
|
|
logger.info("分账成功: paymentId={}", param.getPaymentId());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 失败时记录日志
|
|
|
|
|
|
logger.error("分账失败: paymentId={}, 重试次数={}, 错误信息={}", param.getPaymentId(), retryCount, response.getError_msg());
|
|
|
|
|
|
|
|
|
|
|
|
// 如果未达到最大重试次数,将任务放入延迟队列
|
|
|
|
|
|
if (retryCount < 3) {
|
|
|
|
|
|
retryCount++;
|
|
|
|
|
|
logger.info("将分账任务放入延迟队列: paymentId={}, 重试次数={}", param.getPaymentId(), retryCount);
|
|
|
|
|
|
redisCache.setCacheObject(
|
|
|
|
|
|
CacheConstants.DELAYED_PAYMENT_CONFIRM_QUEUE + param.getPaymentId(),
|
|
|
|
|
|
param,
|
|
|
|
|
|
60, // 延迟1分钟
|
|
|
|
|
|
TimeUnit.SECONDS
|
|
|
|
|
|
);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logger.error("分账失败超过最大重试次数: paymentId={}", param.getPaymentId());
|
|
|
|
|
|
// 记录最终失败的任务,便于后续处理
|
|
|
|
|
|
recordFailedPayment(param);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 记录最终失败的分账任务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void recordFailedPayment(PaymentConfirmParam param) {
|
|
|
|
|
|
String failedKey = CacheConstants.FAILED_PAYMENT_CONFIRM_LIST;
|
|
|
|
|
|
redisCache.setCacheList(failedKey, Lists.newArrayList(param));
|
|
|
|
|
|
logger.error("记录最终失败的分账任务: paymentId={}", param.getPaymentId());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理延迟队列中的分账任务
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Scheduled(fixedDelay = 60000) // 每分钟执行一次
|
|
|
|
|
|
public void processDelayedPaymentConfirm() {
|
|
|
|
|
|
String delayedQueueKey = CacheConstants.DELAYED_PAYMENT_CONFIRM_QUEUE + "*";
|
|
|
|
|
|
Collection<String> keys = redisCache.keys(delayedQueueKey);
|
|
|
|
|
|
for (String key : keys) {
|
|
|
|
|
|
PaymentConfirmParam param = redisCache.getCacheObject(key);
|
|
|
|
|
|
if (param != null) {
|
|
|
|
|
|
int retryCount = Integer.parseInt(key.split("_")[key.split("_").length - 1]);
|
|
|
|
|
|
executeWithRetry(param, retryCount);
|
|
|
|
|
|
redisCache.deleteObject(key); // 处理完成后删除任务
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-18 14:05:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-08 18:35:55 +08:00
|
|
|
|
|
2024-11-08 17:36:24 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 查询分账信息
|
|
|
|
|
|
* @throws BaseAdaPayException
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void queryCreateConfirmReverse() throws BaseAdaPayException {
|
|
|
|
|
|
List<String> paymentIdList = getPaymentIdList(); // 查询分账信息
|
|
|
|
|
|
|
|
|
|
|
|
List<String> unSplitList = Lists.newArrayList(); // 未分帐
|
|
|
|
|
|
List<String> splitList = Lists.newArrayList(); // 已分帐
|
|
|
|
|
|
|
2025-04-03 10:48:40 +08:00
|
|
|
|
BigDecimal total = BigDecimal.ZERO; // 总分账金额
|
|
|
|
|
|
BigDecimal totalWithdrawalAmt = BigDecimal.ZERO; // 实际到账金额汇总
|
|
|
|
|
|
BigDecimal totalFeeAmt = BigDecimal.ZERO; // 手续费金额汇总
|
|
|
|
|
|
|
2024-11-08 17:36:24 +08:00
|
|
|
|
List<String> selfList = Lists.newArrayList();
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, BigDecimal> map = Maps.newHashMap();
|
|
|
|
|
|
for (String paymentId : paymentIdList) {
|
|
|
|
|
|
if (StringUtils.isBlank(paymentId)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 查询支付确认id
|
|
|
|
|
|
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
|
|
|
|
|
dto.setPaymentId(paymentId);
|
|
|
|
|
|
dto.setWechatAppId(wechatAppId1);
|
|
|
|
|
|
// 查询分账信息
|
|
|
|
|
|
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
|
|
|
|
|
if (response != null) {
|
2024-12-26 10:04:39 +08:00
|
|
|
|
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
2024-11-08 17:36:24 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(confirms)) {
|
|
|
|
|
|
unSplitList.add(paymentId);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
splitList.add(paymentId);
|
2024-12-26 10:04:39 +08:00
|
|
|
|
for (PaymentConfirmInfo confirm : confirms) {
|
2024-11-08 17:36:24 +08:00
|
|
|
|
if (queryConfirmReverseStatus(confirm)) {
|
|
|
|
|
|
System.out.println("支付确认id:" + confirm.getId() + "撤销了。。。");
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(confirm.getDescription());
|
|
|
|
|
|
String adapayMemberId = jsonObject.getString("adapayMemberId");
|
2025-03-28 10:10:49 +08:00
|
|
|
|
if (StringUtils.isBlank(adapayMemberId)) {
|
|
|
|
|
|
adapayMemberId = jsonObject.getString("adapayMemberIds");
|
|
|
|
|
|
}
|
2024-11-08 17:36:24 +08:00
|
|
|
|
|
2025-04-03 10:48:40 +08:00
|
|
|
|
BigDecimal confirmAmt = new BigDecimal(confirm.getConfirmAmt()); // 本次确认金额
|
|
|
|
|
|
BigDecimal confirmedAmt = new BigDecimal(confirm.getConfirmedAmt()); // 已确认金额
|
|
|
|
|
|
BigDecimal feeAmt = new BigDecimal(confirm.getFeeAmt()); // 手续费
|
|
|
|
|
|
|
|
|
|
|
|
// 汇总已确认金额
|
|
|
|
|
|
total = total.add(confirmedAmt);
|
|
|
|
|
|
|
|
|
|
|
|
// 汇总手续费金额
|
|
|
|
|
|
totalFeeAmt = totalFeeAmt.add(feeAmt);
|
|
|
|
|
|
|
|
|
|
|
|
// 汇总可提现金额
|
|
|
|
|
|
totalWithdrawalAmt = totalWithdrawalAmt.add(confirmAmt).subtract(feeAmt);
|
|
|
|
|
|
|
2025-03-28 10:10:49 +08:00
|
|
|
|
// confirm
|
|
|
|
|
|
List<DivMember> divMembers = confirm.getDivMembers();
|
|
|
|
|
|
System.out.println("confirm:" + JSON.toJSONString(divMembers));
|
|
|
|
|
|
for (DivMember divMember : divMembers) {
|
|
|
|
|
|
// 放map
|
|
|
|
|
|
map.merge(divMember.getMemberId(), new BigDecimal(divMember.getAmount()), BigDecimal::add);
|
|
|
|
|
|
}
|
2025-04-03 10:48:40 +08:00
|
|
|
|
|
2024-11-08 17:36:24 +08:00
|
|
|
|
if (StringUtils.equals(adapayMemberId, "0")) {
|
|
|
|
|
|
selfList.add(paymentId);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
unSplitList.add(paymentId);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
System.out.println("=================未分账:" + JSON.toJSONString(unSplitList) + ", 数量:" + unSplitList.size());
|
|
|
|
|
|
System.out.println("=================已分账:" + JSON.toJSONString(map) + ", 总分账:" + total + ", 数量:" + splitList.size());
|
2025-04-03 10:48:40 +08:00
|
|
|
|
System.out.println("===============金额明细:" + "总到账金额:" + totalWithdrawalAmt + ", 总手续费:" + totalFeeAmt);
|
|
|
|
|
|
System.out.println("===================自己:" + JSON.toJSONString(selfList) + ", 数量:" + selfList.size());
|
2024-11-08 17:36:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询支付撤销状态
|
|
|
|
|
|
* @param confirm
|
|
|
|
|
|
* @return
|
|
|
|
|
|
* @throws BaseAdaPayException
|
|
|
|
|
|
*/
|
2024-12-26 10:04:39 +08:00
|
|
|
|
private boolean queryConfirmReverseStatus(PaymentConfirmInfo confirm) throws BaseAdaPayException {
|
2024-11-08 17:36:24 +08:00
|
|
|
|
boolean result = false;
|
|
|
|
|
|
QueryConfirmReverseDTO dto = QueryConfirmReverseDTO.builder()
|
|
|
|
|
|
.paymentConfirmId(confirm.getId())
|
|
|
|
|
|
.wechatAppId(wechatAppId1)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
ConfirmReverseResponse confirmReverseResponse = adapayService.queryConfirmReverse(dto);
|
|
|
|
|
|
if (confirmReverseResponse.isSuccess()) {
|
|
|
|
|
|
result = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量支付确认撤销
|
|
|
|
|
|
* @throws BaseAdaPayException
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void testCreateConfirmReverse() throws BaseAdaPayException {
|
|
|
|
|
|
List<String> list = getPaymentIdList(); // 批量支付确认撤销
|
|
|
|
|
|
for (String paymentId : list) {
|
|
|
|
|
|
// 查询支付确认id
|
|
|
|
|
|
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
|
|
|
|
|
dto.setPaymentId(paymentId);
|
|
|
|
|
|
dto.setWechatAppId(wechatAppId1);
|
|
|
|
|
|
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
|
|
|
|
|
if (response != null) {
|
2024-12-26 10:04:39 +08:00
|
|
|
|
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
2024-11-08 17:36:24 +08:00
|
|
|
|
System.out.println("支付id:" + paymentId + ", 确认信息:" + JSON.toJSONString(confirms));
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(confirms)) {
|
2024-12-26 10:04:39 +08:00
|
|
|
|
for (PaymentConfirmInfo confirm : confirms) {
|
2024-11-08 17:36:24 +08:00
|
|
|
|
adapayService.createConfirmReverse(confirm.getId(), wechatAppId1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询退款信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void queryRefundTest() {
|
|
|
|
|
|
List<String> list = getPaymentIdList(); // 查询退款信息
|
|
|
|
|
|
for (String paymentId : list) {
|
|
|
|
|
|
Map<String, Object> refundParams = Maps.newHashMap();
|
|
|
|
|
|
refundParams.put("payment_id", paymentId);
|
|
|
|
|
|
try {
|
|
|
|
|
|
Map<String, Object> refund = Refund.query(refundParams, wechatAppId2);
|
|
|
|
|
|
System.out.println("支付id:" + paymentId + ", 退款信息:" + JSON.toJSONString(refund));
|
|
|
|
|
|
System.out.println();
|
|
|
|
|
|
} catch (BaseAdaPayException e) {
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询支付撤销信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void queryPaymentReverseTest() {
|
|
|
|
|
|
List<String> list = getPaymentIdList(); // 查询支付撤销信息
|
|
|
|
|
|
for (String paymentId : list) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Map<String, Object> reverse = Maps.newHashMap();
|
|
|
|
|
|
reverse.put("payment_id", paymentId);
|
|
|
|
|
|
reverse.put("app_id", wechatAppId2);
|
|
|
|
|
|
Map<String, Object> response = PaymentReverse.queryList(reverse, wechatAppId2);
|
|
|
|
|
|
System.out.printf("支付id: %s, 支付撤销信息: %s%n", paymentId, JSON.toJSONString(response));
|
|
|
|
|
|
System.out.println();
|
|
|
|
|
|
} catch (BaseAdaPayException e) {
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 延迟分账未确认调撤销调撤销接口退款/部分退
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void createPaymentReverseRequestTest() {
|
2025-04-03 13:53:22 +08:00
|
|
|
|
String paymentId = "002212025040208183810753300530720288768";
|
|
|
|
|
|
BigDecimal refundAmount = new BigDecimal("33.55");
|
|
|
|
|
|
String memberId = "61212331";
|
|
|
|
|
|
String orderCode = "C25747230823";
|
2024-11-08 17:36:24 +08:00
|
|
|
|
|
|
|
|
|
|
// 延迟分账未确认调撤销调撤销接口退款
|
|
|
|
|
|
PaymentReverseOperation operation = new PaymentReverseOperation();
|
|
|
|
|
|
operation.setPaymentId(paymentId);
|
|
|
|
|
|
operation.setReverseAmt(refundAmount);
|
|
|
|
|
|
operation.setMerchantKey(wechatAppId1);
|
|
|
|
|
|
operation.setMemberId(memberId);
|
|
|
|
|
|
operation.setScenarioType(ScenarioEnum.ORDER.getValue());
|
|
|
|
|
|
operation.setOrderCode(orderCode);
|
|
|
|
|
|
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(operation);
|
|
|
|
|
|
System.out.println(JSON.toJSONString(response));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void createBalancePaymentRequestTest() {
|
|
|
|
|
|
String outMemberId = "ACM42875164"; // 出账memberId
|
|
|
|
|
|
String inMemberId = "0"; // 入账memberId
|
|
|
|
|
|
String transAmt = "798.20"; // 金额
|
|
|
|
|
|
String title = "提取余额到自己账户"; // 标题
|
|
|
|
|
|
String desc = "2024年7月31日08点55分,售后需求:客户重新添加结算账户, 原账户余额无法提取, 由现下打款给客户"; // 描述
|
|
|
|
|
|
String wechatAppId = wechatAppId1; // 万车充id
|
|
|
|
|
|
adapayService.createBalancePaymentRequest(outMemberId, inMemberId, transAmt, title, desc, wechatAppId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void createBalancePaymentRequestTest2() {
|
|
|
|
|
|
String outMemberId = "0"; // 出账memberId
|
|
|
|
|
|
String inMemberId = "ACM25158725"; // 入账memberId
|
|
|
|
|
|
String transAmt = "42.7"; // 金额
|
|
|
|
|
|
String title = "订单金额补分账"; // 标题
|
|
|
|
|
|
String desc = "补C69401257710,C86364369573结算金额"; // 描述
|
|
|
|
|
|
String wechatAppId = wechatAppId1; // 万车充id
|
|
|
|
|
|
adapayService.createBalancePaymentRequest(outMemberId, inMemberId, transAmt, title, desc, wechatAppId);
|
|
|
|
|
|
}
|
2024-12-19 16:47:40 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 校验订单分账金额
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void verifyOrderConfirmAmountTest() throws BaseAdaPayException {
|
|
|
|
|
|
String orderCode = "C21960272918";
|
|
|
|
|
|
List<String> paymentIds = Lists.newArrayList("002212024121307453510713429549121368064");
|
|
|
|
|
|
BigDecimal settleAmount = new BigDecimal("19.37");
|
|
|
|
|
|
String wechatAppId = wechatAppId1;
|
|
|
|
|
|
OrderSplitResult orderSplitResult = orderBasicInfoService.verifyOrderConfirmAmount(paymentIds, orderCode, settleAmount, wechatAppId);
|
|
|
|
|
|
System.out.println(JSON.toJSONString(orderSplitResult));
|
|
|
|
|
|
}
|
2024-12-26 10:04:39 +08:00
|
|
|
|
|
2025-04-15 17:04:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 查询未分帐金额
|
|
|
|
|
|
*/
|
2024-12-26 10:04:39 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void queryPaymentConfirmDetailTest() throws BaseAdaPayException {
|
|
|
|
|
|
|
|
|
|
|
|
// 查询支付确认id
|
|
|
|
|
|
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
2025-04-15 17:04:17 +08:00
|
|
|
|
dto.setPaymentId("002212023102515344310563156645282902016");
|
2024-12-26 10:04:39 +08:00
|
|
|
|
dto.setWechatAppId(wechatAppId1);
|
|
|
|
|
|
// 查询分账信息
|
|
|
|
|
|
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
|
|
|
|
|
System.out.println(JSON.toJSONString(response));
|
|
|
|
|
|
}
|
2024-11-08 17:36:24 +08:00
|
|
|
|
}
|