mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
845 lines
34 KiB
Java
845 lines
34 KiB
Java
import com.alibaba.fastjson2.JSON;
|
||
import com.alibaba.fastjson2.JSONArray;
|
||
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.Payment;
|
||
import com.huifu.adapay.model.PaymentReverse;
|
||
import com.huifu.adapay.model.Refund;
|
||
import com.jsowell.JsowellApplication;
|
||
import com.jsowell.adapay.common.DivMember;
|
||
import com.jsowell.adapay.common.PaymentConfirmInfo;
|
||
import com.jsowell.adapay.dto.PaymentConfirmParam;
|
||
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
|
||
import com.jsowell.adapay.operation.PaymentReverseOperation;
|
||
import com.jsowell.adapay.response.PaymentConfirmResponse;
|
||
import com.jsowell.adapay.response.PaymentReverseResponse;
|
||
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
|
||
import com.jsowell.adapay.service.AdapayService;
|
||
import com.jsowell.adapay.vo.AdapayCorpMemberVO;
|
||
import com.jsowell.adapay.vo.OrderSplitResult;
|
||
import com.jsowell.api.uniapp.customer.TempController;
|
||
import com.jsowell.common.constant.CacheConstants;
|
||
import com.jsowell.common.constant.Constants;
|
||
import com.jsowell.common.core.redis.RedisCache;
|
||
import com.jsowell.common.enums.ykc.ScenarioEnum;
|
||
import com.jsowell.common.util.AdapayUtil;
|
||
import com.jsowell.common.util.DateUtils;
|
||
import com.jsowell.common.util.StringUtils;
|
||
import com.jsowell.pile.domain.AdapayMemberAccount;
|
||
import com.jsowell.pile.domain.OrderUnsplitRecord;
|
||
import com.jsowell.pile.dto.QueryOrderDTO;
|
||
import com.jsowell.pile.service.OrderBasicInfoService;
|
||
import com.jsowell.pile.service.OrderUnsplitRecordService;
|
||
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;
|
||
import org.springframework.scheduling.annotation.Scheduled;
|
||
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;
|
||
import java.util.*;
|
||
import java.util.concurrent.TimeUnit;
|
||
|
||
/**
|
||
* 专用处理汇付支付相关
|
||
*/
|
||
@ActiveProfiles("dev")
|
||
@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"; // 嘉佳充电
|
||
|
||
String adapayAppId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"; // 固定参数, 汇付配置的万车充小程序appId
|
||
|
||
@Autowired
|
||
private RedisCache redisCache;
|
||
|
||
@Autowired
|
||
private OrderUnsplitRecordService orderUnsplitRecordService;
|
||
|
||
@Autowired
|
||
private AdapayService adapayService;
|
||
|
||
@Autowired
|
||
private OrderBasicInfoService orderBasicInfoService;
|
||
|
||
/**
|
||
* 从payment_ids文件中获取支付id, 并批量查询分账信息
|
||
* 如需撤销分账, 请使用 {@link PaymentTestController#testCreateConfirmReverse()} 可以本地运行
|
||
* 如需重新分账, 请使用 {@link TempController#retryOrderSplit(QueryOrderDTO)} 需要使用ApiPost调用pre环境接口
|
||
*/
|
||
@Test
|
||
public void queryCreateConfirmReverse() throws BaseAdaPayException {
|
||
List<String> paymentIdList = getPaymentIdList(); // 查询分账信息
|
||
|
||
List<String> unSplitList = Lists.newArrayList(); // 未分帐
|
||
List<String> splitList = Lists.newArrayList(); // 已分帐
|
||
|
||
BigDecimal total = BigDecimal.ZERO; // 总分账金额
|
||
BigDecimal totalWithdrawalAmt = BigDecimal.ZERO; // 实际到账金额汇总
|
||
BigDecimal totalFeeAmt = BigDecimal.ZERO; // 手续费金额汇总
|
||
|
||
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) {
|
||
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
||
if (CollectionUtils.isEmpty(confirms)) {
|
||
unSplitList.add(paymentId);
|
||
} else {
|
||
splitList.add(paymentId);
|
||
for (PaymentConfirmInfo confirm : confirms) {
|
||
if (adapayService.queryConfirmReverseStatus(confirm)) {
|
||
System.out.println("支付确认id:" + confirm.getId() + "撤销了。。。");
|
||
continue;
|
||
}
|
||
JSONObject jsonObject = JSON.parseObject(confirm.getDescription());
|
||
String adapayMemberId = jsonObject.getString("adapayMemberId");
|
||
if (StringUtils.isBlank(adapayMemberId)) {
|
||
adapayMemberId = jsonObject.getString("adapayMemberIds");
|
||
}
|
||
|
||
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);
|
||
|
||
// 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);
|
||
}
|
||
|
||
if (StringUtils.equals(adapayMemberId, "0")
|
||
|| StringUtils.equals(adapayMemberId, "AM29102732")) {
|
||
// 0为默认平台id, AM29102732为罗总账户
|
||
selfList.add(paymentId);
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
unSplitList.add(paymentId);
|
||
}
|
||
}
|
||
System.out.println("=================未分账:" + JSON.toJSONString(unSplitList) + ", 数量:" + unSplitList.size());
|
||
System.out.println("=================已分账:" + JSON.toJSONString(map) + ", 总分账:" + total + ", 数量:" + splitList.size());
|
||
System.out.println("===============金额明细:" + "总到账金额:" + totalWithdrawalAmt + ", 总手续费:" + totalFeeAmt);
|
||
System.out.println("===================自己:" + JSON.toJSONString(selfList) + ", 数量:" + selfList.size());
|
||
}
|
||
|
||
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";
|
||
FileReader fileReader = new FileReader(path);
|
||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||
String str = null;
|
||
while ((str = bufferedReader.readLine()) != null) {
|
||
if (str.trim().length() > 2) {
|
||
list.add(str);
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
|
||
}
|
||
// System.out.println(list);
|
||
return list;
|
||
}
|
||
|
||
/**
|
||
* 获取分账参数
|
||
*/
|
||
public Map<String, Object> getPaymentConfirmParam() {
|
||
Map<String, Object> paramMap = Maps.newHashMap();
|
||
|
||
// 待分账汇付会员id, 如需分给对应商户就填写正确的汇付会员id
|
||
String adapayMemberId = "AM44542905";
|
||
|
||
// 待分账订单信息, 需要重新分账的订单信息(针对未分账的订单)
|
||
String jsonArrayString = "[" +
|
||
"{\"orderCode\":\"C27490025494\", \"settleAmount\":\"12.95\", \"paymentId\":\"002212025040121085510753131992504455168\"}" +
|
||
"]";
|
||
JSONArray jsonArray = JSONArray.parseArray(jsonArrayString);
|
||
|
||
paramMap.put("adapayMemberId", adapayMemberId);
|
||
paramMap.put("paymentList", jsonArray);
|
||
return paramMap;
|
||
}
|
||
|
||
/**
|
||
* 提现方法
|
||
*
|
||
*/
|
||
@Test
|
||
public void withdraw() {
|
||
String merchantId = "87";
|
||
String orderNo = "drawcash_" + merchantId + "_" + System.currentTimeMillis();
|
||
BigDecimal cashAmt = new BigDecimal("2013.81");
|
||
String adapayMemberId = "AM67987250";
|
||
// String adapayAppId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"; // 固定参数, 汇付配置的万车充小程序appId
|
||
String settleAccountId = "0600303988488384";
|
||
String wechatAppId = wechatAppId1;
|
||
try {
|
||
adapayService.createDrawcashRequest(orderNo, cashAmt, adapayMemberId, adapayAppId, settleAccountId, wechatAppId);
|
||
} catch (BaseAdaPayException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
|
||
|
||
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);
|
||
String str;
|
||
while ((str = bufferedReader.readLine()) != null) {
|
||
if (str.trim().length() > 2) {
|
||
// str根据逗号切割 002212023102515344310563156645282902016,C88208113664,20.0,2.15,17.85,2023-10-25 15:34:49
|
||
String[] strArr = str.split(",");
|
||
String paymentId = strArr[0]; // 支付id
|
||
String orderCode = strArr[1]; // 订单编号
|
||
String payAmount = strArr[2]; // 支付金额
|
||
String refundAmount = strArr[3]; // 退款金额
|
||
String settleAmount = strArr[4]; // 结算金额
|
||
String orderTime = strArr[5]; // 订单时间
|
||
|
||
// 如果orderCode长度大于12并且有下划线, 则根据下划线切割只取第一部分
|
||
if (orderCode.length() > 12 && orderCode.contains("_")) {
|
||
orderCode = orderCode.substring(0, orderCode.indexOf("_"));
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
|
||
}
|
||
// System.out.println(list);
|
||
return list;
|
||
}
|
||
|
||
@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);
|
||
}
|
||
|
||
/**
|
||
* 从文件获取批量分账参数
|
||
* adapayMemberId 待分账的汇付会员id
|
||
* paymentList 待分账的订单信息(包含订单编号, 结算金额, 支付id)
|
||
*/
|
||
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;
|
||
}
|
||
|
||
/**
|
||
* 批量执行分账
|
||
* @deprecated 2025年8月16日15点48分弃用, 此分账方法不会保存分账记录, 应使用接口执行分账
|
||
*/
|
||
@Test
|
||
public void batchCreatePaymentConfirm() {
|
||
// 获取分账参数
|
||
// Map<String, Object> confirmParam = getPaymentConfirmParam();
|
||
Map<String, Object> confirmParam = getPaymentConfirmParamFromFile();
|
||
// 分账到指定汇付会员账户中
|
||
AdapayMemberAccount adapayMemberAccount = new AdapayMemberAccount();
|
||
adapayMemberAccount.setAdapayMemberId((String) confirmParam.get("adapayMemberId"));
|
||
// 分账订单信息
|
||
JSONArray paymentList = (JSONArray) confirmParam.get("paymentList");
|
||
|
||
// 请求参数list
|
||
List<PaymentConfirmParam> paramList = new ArrayList<>();
|
||
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"); // 订单编号
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 执行分账并处理重试
|
||
// for (PaymentConfirmParam param : paramList) {
|
||
// executeWithRetry(param, 0); // 初始重试次数为0
|
||
// }
|
||
}
|
||
|
||
/**
|
||
* 执行分账并处理重试逻辑
|
||
* @deprecated
|
||
*/
|
||
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());
|
||
}
|
||
|
||
/**
|
||
* 处理延迟队列中的分账任务
|
||
* @deprecated
|
||
*/
|
||
@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); // 处理完成后删除任务
|
||
}
|
||
}
|
||
}
|
||
|
||
@Test
|
||
public void getTotalSplitAmountByPaymentIdTest() {
|
||
String paymentId = "002212023102523235110563274707384705024";
|
||
try {
|
||
BigDecimal amount = adapayService.getTotalSplitAmountByPaymentId(paymentId);
|
||
System.out.println("分账金额: " + amount);
|
||
} catch (BaseAdaPayException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 批量支付确认撤销
|
||
* 用于撤销分账
|
||
* @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) {
|
||
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
||
System.out.println("支付id:" + paymentId + ", 确认信息:" + JSON.toJSONString(confirms));
|
||
if (CollectionUtils.isNotEmpty(confirms)) {
|
||
for (PaymentConfirmInfo confirm : confirms) {
|
||
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() {
|
||
String paymentId = "002212025091910192610814936868000780288";
|
||
BigDecimal refundAmount = new BigDecimal("0.02");
|
||
String memberId = "65622699";
|
||
String orderCode = "C48996543963";
|
||
|
||
// 延迟分账未确认调撤销调撤销接口退款
|
||
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);
|
||
}
|
||
|
||
/**
|
||
* 校验订单分账金额
|
||
*/
|
||
@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));
|
||
}
|
||
|
||
/**
|
||
* 查询未分帐金额
|
||
*/
|
||
@Test
|
||
public void queryPaymentConfirmDetailTest() throws BaseAdaPayException {
|
||
|
||
// 查询支付确认id
|
||
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
||
dto.setPaymentId("002212023102515344310563156645282902016");
|
||
dto.setWechatAppId(wechatAppId1);
|
||
// 查询分账信息
|
||
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
||
System.out.println(JSON.toJSONString(response));
|
||
}
|
||
|
||
private List<String> getAdapayMemberIds() {
|
||
List<String> list = new ArrayList<>();
|
||
list.add("ACM25743626");
|
||
list.add("ACM69424215");
|
||
list.add("ACM27437238");
|
||
list.add("ACM84442005");
|
||
list.add("ACM42810916");
|
||
list.add("ACM48576257");
|
||
list.add("ACM67580043");
|
||
list.add("ACM67738893");
|
||
list.add("ACM23489463");
|
||
list.add("ACM40991242");
|
||
list.add("ACM48720983");
|
||
list.add("ACM82507085");
|
||
list.add("ACM25511707");
|
||
list.add("ACM48152528");
|
||
list.add("ACM84659934");
|
||
list.add("ACM29123898");
|
||
list.add("ACM82792551");
|
||
list.add("ACM44398405");
|
||
list.add("ACM61290230");
|
||
list.add("ACM84693947");
|
||
list.add("ACM25158725");
|
||
list.add("ACM25530730");
|
||
list.add("ACM48910890");
|
||
list.add("ACM88601280");
|
||
list.add("ACM61634334");
|
||
list.add("ACM80895702");
|
||
list.add("ACM63995722");
|
||
list.add("ACM46639968");
|
||
list.add("ACM61026608");
|
||
list.add("ACM21943395");
|
||
list.add("ACM42242307");
|
||
list.add("ACM46086128");
|
||
list.add("ACM46272826");
|
||
list.add("ACM82731955");
|
||
list.add("ACM69232006");
|
||
list.add("ACM65039881");
|
||
list.add("ACM84868091");
|
||
list.add("ACM65835351");
|
||
list.add("ACM84007115");
|
||
list.add("ACM82710624");
|
||
list.add("ACM63191244");
|
||
list.add("ACM80665158");
|
||
list.add("ACM88877099");
|
||
list.add("ACM23253592");
|
||
list.add("ACM40744704");
|
||
list.add("ACM82585598");
|
||
list.add("ACM61630517");
|
||
list.add("ACM86381094");
|
||
list.add("ACM44105905");
|
||
list.add("ACM42282057");
|
||
list.add("ACM46270169");
|
||
list.add("ACM48532303");
|
||
list.add("ACM69867986");
|
||
list.add("ACM25576542");
|
||
list.add("ACM80057656");
|
||
list.add("ACM42459200");
|
||
list.add("ACM46046815");
|
||
list.add("ACM61085115");
|
||
list.add("ACM25916276");
|
||
list.add("ACM69804831");
|
||
list.add("ACM65455320");
|
||
list.add("ACM84845205");
|
||
list.add("ACM48173891");
|
||
list.add("ACM84486182");
|
||
list.add("ACM46460819");
|
||
list.add("ACM63740826");
|
||
list.add("ACM63191096");
|
||
list.add("ACM48918479");
|
||
list.add("ACM29522241");
|
||
list.add("ACM27416361");
|
||
list.add("ACM48956267");
|
||
list.add("ACM65098379");
|
||
list.add("ACM46251134");
|
||
list.add("ACM42491105");
|
||
list.add("ACM27859047");
|
||
list.add("ACM86788208");
|
||
list.add("ACM46692941");
|
||
list.add("ACM80410442");
|
||
list.add("ACM27036391");
|
||
list.add("ACM27853386");
|
||
list.add("ACM23654452");
|
||
list.add("ACM40782726");
|
||
list.add("ACM63571448");
|
||
list.add("ACM29566538");
|
||
list.add("ACM46846737");
|
||
list.add("ACM29393542");
|
||
list.add("ACM23485623");
|
||
list.add("ACM82526496");
|
||
list.add("ACM27663450");
|
||
list.add("ACM88831475");
|
||
list.add("ACM69048024");
|
||
list.add("ACM65854572");
|
||
list.add("ACM88261510");
|
||
list.add("ACM42497015");
|
||
list.add("ACM61807959");
|
||
list.add("ACM25116331");
|
||
list.add("ACM82399802");
|
||
list.add("ACM88079897");
|
||
list.add("ACM61630935");
|
||
list.add("ACM44799744");
|
||
list.add("ACM40326146");
|
||
list.add("ACM88603166");
|
||
list.add("ACM86592402");
|
||
list.add("ACM61254324");
|
||
list.add("ACM69882166");
|
||
list.add("ACM44124955");
|
||
list.add("ACM65683299");
|
||
list.add("ACM82102763");
|
||
list.add("ACM48321794");
|
||
list.add("ACM69673479");
|
||
list.add("ACM67500600");
|
||
list.add("ACM86172597");
|
||
list.add("ACM42491905");
|
||
list.add("ACM67751788");
|
||
list.add("ACM42854259");
|
||
list.add("ACM61465505");
|
||
list.add("ACM25576943");
|
||
list.add("ACM65622214");
|
||
list.add("ACM88035944");
|
||
list.add("ACM44582427");
|
||
list.add("ACM61296391");
|
||
list.add("ACM69426703");
|
||
list.add("ACM44924010");
|
||
list.add("ACM23673274");
|
||
list.add("ACM84045137");
|
||
list.add("ACM80205384");
|
||
list.add("ACM44398211");
|
||
list.add("ACM29908562");
|
||
list.add("ACM23698348");
|
||
list.add("ACM80266727");
|
||
list.add("ACM63556694");
|
||
list.add("ACM29560453");
|
||
list.add("ACM63706872");
|
||
list.add("ACM46652838");
|
||
list.add("ACM65854139");
|
||
list.add("ACM67183933");
|
||
list.add("ACM69802535");
|
||
list.add("ACM46829664");
|
||
list.add("ACM21143070");
|
||
list.add("ACM61425221");
|
||
list.add("ACM42244668");
|
||
list.add("ACM40326509");
|
||
list.add("ACM21949831");
|
||
list.add("ACM63383478");
|
||
list.add("ACM40700033");
|
||
list.add("ACM42056483");
|
||
list.add("ACM61862227");
|
||
list.add("ACM65681312");
|
||
list.add("ACM21181689");
|
||
list.add("ACM80876335");
|
||
list.add("ACM63552660");
|
||
list.add("ACM69082641");
|
||
list.add("ACM23447202");
|
||
list.add("ACM61024342");
|
||
list.add("ACM46046494");
|
||
list.add("ACM88607781");
|
||
list.add("ACM86579709");
|
||
list.add("ACM65858167");
|
||
list.add("ACM42261148");
|
||
list.add("ACM42077124");
|
||
list.add("ACM48994471");
|
||
list.add("ACM88873084");
|
||
list.add("ACM84250847");
|
||
list.add("ACM88073310");
|
||
list.add("ACM65818689");
|
||
list.add("ACM42810992");
|
||
list.add("ACM21968250");
|
||
list.add("ACM42666015");
|
||
list.add("ACM42227741");
|
||
list.add("ACM44968744");
|
||
list.add("ACM65202789");
|
||
list.add("ACM25576713");
|
||
list.add("ACM25196954");
|
||
list.add("ACM48530698");
|
||
list.add("ACM25380172");
|
||
list.add("ACM23468349");
|
||
list.add("ACM65227435");
|
||
list.add("ACM23270264");
|
||
list.add("ACM82944298");
|
||
list.add("ACM65056931");
|
||
list.add("ACM25720476");
|
||
list.add("ACM82948898");
|
||
list.add("ACM46449658");
|
||
list.add("ACM69844311");
|
||
list.add("ACM82794891");
|
||
list.add("ACM42474874");
|
||
list.add("ACM48557876");
|
||
list.add("ACM69061582");
|
||
list.add("ACM84062890");
|
||
list.add("ACM21981947");
|
||
list.add("ACM23447601");
|
||
list.add("ACM46000454");
|
||
list.add("ACM80897090");
|
||
list.add("ACM40594777");
|
||
return list;
|
||
}
|
||
|
||
@Test
|
||
public void queryAdapayMember() throws BaseAdaPayException {
|
||
// 查询所有运营商的adapayMemberId
|
||
// String adapayMemberId = "ACM25158725";
|
||
List<String> nullInfoList = new ArrayList<>();
|
||
List<String> targetList = new ArrayList<>();
|
||
|
||
List<String> adapayMemberIds = getAdapayMemberIds();
|
||
for (String memberId : adapayMemberIds) {
|
||
AdapayCorpMemberVO adapayCorpMemberVO = adapayService.queryCorpAdapayMemberInfo(memberId, wechatAppId1);
|
||
if (adapayCorpMemberVO == null) {
|
||
nullInfoList.add(memberId);
|
||
continue;
|
||
}
|
||
String settleAccountId = adapayCorpMemberVO.getSettleAccountId();
|
||
if (settleAccountId == null) {
|
||
targetList.add(memberId);
|
||
}
|
||
}
|
||
logger.info("无信息运营商:{}", nullInfoList);
|
||
logger.info("无结算账户运营商:{}", targetList);
|
||
|
||
}
|
||
|
||
@Test
|
||
public void closeOrder() throws BaseAdaPayException {
|
||
String paymentId = "002212025070811225010788498509816119296";
|
||
Map<String, Object> map = new LinkedHashMap<>();
|
||
map.put("payment_id", paymentId);
|
||
Map<String, Object> close = Payment.close(map, wechatAppId1);
|
||
logger.info("关单接口调用结果:{}", close);
|
||
|
||
}
|
||
}
|