Files
jsowell-charger-web/jsowell-pile/src/main/java/com/jsowell/adapay/service/AdapayService.java

1231 lines
60 KiB
Java
Raw Normal View History

2023-06-06 16:18:25 +08:00
package com.jsowell.adapay.service;
2023-06-28 08:54:55 +08:00
import com.alibaba.fastjson2.JSON;
2023-07-06 11:04:21 +08:00
import com.alibaba.fastjson2.JSONObject;
2023-10-24 14:49:49 +08:00
import com.alibaba.fastjson2.JSONReader;
2023-08-18 09:52:12 +08:00
import com.alibaba.fastjson2.TypeReference;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
2023-06-06 16:18:25 +08:00
import com.google.common.collect.Maps;
2023-06-09 09:44:20 +08:00
import com.huifu.adapay.core.exception.BaseAdaPayException;
2023-07-06 15:11:17 +08:00
import com.huifu.adapay.model.*;
2023-10-24 14:49:49 +08:00
import com.jsowell.adapay.common.AdaPayment;
2023-08-18 09:52:12 +08:00
import com.jsowell.adapay.common.CreateAdaPaymentParam;
2023-08-10 17:03:20 +08:00
import com.jsowell.adapay.common.DivMember;
2023-12-27 16:27:14 +08:00
import com.jsowell.adapay.common.RefundInfo;
import com.jsowell.adapay.config.AbstractAdapayConfig;
2023-08-21 08:52:32 +08:00
import com.jsowell.adapay.dto.*;
import com.jsowell.adapay.factory.AdapayConfigFactory;
2023-08-26 18:38:00 +08:00
import com.jsowell.adapay.operation.PaymentReverseOperation;
2023-08-11 11:44:55 +08:00
import com.jsowell.adapay.response.*;
2023-08-21 13:20:17 +08:00
import com.jsowell.adapay.vo.*;
2023-08-18 09:52:12 +08:00
import com.jsowell.common.constant.CacheConstants;
2023-06-20 16:24:04 +08:00
import com.jsowell.common.constant.Constants;
2023-08-18 09:52:12 +08:00
import com.jsowell.common.core.redis.RedisCache;
2023-08-01 16:16:34 +08:00
import com.jsowell.common.enums.DelFlagEnum;
2023-08-05 16:15:20 +08:00
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
2023-09-01 13:30:59 +08:00
import com.jsowell.common.enums.adapay.MerchantDelayModeEnum;
2023-08-01 16:16:34 +08:00
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.ScenarioEnum;
2023-06-09 08:18:42 +08:00
import com.jsowell.common.exception.BusinessException;
2023-06-28 10:33:50 +08:00
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.DateUtils;
2023-06-07 16:04:10 +08:00
import com.jsowell.common.util.StringUtils;
2023-06-29 15:06:31 +08:00
import com.jsowell.common.util.ZipUtil;
2023-06-06 16:18:25 +08:00
import com.jsowell.common.util.id.IdUtils;
2023-06-15 14:26:53 +08:00
import com.jsowell.pile.domain.AdapayMemberAccount;
2023-08-01 16:59:33 +08:00
import com.jsowell.pile.domain.ClearingBillInfo;
2023-08-01 16:16:34 +08:00
import com.jsowell.pile.domain.ClearingWithdrawInfo;
2023-08-23 15:36:14 +08:00
import com.jsowell.pile.domain.MemberBasicInfo;
2023-08-18 09:52:12 +08:00
import com.jsowell.pile.dto.PayOrderDTO;
2023-08-23 15:36:14 +08:00
import com.jsowell.pile.service.*;
2023-06-06 16:18:25 +08:00
import lombok.extern.slf4j.Slf4j;
2023-07-13 15:22:26 +08:00
import org.apache.commons.collections4.CollectionUtils;
2023-06-07 15:10:35 +08:00
import org.springframework.beans.factory.annotation.Autowired;
2023-06-07 16:04:10 +08:00
import org.springframework.beans.factory.annotation.Value;
2023-08-18 09:52:12 +08:00
import org.springframework.cglib.beans.BeanMap;
2023-06-06 16:18:25 +08:00
import org.springframework.stereotype.Service;
2023-06-14 16:23:16 +08:00
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
2023-06-06 16:18:25 +08:00
2023-06-20 11:39:24 +08:00
import java.io.File;
2023-06-13 11:28:15 +08:00
import java.math.BigDecimal;
2023-08-01 16:16:34 +08:00
import java.util.Date;
2024-01-03 17:07:01 +08:00
import java.util.HashMap;
2023-07-01 11:46:17 +08:00
import java.util.List;
2023-06-06 16:18:25 +08:00
import java.util.Map;
2023-08-18 09:52:12 +08:00
import java.util.concurrent.TimeUnit;
2023-08-01 16:59:33 +08:00
import java.util.stream.Collectors;
2023-06-06 16:18:25 +08:00
@Slf4j
@Service
2023-08-18 09:52:12 +08:00
public class AdapayService {
@Autowired
private RedisCache redisCache;
2023-06-07 15:10:35 +08:00
2023-07-10 17:41:21 +08:00
@Value("${adapay.callback}")
private String ADAPAY_CALLBACK_URL;
2023-07-05 15:42:44 +08:00
2023-06-15 14:26:53 +08:00
@Autowired
2023-11-29 11:55:33 +08:00
private AdapayMemberAccountService adapayMemberAccountService;
2023-06-15 14:26:53 +08:00
2023-08-01 16:16:34 +08:00
@Autowired
private ClearingWithdrawInfoService clearingWithdrawInfoService;
2023-08-01 16:59:33 +08:00
@Autowired
private ClearingBillInfoService clearingBillInfoService;
2023-08-17 16:42:49 +08:00
@Autowired
private IPileMerchantInfoService pileMerchantInfoService;
2023-08-23 15:36:14 +08:00
@Autowired
private IMemberBasicInfoService memberBasicInfoService;
2023-08-18 09:52:12 +08:00
/**
* 获取支付参数
*/
public Map<String, Object> createPayment(PayOrderDTO dto) {
2023-11-13 16:42:44 +08:00
// log.info("===============使用汇付支付-获取支付参数");
2023-08-18 09:52:12 +08:00
// 相同参数重复请求,返回同一个支付对象
String redisKey = CacheConstants.ADAPAY_ORDER_PARAM + dto.getOrderCode();
Map<String, Object> cacheObject = redisCache.getCacheObject(redisKey);
if (cacheObject != null) {
// 表示已经获取到支付参数了,后续再有支付请求就拒绝
return cacheObject;
}
// 获取支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
// 获取openId
2023-08-23 15:36:14 +08:00
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMemberId(dto.getMemberId());
if (memberBasicInfo == null) {
2023-08-18 09:52:12 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
}
2023-08-25 16:07:15 +08:00
String openId = memberBasicInfo.getOpenId();
2023-08-18 09:52:12 +08:00
// 支付场景
String type = dto.getType();
2023-08-18 09:52:12 +08:00
// 封装对象
String amount = AdapayUtil.formatAmount(dto.getPayAmount()); // 用户支付金额
2023-09-01 13:30:59 +08:00
String delayMode = pileMerchantInfoService.getDelayModeByWechatAppId(dto.getWechatAppId());
String payMode = MerchantDelayModeEnum.getAdapayPayMode(delayMode);
2023-08-18 09:52:12 +08:00
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
// 请求订单号
String orderNo = dto.getOrderCode();
if (ScenarioEnum.OCCUPY.getValue().equals(type)) {
orderNo = orderNo + "_" + DateUtils.dateTimeNow();
}
createAdaPaymentParam.setOrder_no(orderNo);
2023-08-18 09:52:12 +08:00
createAdaPaymentParam.setPay_amt(amount);
createAdaPaymentParam.setApp_id(config.getAdapayAppId());
createAdaPaymentParam.setPay_channel("wx_lite"); // todo 如果以后有支付宝等别的渠道,这里需要做修改,判断是什么渠道的请求
createAdaPaymentParam.setGoods_title(dto.getGoodsTitle());
createAdaPaymentParam.setGoods_desc(dto.getGoodsDesc()); // 这个字段是微信支付凭证的商品名
Map<String, String> map = Maps.newHashMap();
map.put("type", type);
2023-08-18 09:52:12 +08:00
map.put("orderCode", dto.getOrderCode());
map.put("payMode", payMode);
map.put("memberId", dto.getMemberId());
createAdaPaymentParam.setDescription(JSON.toJSONString(map));
// 异步通知地址url为http/https路径服务器POST回调URL 上请勿附带参数
createAdaPaymentParam.setNotify_url(ADAPAY_CALLBACK_URL);
createAdaPaymentParam.setExpend(JSONObject.toJSONString(ImmutableMap.of("open_id", openId)));
// 延时分账
2023-08-25 16:07:15 +08:00
if (StringUtils.isNotBlank(payMode)) {
createAdaPaymentParam.setPay_mode(payMode);
}
2023-08-18 09:52:12 +08:00
try {
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam), config.getWechatAppId());
2023-11-03 14:37:09 +08:00
log.info("创建汇付支付参数:{}, response:{}", JSON.toJSONString(createAdaPaymentParam), JSON.toJSONString(response));
2023-08-18 09:52:12 +08:00
if (response != null && !response.isEmpty()) {
String status = (String) response.get("status");
if (!StringUtils.equals(status, AdapayStatusEnum.SUCCEEDED.getValue())) {
String error_msg = (String) response.get("error_msg");
throw new BusinessException(ReturnCodeEnum.CODE_GET_WECHAT_PAY_PARAMETER_ERROR.getValue(), error_msg);
}
2023-08-18 09:52:12 +08:00
JSONObject expend = JSONObject.parseObject(response.get("expend").toString());
JSONObject pay_info = expend.getJSONObject("pay_info");
2023-08-25 16:07:15 +08:00
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {
});
2023-08-18 09:52:12 +08:00
if (resultMap != null) {
// 请求参数放入缓存15分钟以内返回同一个支付参数
redisCache.setCacheObject(redisKey, resultMap, 15, TimeUnit.MINUTES);
}
return resultMap;
}
} catch (BaseAdaPayException e) {
log.error("汇付-获取支付对象发生异常", e);
}
return null;
}
2023-08-11 11:29:43 +08:00
/**
* 创建结算账户
2023-08-11 14:20:00 +08:00
*
2023-08-11 11:29:43 +08:00
* @param dto
* @throws BaseAdaPayException
* @throws BusinessException
*/
2023-07-17 15:49:20 +08:00
public void createSettleAccount(SettleAccountDTO dto) throws BaseAdaPayException, BusinessException {
2023-06-20 16:24:04 +08:00
String bankAcctType = dto.getBankAcctType();
2023-08-17 17:12:17 +08:00
// 设置wechatAppId
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
dto.setWechatAppId(wechatAppId);
2023-08-25 11:53:53 +08:00
String cardId = dto.getCardId();
String cardNo = dto.getCardNo();
if (StringUtils.isBlank(cardId) && StringUtils.isNotBlank(cardNo)) {
dto.setCardId(cardNo);
}
if (StringUtils.isBlank(cardNo) && StringUtils.isNotBlank(cardId)) {
dto.setCardNo(cardId);
}
2023-06-20 16:24:04 +08:00
if (StringUtils.equals(bankAcctType, Constants.ONE)) {
createCorpMember(dto);
2023-06-29 15:06:31 +08:00
} else if (StringUtils.equals(bankAcctType, Constants.TWO)) {
createMember(dto);
2023-06-20 16:24:04 +08:00
}
}
2023-06-06 16:18:25 +08:00
/**
2023-06-09 09:44:20 +08:00
* 创建汇付会员
2023-06-17 16:33:01 +08:00
*
2023-06-09 09:44:20 +08:00
* @param dto
* @throws Exception
2023-06-06 16:18:25 +08:00
*/
2023-06-14 16:23:16 +08:00
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
2023-08-11 14:20:00 +08:00
public void createMember(SettleAccountDTO dto) throws BaseAdaPayException, BusinessException {
2023-08-17 17:12:17 +08:00
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
// 查询汇付会员关系
2023-06-15 14:26:53 +08:00
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(dto.getMerchantId());
if (adapayMemberAccount != null) {
2023-08-17 17:12:17 +08:00
log.error("通过merchantId:{}, 查询到结算账户配置:{}", dto.getMerchantId(), JSON.toJSONString(adapayMemberAccount));
2023-06-09 15:34:35 +08:00
return;
}
2023-06-07 16:04:10 +08:00
log.info("=======execute CreateMember begin=======");
Map<String, Object> memberParams = Maps.newHashMap();
2023-06-29 16:16:25 +08:00
String adapayMemberId = Constants.ADAPAY_MEMBER_PREFIX + IdUtils.getMemberId();
2023-06-15 14:26:53 +08:00
memberParams.put("member_id", adapayMemberId);
2023-08-17 17:12:17 +08:00
memberParams.put("app_id", config.getAdapayAppId());
2023-06-07 16:04:10 +08:00
memberParams.put("location", dto.getLocation());
memberParams.put("email", dto.getEmail());
memberParams.put("gender", dto.getGender());
memberParams.put("nickname", dto.getNickname());
log.info("创建用户,请求参数:" + JSON.toJSONString(memberParams));
2023-08-17 17:12:17 +08:00
Map<String, Object> member = Member.create(memberParams, config.getWechatAppId());
2023-06-07 16:04:10 +08:00
log.info("创建用户,返回参数:" + JSON.toJSONString(member));
log.info("=======execute CreateMember end=======");
2023-06-09 09:44:20 +08:00
if (member == null || StringUtils.equals((String) member.get("status"), "failed")) {
2023-06-09 08:18:42 +08:00
String errorMsg = member == null ? "创建汇付用户失败" : (String) member.get("error_msg");
throw new BusinessException("00500001", errorMsg);
2023-06-07 16:04:10 +08:00
}
2023-06-09 09:44:20 +08:00
2023-08-21 14:49:22 +08:00
Map<String, Object> settleCount = createSettleAccountRequest(dto, adapayMemberId, dto.getWechatAppId());
2023-06-14 16:23:16 +08:00
if (settleCount == null || StringUtils.equals((String) settleCount.get("status"), "failed")) {
2023-06-14 16:29:51 +08:00
String errorMsg = settleCount == null ? "创建汇付结算账户失败" : (String) settleCount.get("error_msg");
2023-06-14 16:23:16 +08:00
throw new BusinessException("00500001", errorMsg);
}
2023-06-15 14:26:53 +08:00
String settleAccountId = (String) settleCount.get("id");
// 保存到数据库
adapayMemberAccount = new AdapayMemberAccount();
adapayMemberAccount.setMerchantId(dto.getMerchantId());
adapayMemberAccount.setAdapayMemberId(adapayMemberId);
adapayMemberAccount.setSettleAccountId(settleAccountId);
2023-07-05 14:49:47 +08:00
adapayMemberAccount.setStatus(Constants.ONE);
2023-06-15 14:26:53 +08:00
adapayMemberAccountService.insertAdapayMemberAccount(adapayMemberAccount);
2023-06-07 16:04:10 +08:00
}
2023-06-08 15:00:30 +08:00
2023-06-09 09:44:20 +08:00
/**
* 查询汇付会员信息
2023-06-17 16:33:01 +08:00
*
2023-06-09 09:44:20 +08:00
* @param merchantId
* @return
*/
public Map<String, Object> selectAdapayMember(String merchantId) throws BaseAdaPayException {
Map<String, Object> map = Maps.newHashMap();
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(merchantId);
2023-07-11 11:06:42 +08:00
if (adapayMemberAccount == null) {
log.error("通过merchantId:{}, 没有查询到结算账户配置", merchantId);
return null;
}
2023-08-17 16:42:49 +08:00
// 通过merchantId获取appId
2023-08-17 17:12:17 +08:00
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
2023-08-17 16:42:49 +08:00
2023-07-11 11:06:42 +08:00
String adapayMemberId = adapayMemberAccount.getAdapayMemberId();
2023-06-29 16:16:25 +08:00
String bankAcctType;
2023-07-01 11:46:17 +08:00
AdapayMemberInfoVO adapayMemberInfoVO = null;
List<AdapaySettleAccountVO> list = null;
2023-07-06 11:13:55 +08:00
AdapayCorpMemberVO adapayCorpMemberVO = null;
2023-06-29 16:16:25 +08:00
if (StringUtils.startsWith(adapayMemberId, Constants.ADAPAY_MEMBER_PREFIX)) {
2023-07-06 14:07:23 +08:00
bankAcctType = Constants.TWO;
2023-06-29 16:16:25 +08:00
// 查询个人用户
2023-08-17 17:12:17 +08:00
adapayMemberInfoVO = queryAdapayMemberInfo(adapayMemberId, wechatAppId);
2023-06-29 16:16:25 +08:00
if (adapayMemberInfoVO != null) {
adapayMemberInfoVO.setMerchantId(merchantId);
}
2023-08-17 17:12:17 +08:00
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount(adapayMemberId, adapayMemberAccount.getSettleAccountId(), wechatAppId);
2023-06-29 16:16:25 +08:00
if (adapaySettleAccountVO != null) {
adapaySettleAccountVO.setMerchantId(merchantId);
}
map.put("adapayMember", adapayMemberInfoVO);
2023-07-01 11:46:17 +08:00
list = Lists.newArrayList(adapaySettleAccountVO);
map.put("settleAccountList", list);
2023-06-29 16:16:25 +08:00
} else {
2023-07-06 14:07:23 +08:00
bankAcctType = Constants.ONE;
2023-06-29 16:16:25 +08:00
// 查询企业用户
2023-08-17 17:12:17 +08:00
adapayCorpMemberVO = queryCorpAdapayMemberInfo(adapayMemberId, wechatAppId);
}
2023-06-29 16:16:25 +08:00
map.put("bankAcctType", bankAcctType);
2023-07-01 11:46:17 +08:00
map.put("adapayMember", adapayMemberInfoVO);
map.put("settleAccountList", list);
2023-07-06 11:13:55 +08:00
map.put("adapayCorpMember", adapayCorpMemberVO);
return map;
2023-06-08 15:00:30 +08:00
}
2023-06-09 09:44:20 +08:00
2023-06-15 14:06:33 +08:00
2023-06-09 09:44:20 +08:00
/**
2023-06-15 14:06:33 +08:00
* 查询汇付会员信息
2023-06-09 09:44:20 +08:00
*/
2023-08-17 16:42:49 +08:00
public AdapayMemberInfoVO queryAdapayMemberInfo(String adapayMemberId, String wechatAppId) throws BaseAdaPayException {
2023-08-17 17:12:17 +08:00
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
if (StringUtils.isBlank(adapayMemberId)) {
return null;
}
2023-06-15 14:06:33 +08:00
Map<String, Object> memberParams = Maps.newHashMap();
memberParams.put("member_id", adapayMemberId);
2023-08-17 17:12:17 +08:00
memberParams.put("app_id", config.getAdapayAppId());
Map<String, Object> member = Member.query(memberParams, config.getWechatAppId());
2023-07-11 10:01:13 +08:00
log.info("==查询个人用户,请求参数:{},返回参数:{}", JSON.toJSONString(memberParams), JSON.toJSONString(member));
if (member == null || member.isEmpty() || !"succeeded".equals(member.get("status"))) {
return null;
}
2023-06-15 14:06:33 +08:00
QueryMemberResponse queryMemberResponse = JSON.parseObject(JSON.toJSONString(member), QueryMemberResponse.class);
AdapayMemberInfoVO resultVO = AdapayMemberInfoVO.builder()
.nickname(queryMemberResponse.getNickname())
.gender(queryMemberResponse.getGender())
.email(queryMemberResponse.getEmail())
.location(queryMemberResponse.getLocation())
.build();
return resultVO;
2023-06-15 14:06:33 +08:00
}
2023-06-09 09:44:20 +08:00
2023-06-29 16:16:25 +08:00
/**
* 查询企业用户信息
*/
2023-08-17 17:12:17 +08:00
public AdapayCorpMemberVO queryCorpAdapayMemberInfo(String adapayMemberId, String wechatAppId) throws BaseAdaPayException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-06-29 16:16:25 +08:00
Map<String, Object> memberParams = Maps.newHashMap();
memberParams.put("member_id", adapayMemberId);
2023-08-17 17:12:17 +08:00
memberParams.put("app_id", config.getAdapayAppId());
Map<String, Object> member = CorpMember.query(memberParams, config.getWechatAppId());
2023-07-11 10:01:13 +08:00
log.info("==查询企业用户信息 param:{}, result:{}", JSON.toJSONString(memberParams), JSON.toJSONString(member));
2023-06-29 16:16:25 +08:00
if (member == null || member.isEmpty() || !"succeeded".equals(member.get("status"))) {
return null;
}
2023-07-06 11:04:21 +08:00
QueryCorpMemberResponse response = JSONObject.parseObject(JSON.toJSONString(member), QueryCorpMemberResponse.class);
2023-07-06 11:13:55 +08:00
AdapayCorpMemberVO corpMemberVO = AdapayCorpMemberVO.builder()
.memberId(adapayMemberId)
.address(response.getAddress())
.name(response.getName())
.areaCode(response.getArea_code())
.provCode(response.getProv_code())
.auditDesc(response.getAudit_desc())
.auditState(response.getAudit_state())
.legalCertIdExpires(response.getLegal_cert_id_expires())
.businessScope(response.getBusiness_scope())
.legalMp(response.getLegal_mp())
.legalPerson(response.getLegal_person())
.legalCertId(response.getLegal_cert_id())
.telphone(response.getTelphone())
.zipCode(response.getZip_code())
.email(response.getEmail())
2023-07-06 14:07:23 +08:00
.socialCreditCode(response.getSocial_credit_code())
.socialCreditCodeExpires(response.getSocial_credit_code_expires())
2023-07-11 10:35:27 +08:00
// .bankCode(response.getBank_code())
// .cardName(response.getCard_name())
// .cardNo(response.getCard_no())
2023-07-06 11:13:55 +08:00
.build();
2023-07-11 10:35:27 +08:00
if (StringUtils.isNotBlank(response.getSettle_accounts())) {
JSONObject jsonObject = JSON.parseObject(response.getSettle_accounts());
String settleAccountId = jsonObject.getString("id");
if (StringUtils.isNotEmpty(settleAccountId)) {
2023-08-17 17:12:17 +08:00
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount(adapayMemberId, settleAccountId, config.getWechatAppId());
2023-07-11 10:35:27 +08:00
if (adapaySettleAccountVO != null) {
corpMemberVO.setBankCode(adapaySettleAccountVO.getBankCode());
corpMemberVO.setCardName(adapaySettleAccountVO.getCardName());
corpMemberVO.setCardNo(adapaySettleAccountVO.getCardId());
}
}
}
2023-07-06 11:13:55 +08:00
return corpMemberVO;
2023-06-29 16:16:25 +08:00
}
2023-08-21 14:49:22 +08:00
/**
* 创建结算账户请求
*/
public Map<String, Object> createSettleAccountRequest(SettleAccountDTO dto, String adapayMemberId, String wechatAppId) throws BaseAdaPayException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
// 创建结算账户
Map<String, Object> accountInfo = Maps.newHashMap();
// 银行卡号
accountInfo.put("card_id", dto.getCardId());
2023-08-25 11:53:53 +08:00
accountInfo.put("card_no", dto.getCardNo());
2023-08-21 14:49:22 +08:00
// 银行卡对应的户名
accountInfo.put("card_name", dto.getCardName());
// 证件号,银行账户类型为对私时,必填
if (StringUtils.isNotBlank(dto.getCertId())) {
accountInfo.put("cert_id", dto.getCertId());
}
// 证件类型仅支持00-身份证,银行账户类型为对私时,必填
accountInfo.put("cert_type", "00");
// 手机号
accountInfo.put("tel_no", dto.getTelNo());
// 银行编码,详见附录 银行代码,银行账户类型对公时,必填
if (StringUtils.isNotBlank(dto.getBankCode())) {
accountInfo.put("bank_code", dto.getBankCode());
}
// 银行账户类型1-对公2-对私
accountInfo.put("bank_acct_type", dto.getBankAcctType());
// 银行账户开户银行所在省份编码 (省市编码),银行账户类型为对公时,必填
if (StringUtils.isNotBlank(dto.getProvCode())) {
accountInfo.put("prov_code", dto.getProvCode());
}
// 银行账户开户银行所在地区编码(省市编码),银行账户类型为对公时,必填
if (StringUtils.isNotBlank(dto.getAreaCode())) {
accountInfo.put("area_code", dto.getAreaCode());
}
Map<String, Object> settleCountParams = Maps.newHashMap();
settleCountParams.put("member_id", adapayMemberId);
settleCountParams.put("app_id", config.getAdapayAppId());
// channel String Y 目前仅支持bank_account银行卡
settleCountParams.put("channel", "bank_account");
settleCountParams.put("account_info", accountInfo);
Map<String, Object> settleCount = SettleAccount.create(settleCountParams, config.getWechatAppId());
log.info("创建汇付结算账户param:{}, result:{}", JSON.toJSONString(settleCountParams), JSON.toJSONString(settleCount));
return settleCount;
}
2023-08-21 13:51:14 +08:00
/**
2023-08-21 13:52:48 +08:00
* 删除结算账户对象/创建删除结算账户请求
2023-08-21 13:51:14 +08:00
* 企业用户更新银行卡信息时调用先删除后新建
*/
2023-08-21 13:52:48 +08:00
public void createDeleteSettleAccountRequest(String adapayMemberId, String settleAccountId, String wechatAppId) throws BaseAdaPayException {
2023-08-21 13:51:14 +08:00
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> settleCountParams = Maps.newHashMap();
settleCountParams.put("settle_account_id", settleAccountId);
settleCountParams.put("member_id", adapayMemberId);
settleCountParams.put("app_id", config.getAdapayAppId());
2023-08-21 15:17:38 +08:00
Map<String, Object> settleCount = SettleAccount.delete(settleCountParams, wechatAppId);
2023-08-21 14:49:22 +08:00
log.info("创建删除结算账户请求param:{}, result:{}", JSON.toJSONString(settleCountParams), JSON.toJSONString(settleCount));
2023-08-21 13:51:14 +08:00
}
2023-06-15 14:06:33 +08:00
/**
* 查询汇付结算账户信息
*/
2023-08-17 17:12:17 +08:00
public AdapaySettleAccountVO queryAdapaySettleAccount(String adapayMemberId, String settleAccountId, String wechatAppId) throws BaseAdaPayException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
if (StringUtils.isBlank(adapayMemberId) || StringUtils.isBlank(settleAccountId)) {
return null;
}
2023-06-09 09:44:20 +08:00
Map<String, Object> settleCountParams = Maps.newHashMap();
2023-06-15 14:06:33 +08:00
settleCountParams.put("settle_account_id", settleAccountId);
settleCountParams.put("member_id", adapayMemberId);
2023-08-17 17:12:17 +08:00
settleCountParams.put("app_id", config.getAdapayAppId());
Map<String, Object> settleAccount = SettleAccount.query(settleCountParams, config.getWechatAppId());
2023-07-11 10:01:28 +08:00
log.info("==查询汇付结算账户信息param:{}, result:{}", JSON.toJSONString(settleCountParams), JSON.toJSONString(settleAccount));
if (settleAccount == null || settleAccount.isEmpty() || !"succeeded".equals(settleAccount.get("status"))) {
return null;
}
QueryMemberResponse.SettleAccount settleAccountInfo = JSON.parseObject(JSON.toJSONString(settleAccount), QueryMemberResponse.SettleAccount.class);
QueryMemberResponse.AccountInfo accountInfo = settleAccountInfo.getAccount_info();
AdapaySettleAccountVO resultVO = AdapaySettleAccountVO.builder()
.adapayMemberId(settleAccountInfo.getMember_id())
.settleAccountId(settleAccountInfo.getId())
.cardId(accountInfo.getCard_id())
.cardName(accountInfo.getCard_name())
.certId(accountInfo.getCert_id())
.certType(accountInfo.getCert_type())
.telNo(accountInfo.getTel_no())
.bankName(accountInfo.getBank_name())
.bankCode(accountInfo.getBank_code())
.bankAcctType(accountInfo.getBank_acct_type())
.provCode(accountInfo.getProv_code())
.areaCode(accountInfo.getArea_code())
.build();
return resultVO;
2023-06-09 09:44:20 +08:00
}
2023-06-13 09:20:24 +08:00
/**
* 查询汇付会员账户余额
*/
2023-06-13 11:28:15 +08:00
public AdapayAccountBalanceVO queryAdapayAccountBalance(String merchantId) throws BaseAdaPayException {
2023-08-17 17:12:17 +08:00
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-06-13 11:28:15 +08:00
AdapayAccountBalanceVO vo = AdapayAccountBalanceVO.builder().build();
// 通过merchantId 查询出汇付会员id 和 结算账户id用来查询余额
2023-06-15 14:40:11 +08:00
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(merchantId);
if (adapayMemberAccount == null) {
2023-08-01 16:16:34 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_MEMBER_IS_NULL_ERROR);
2023-06-13 11:28:15 +08:00
}
2023-06-15 16:42:33 +08:00
String settle_account_id = adapayMemberAccount.getSettleAccountId();
2023-06-15 14:40:11 +08:00
String member_id = adapayMemberAccount.getAdapayMemberId();
2023-06-13 11:28:15 +08:00
Map<String, Object> queryParams = Maps.newHashMap();
queryParams.put("settle_account_id", settle_account_id);
queryParams.put("member_id", member_id);
2023-08-17 17:12:17 +08:00
queryParams.put("app_id", config.getAdapayAppId());
Map<String, Object> settleCount = SettleAccount.balance(queryParams, config.getWechatAppId());
if (settleCount == null || settleCount.isEmpty() || !"succeeded".equals(settleCount.get("status"))) {
2023-06-13 11:28:15 +08:00
return vo;
}
vo.setFrzBalance(new BigDecimal((String) settleCount.get("frz_balance")));
vo.setAcctBalance(new BigDecimal((String) settleCount.get("acct_balance")));
vo.setAvlBalance(new BigDecimal((String) settleCount.get("avl_balance")));
vo.setLastAvlBalance(new BigDecimal((String) settleCount.get("last_avl_balance")));
2023-08-01 16:16:34 +08:00
vo.setAdapayMemberId(adapayMemberAccount.getAdapayMemberId());
vo.setSettleAccountId(adapayMemberAccount.getSettleAccountId());
2023-09-22 13:07:26 +08:00
// 昨日收入
BigDecimal yesterdayRevenue = BigDecimal.ZERO;
ClearingBillInfo clearingBillInfo = clearingBillInfoService.selectByMerchantIdAndTradeDate(merchantId, DateUtils.getYesterdayStr());
if (clearingBillInfo != null) {
yesterdayRevenue = clearingBillInfo.getActualClearingAmount();
}
vo.setYesterdayRevenue(yesterdayRevenue);
2023-09-22 15:54:26 +08:00
// 累计提现金额
2024-01-05 15:26:22 +08:00
// BigDecimal totalWithdraw = BigDecimal.ZERO;
// List<WithdrawInfoVO> withdrawInfoVOS = clearingWithdrawInfoService.selectByMerchantId(merchantId);
// if (CollectionUtils.isNotEmpty(withdrawInfoVOS)) {
// totalWithdraw = withdrawInfoVOS.stream().map(WithdrawInfoVO::getCashAmt).reduce(BigDecimal.ZERO, BigDecimal::add);
// }
BigDecimal totalWithdraw = clearingWithdrawInfoService.queryTotalWithdraw(merchantId);
vo.setTotalWithdraw(totalWithdraw);
2023-06-13 11:28:15 +08:00
return vo;
2023-06-13 09:20:24 +08:00
}
2023-06-14 14:48:58 +08:00
2023-06-20 10:09:21 +08:00
/**
* 更新结算账户设置
2023-06-20 11:39:24 +08:00
*
2023-06-20 10:09:21 +08:00
* @param dto
* @throws BaseAdaPayException
*/
2023-06-17 16:33:01 +08:00
public void updateSettleAccountConfig(UpdateAccountConfigDTO dto) throws BaseAdaPayException {
2023-08-17 17:12:17 +08:00
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-06-17 16:33:01 +08:00
// 通过merchantId 查询出汇付会员id 和 结算账户id用来查询余额
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(dto.getMerchantId());
if (adapayMemberAccount == null) {
2023-06-28 10:33:50 +08:00
log.error("通过merchantId:{}, 没有查询到结算账户配置", dto.getMerchantId());
2023-06-17 16:33:01 +08:00
return;
}
// 修改账户配置
Map<String, Object> params = Maps.newHashMap();
2023-08-17 17:12:17 +08:00
params.put("app_id", config.getAdapayAppId());
2023-06-17 16:33:01 +08:00
params.put("member_id", adapayMemberAccount.getAdapayMemberId());
params.put("settle_account_id", adapayMemberAccount.getSettleAccountId());
if (StringUtils.isNotBlank(dto.getMinAmt())) {
params.put("min_amt", dto.getMinAmt());
}
if (StringUtils.isNotBlank(dto.getRemainedAmt())) {
params.put("remained_amt", dto.getRemainedAmt());
}
if (StringUtils.isNotBlank(dto.getChannelRemark())) {
params.put("channel_remark", dto.getChannelRemark());
}
Map<String, Object> settleCount = SettleAccount.update(params);
2023-08-08 15:44:06 +08:00
log.info("更新结算账户设置 param:{}, result:{}", JSON.toJSONString(params), JSON.toJSONString(settleCount));
2023-06-17 16:33:01 +08:00
}
2023-06-20 10:09:21 +08:00
/**
* 创建企业用户
*/
2023-07-17 15:49:20 +08:00
public void createCorpMember(SettleAccountDTO dto) throws BaseAdaPayException, BusinessException {
2023-08-17 17:12:17 +08:00
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-08-25 13:23:36 +08:00
// 逻辑删除原来审核不通过的记录
List<AdapayMemberAccount> accountList = adapayMemberAccountService.selectAdapayMemberAccountList(dto.getMerchantId());
if (CollectionUtils.isNotEmpty(accountList)) {
2023-11-30 14:25:57 +08:00
List<String> ids = accountList.stream()
.map(x -> x.getId() + "")
.collect(Collectors.toList());
2023-08-25 13:23:36 +08:00
adapayMemberAccountService.deleteAdapayMemberAccountByIds(ids);
}
// 创建企业用户参数
2023-06-20 11:39:24 +08:00
Map<String, Object> memberParams = Maps.newHashMap();
2023-06-29 16:16:25 +08:00
String adapayMemberId = Constants.ADAPAY_CORP_MEMBER_PREFIX + IdUtils.getMemberId();
2023-08-25 13:23:36 +08:00
// 先保存一条记录
AdapayMemberAccount adapayMemberAccount = new AdapayMemberAccount();
adapayMemberAccount.setMerchantId(dto.getMerchantId());
adapayMemberAccount.setAdapayMemberId(adapayMemberId);
adapayMemberAccount.setStatus(Constants.ZERO);
adapayMemberAccountService.insertAdapayMemberAccount(adapayMemberAccount);
2023-06-20 11:39:24 +08:00
memberParams.put("member_id", adapayMemberId);
2023-08-17 17:12:17 +08:00
memberParams.put("app_id", config.getAdapayAppId());
2024-01-05 09:06:42 +08:00
// memberParams.put("order_no", "jsdk_order" + System.currentTimeMillis());
memberParams.put("order_no", IdUtils.get16UUID("jsdk_order"));
2023-06-20 11:39:24 +08:00
memberParams.put("social_credit_code_expires", dto.getSocialCreditCodeExpires());
memberParams.put("business_scope", dto.getBusinessScope());
memberParams.put("name", dto.getBusinessName());
memberParams.put("prov_code", dto.getProvCode());
memberParams.put("area_code", dto.getAreaCode());
memberParams.put("social_credit_code", dto.getSocialCreditCode());
memberParams.put("legal_person", dto.getLegalPerson());
memberParams.put("legal_cert_id", dto.getLegalCertId());
memberParams.put("legal_cert_id_expires", dto.getLegalCertIdExpires());
memberParams.put("legal_mp", dto.getLegalMp());
memberParams.put("address", dto.getAddress());
memberParams.put("zip_code", dto.getZipCode());
memberParams.put("telphone", dto.getTelphone());
memberParams.put("email", dto.getEmail());
2023-08-31 08:52:40 +08:00
memberParams.put("bank_code", dto.getBankCode());
memberParams.put("bank_acct_type", dto.getBankAcctType());
memberParams.put("card_no", dto.getCardNo());
memberParams.put("card_name", dto.getCardName());
2023-07-10 17:41:21 +08:00
memberParams.put("notify_url", ADAPAY_CALLBACK_URL);
2023-06-29 15:06:31 +08:00
File file = ZipUtil.createZipFileFromImages(dto.getImgList());
2023-08-17 17:12:17 +08:00
Map<String, Object> member = CorpMember.create(memberParams, file, config.getWechatAppId());
2023-08-08 15:44:06 +08:00
log.info("创建企业账户param:{}, result:{}", JSON.toJSONString(memberParams), JSON.toJSONString(member));
2023-07-06 10:15:49 +08:00
if (StringUtils.equals((String) member.get("status"), "failed")) {
2023-11-29 14:23:01 +08:00
String error_msg = (String) member.get("error_msg");
adapayMemberAccount.setStatus(Constants.TWO); // 创建失败,改状态
adapayMemberAccount.setRemark(error_msg);
adapayMemberAccountService.updateAdapayMemberAccount(adapayMemberAccount);
throw new BusinessException("", error_msg);
2023-07-06 10:15:49 +08:00
}
2023-07-13 15:22:26 +08:00
2023-08-21 14:49:22 +08:00
// 取消自动创建结算账户,手动创建结算账户
2023-08-31 08:52:40 +08:00
// Map<String, Object> settleCount = createSettleAccountRequest(dto, adapayMemberId, dto.getWechatAppId());
//
// if (settleCount == null || StringUtils.equals((String) settleCount.get("status"), "failed")) {
// String errorMsg = settleCount == null ? "创建汇付结算账户失败" : (String) settleCount.get("error_msg");
// throw new BusinessException("00500001", errorMsg);
// }
// String settleAccountId = (String) settleCount.get("id");
// // 更新数据库
// adapayMemberAccount.setSettleAccountId(settleAccountId);
// adapayMemberAccountService.updateAdapayMemberAccount(adapayMemberAccount);
2023-06-20 10:09:21 +08:00
}
2023-06-20 16:24:04 +08:00
/**
2023-08-21 13:20:17 +08:00
* 提现逻辑/创建取现对象
2023-08-11 14:20:00 +08:00
*
* @param dto
* @throws BaseAdaPayException
*/
2023-08-01 14:07:41 +08:00
public void drawCash(WithdrawDTO dto) throws BaseAdaPayException {
2023-08-17 17:14:44 +08:00
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
2023-08-17 17:12:17 +08:00
// 获取汇付支付配置
2023-08-17 17:14:44 +08:00
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
2023-08-17 17:12:17 +08:00
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-08-01 16:16:34 +08:00
// 查询余额
AdapayAccountBalanceVO adapayAccountBalanceVO = queryAdapayAccountBalance(dto.getMerchantId());
if (adapayAccountBalanceVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_MEMBER_IS_NULL_ERROR);
2023-06-28 10:33:50 +08:00
}
2023-08-05 16:15:20 +08:00
// 提现手续费 每笔固定5元
2023-08-03 09:58:05 +08:00
BigDecimal feeAmt = new BigDecimal("5");
2023-08-01 16:16:34 +08:00
// 实际提现到账金额
BigDecimal cashAmt = adapayAccountBalanceVO.getAvlBalance().subtract(feeAmt);
// 可提现金额减去手续费后需大于0
2023-08-08 10:32:30 +08:00
if (cashAmt.compareTo(BigDecimal.ZERO) <= 0) {
2023-08-01 16:16:34 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_INSUFFICIENT_BALANCE_ERROR);
}
// 发送提现申请
Map<String, Object> settleCountParams = Maps.newHashMap();
2023-08-25 16:07:15 +08:00
String orderNo = "drawcash_" + dto.getMerchantId() + "_" + System.currentTimeMillis();
2023-08-21 11:25:01 +08:00
settleCountParams.put("order_no", orderNo);
2023-08-01 16:16:34 +08:00
settleCountParams.put("cash_amt", AdapayUtil.formatAmount(cashAmt));
settleCountParams.put("member_id", adapayAccountBalanceVO.getAdapayMemberId());
2023-08-17 17:12:17 +08:00
settleCountParams.put("app_id", config.getAdapayAppId());
2023-08-01 16:16:34 +08:00
settleCountParams.put("settle_account_id", adapayAccountBalanceVO.getSettleAccountId());
2023-08-22 11:08:35 +08:00
settleCountParams.put("cash_type", "T1");
2023-08-01 14:07:41 +08:00
settleCountParams.put("notify_url", ADAPAY_CALLBACK_URL);
2023-08-17 17:12:17 +08:00
Map<String, Object> settleCount = Drawcash.create(settleCountParams, config.getWechatAppId());
2023-08-08 15:44:06 +08:00
log.info("申请取现接口,请求参数:{}, 返回参数:{}", JSON.toJSONString(settleCountParams), JSON.toJSONString(settleCount));
2023-08-01 16:16:34 +08:00
if (settleCount == null) {
throw new BusinessException("", "申请取现接口发生异常");
}
2023-08-22 11:11:45 +08:00
if (AdapayStatusEnum.FAILED.getValue().equals(settleCount.get("status"))) {
throw new BusinessException((String) settleCount.get("error_code"), (String) settleCount.get("error_msg"));
}
2023-08-01 16:16:34 +08:00
String id = (String) settleCount.get("id");
// 发起支付手续费请求 inMemberId为0表示本商户
2023-08-17 17:12:17 +08:00
createBalancePaymentRequest(adapayAccountBalanceVO.getAdapayMemberId(), Constants.ZERO, feeAmt.toString(), "提现手续费", "提现单号:" + id, config.getWechatAppId());
2023-08-01 16:16:34 +08:00
// 保存提现记录
ClearingWithdrawInfo record = new ClearingWithdrawInfo();
2023-08-08 14:36:49 +08:00
record.setMerchantId(dto.getMerchantId());
2023-08-01 16:16:34 +08:00
record.setWithdrawCode(id);
2023-08-21 11:25:01 +08:00
record.setOrderNo(orderNo);
2023-08-01 16:16:34 +08:00
record.setWithdrawStatus(Constants.ZERO);
2023-09-22 15:25:21 +08:00
record.setWithdrawAmt(adapayAccountBalanceVO.getAvlBalance()); // 申请提现金额
record.setFeeAmt(feeAmt); // 提现手续费
record.setCreditedAmt(cashAmt); // 到账金额
2023-08-01 16:16:34 +08:00
Date now = new Date();
record.setApplicationTime(now);
record.setCreateTime(now);
record.setDelFlag(DelFlagEnum.NORMAL.getValue());
2023-08-08 14:36:49 +08:00
clearingWithdrawInfoService.insertSelective(record);
2023-08-01 16:29:45 +08:00
// 修改清分账单为提现中
2023-08-08 10:32:30 +08:00
List<ClearingBillInfo> list = clearingBillInfoService.selectByMerchantId(dto.getMerchantId(), "2");
2023-08-01 16:59:33 +08:00
List<Integer> clearingBillIds = list.stream().map(ClearingBillInfo::getId).collect(Collectors.toList());
String billStatus = "3";
2023-10-20 16:34:21 +08:00
clearingBillInfoService.updateStatus(clearingBillIds, billStatus, id);
2023-06-28 10:33:50 +08:00
}
2023-07-06 15:11:17 +08:00
2023-08-21 13:20:17 +08:00
/**
* 查询取现对象
2023-08-25 16:07:15 +08:00
*
2023-08-21 13:20:17 +08:00
* @param orderNo 请求订单号
*/
public DrawCashDetailVO queryDrawCashDetail(String orderNo, String wechatAppId) throws BaseAdaPayException {
Map<String, Object> queryCashParam = Maps.newHashMap();
queryCashParam.put("order_no", orderNo);
Map<String, Object> response = Drawcash.query(queryCashParam, wechatAppId);
log.info("查询取现对象param:{}, result:{}", JSON.toJSONString(queryCashParam), JSON.toJSONString(response));
if (response != null) {
QueryDrawCashResponse queryDrawCashResponse = JSON.parseObject(JSON.toJSONString(response), QueryDrawCashResponse.class);
2023-08-21 13:24:07 +08:00
if (queryDrawCashResponse == null || queryDrawCashResponse.isNotSuccess()) {
2023-08-21 13:20:17 +08:00
return null;
}
QueryDrawCashResponse.Cash cash = queryDrawCashResponse.getCashList().get(0);
DrawCashDetailVO vo = new DrawCashDetailVO();
vo.setCashId(cash.getCashId());
vo.setCashAmt(cash.getCashAmt());
vo.setTransStat(cash.getTransStat());
vo.setStatusDesc(cash.getTransStatusDesc());
return vo;
}
return null;
}
2023-07-29 16:43:16 +08:00
/**
* 更新汇付会员信息
2023-08-11 14:20:00 +08:00
*
2023-07-29 16:43:16 +08:00
* @param dto
* @return
* @throws BaseAdaPayException
*/
2023-07-06 15:11:17 +08:00
public Map<String, Object> updateAdapayMember(SettleAccountDTO dto) throws BaseAdaPayException {
2023-08-17 17:12:17 +08:00
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-07-06 15:11:17 +08:00
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(dto.getMerchantId());
if (adapayMemberAccount == null) {
log.error("通过merchantId:{}, 没有查询到结算账户配置", dto.getMerchantId());
return null;
}
Map<String, Object> memberParams = Maps.newHashMap();
memberParams.put("adapay_func_code", "corp_members.update");
memberParams.put("member_id", adapayMemberAccount.getAdapayMemberId());
2023-08-17 17:12:17 +08:00
memberParams.put("app_id", config.getAdapayAppId());
2024-01-05 09:06:42 +08:00
// memberParams.put("order_no", "jsdk_order_" + System.currentTimeMillis());
memberParams.put("order_no", IdUtils.get16UUID("jsdk_order_"));
2023-07-06 15:11:17 +08:00
memberParams.put("social_credit_code_expires", dto.getSocialCreditCodeExpires());
memberParams.put("business_scope", dto.getBusinessScope());
memberParams.put("name", dto.getNickname());
memberParams.put("prov_code", dto.getProvCode());
memberParams.put("area_code", dto.getAreaCode());
memberParams.put("legal_person", dto.getLegalPerson());
memberParams.put("legal_cert_id", dto.getLegalCertId());
memberParams.put("legal_cert_id_expires", dto.getLegalCertIdExpires());
memberParams.put("legal_mp", dto.getLegalMp());
memberParams.put("address", dto.getAddress());
memberParams.put("zip_code", dto.getZipCode());
memberParams.put("telphone", dto.getTelphone());
memberParams.put("email", dto.getEmail());
File file = ZipUtil.createZipFileFromImages(dto.getImgList());
2023-08-17 17:12:17 +08:00
Map<String, Object> member = AdapayCommon.requestAdapayFile(memberParams, file, config.getWechatAppId());
2023-08-08 15:44:06 +08:00
log.info("更新企业账户param:{}, result:{}", JSON.toJSONString(memberParams), JSON.toJSONString(member));
2023-08-05 16:15:20 +08:00
if (AdapayStatusEnum.FAILED.getValue().equals((String) member.get("status"))) {
2023-07-07 08:11:18 +08:00
throw new BusinessException("", (String) member.get("error_msg"));
}
2023-07-06 15:11:17 +08:00
return null;
}
2023-07-29 16:43:16 +08:00
2023-08-10 17:03:20 +08:00
/**
* 创建交易确认请求/创建分账请求
* 这个方法只适用于给一个用户分账
2023-08-11 14:20:00 +08:00
*
* @param paymentId 支付对象id
2023-08-26 16:41:59 +08:00
* @param adapayMemberAccount 收到该账的汇付会员信息
2023-08-11 14:20:00 +08:00
* @param confirmAmt 确认的金额
* @param orderCode 订单编号
2023-08-10 17:03:20 +08:00
*/
2023-08-23 08:47:53 +08:00
public PaymentConfirmResponse createPaymentConfirmRequest(String paymentId, AdapayMemberAccount adapayMemberAccount, BigDecimal confirmAmt, String orderCode, String wechatAppId) {
2023-08-10 17:03:20 +08:00
// 调汇付的分账接口 确认交易
Map<String, Object> confirmParams = Maps.newHashMap();
// Adapay生成的支付对象id
confirmParams.put("payment_id", paymentId);
// 请求订单号只能为英文、数字或者下划线的一种或多种组合保证在app_id下唯一
2024-01-04 17:43:53 +08:00
// confirmParams.put("order_no", "PC" + System.currentTimeMillis());
confirmParams.put("order_no", IdUtils.get16UUID("PC"));
2023-08-10 17:03:20 +08:00
// 确认金额必须大于0保留两位小数点如0.10、100.05等。必须小于等于原支付金额-已确认金额-已撤销金额。
confirmParams.put("confirm_amt", AdapayUtil.formatAmount(confirmAmt));
// 附加说明
JSONObject jsonObject = new JSONObject();
jsonObject.put("orderCode", orderCode);
jsonObject.put("adapayMemberId", adapayMemberAccount.getAdapayMemberId());
confirmParams.put("description", jsonObject.toJSONString());
// 分账对象信息 一次最多7个
DivMember divMember = new DivMember();
divMember.setMember_id(adapayMemberAccount.getAdapayMemberId());
divMember.setAmount(AdapayUtil.formatAmount(confirmAmt));
divMember.setFee_flag(Constants.Y);
confirmParams.put("div_members", Lists.newArrayList(divMember));
Map<String, Object> paymentConfirm = null;
try {
2023-08-23 08:47:53 +08:00
paymentConfirm = PaymentConfirm.create(confirmParams, wechatAppId);
2023-08-10 17:03:20 +08:00
} catch (BaseAdaPayException e) {
log.error("创建交易确认请求error", e);
}
String jsonString = JSON.toJSONString(paymentConfirm);
log.info("调分账接口param:{}, result:{}", JSON.toJSONString(confirmParams), jsonString);
// 删除支付确认信息缓存
redisCache.deleteObject(CacheConstants.PAYMENT_CONFIRM_LIST + paymentId);
2023-08-10 17:03:20 +08:00
return JSONObject.parseObject(jsonString, PaymentConfirmResponse.class);
}
2023-07-29 16:43:16 +08:00
/**
* 创建余额支付请求
2023-08-11 14:20:00 +08:00
*
2023-07-29 16:43:16 +08:00
* @param outMemberId 出账用户的member_id 若为商户本身时请传入0
2023-08-11 14:20:00 +08:00
* @param inMemberId 入账用户的member_id 若为商户本身时请传入0
* @param transAmt 交易金额 必须大于0保留两位小数点如0.10100.05等
* @param title 标题
* @param desc 描述信息
2023-07-29 16:43:16 +08:00
*/
2023-08-17 17:12:17 +08:00
public BalancePaymentResponse createBalancePaymentRequest(String outMemberId, String inMemberId, String transAmt, String title, String desc, String wechatAppId) {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-07-29 16:43:16 +08:00
Map<String, Object> balanceParam = Maps.newHashMap();
2023-08-17 17:12:17 +08:00
balanceParam.put("app_id", config.getAdapayAppId());
2023-07-29 16:43:16 +08:00
balanceParam.put("adapay_func_code", "settle_accounts.balancePay");
balanceParam.put("order_no", IdUtils.fastSimpleUUID());
balanceParam.put("out_member_id", outMemberId);
2023-07-29 16:53:16 +08:00
balanceParam.put("in_member_id", inMemberId);
2023-07-29 16:43:16 +08:00
balanceParam.put("trans_amt", AdapayUtil.formatAmount(transAmt));
2023-08-05 16:15:20 +08:00
balanceParam.put("goods_title", title);
balanceParam.put("goods_desc", desc);
2023-08-10 17:03:20 +08:00
Map<String, Object> paymentResult = null;
try {
2023-08-17 17:12:17 +08:00
paymentResult = AdapayCommon.requestAdapay(balanceParam, config.getWechatAppId());
2023-08-10 17:03:20 +08:00
} catch (BaseAdaPayException e) {
log.error("创建余额支付请求error", e);
}
String jsonString = JSON.toJSONString(paymentResult);
log.info("创建余额支付param:{}, result:{}", JSON.toJSONString(balanceParam), jsonString);
return JSONObject.parseObject(jsonString, BalancePaymentResponse.class);
2023-07-29 16:43:16 +08:00
}
2023-08-03 18:53:24 +08:00
/**
* 创建支付确认撤销
*/
2023-09-06 14:30:06 +08:00
public void createConfirmReverse(String paymentConfirmId, String wechatAppId) throws BaseAdaPayException {
2023-08-03 18:53:24 +08:00
Map<String, Object> confirmReverseParams = Maps.newHashMap();
confirmReverseParams.put("adapay_func_code", "payments.confirm.reverse");
confirmReverseParams.put("payment_confirm_id", paymentConfirmId);
confirmReverseParams.put("reason", "支付确认撤销");
confirmReverseParams.put("order_no", IdUtils.fastSimpleUUID());
2023-09-06 14:30:06 +08:00
Map<String, Object> confirmReverseResult = AdapayCommon.requestAdapay(confirmReverseParams, wechatAppId);
2023-08-03 18:53:24 +08:00
log.info("创建支付确认撤销param:{}, result:{}", JSON.toJSONString(confirmReverseParams), JSON.toJSONString(confirmReverseResult));
}
2023-08-10 17:03:20 +08:00
2023-08-11 11:29:43 +08:00
/**
* 创建退款请求
*/
2023-08-25 16:07:15 +08:00
public RefundResponse createRefundRequest(String paymentId, BigDecimal refundAmt, String wechatAppId, String memberId, String scenarioType, String orderCode) {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
// 实时分账的调退款接口
2023-08-11 11:29:43 +08:00
Map<String, Object> refundParams = Maps.newHashMap();
refundParams.put("refund_amt", AdapayUtil.formatAmount(refundAmt));
refundParams.put("refund_order_no", IdUtils.fastSimpleUUID());
2023-08-25 16:07:15 +08:00
// expand 为扩展域
Map<String, String> expendMap = Maps.newHashMap();
expendMap.put("memberId", memberId);
expendMap.put("scenarioType", scenarioType);
if (StringUtils.isNotBlank(orderCode)) {
expendMap.put("orderCode", orderCode);
}
refundParams.put("expand", expendMap);
refundParams.put("reason", expendMap);
2023-08-11 11:29:43 +08:00
refundParams.put("notify_url", ADAPAY_CALLBACK_URL);
2023-08-25 16:07:15 +08:00
2023-08-11 14:20:00 +08:00
Map<String, Object> resultResponse = null;
2023-08-11 11:29:43 +08:00
try {
2023-08-25 16:07:15 +08:00
resultResponse = Refund.create(paymentId, refundParams, config.getWechatAppId());
2023-08-11 11:29:43 +08:00
} catch (BaseAdaPayException e) {
log.error("汇付支付创建退款对象error", e);
}
2023-08-11 14:20:00 +08:00
String jsonString = JSON.toJSONString(resultResponse);
log.info("汇付支付创建退款对象param:{}, result:{}", JSON.toJSONString(refundParams), JSON.toJSONString(jsonString));
return JSONObject.parseObject(jsonString, RefundResponse.class);
2023-08-11 11:29:43 +08:00
}
/**
* 创建交易撤销请求
* 延迟分账未确认, 调交易撤销接口退款
2023-08-26 18:38:00 +08:00
* delay模式的商户使用
*/
public PaymentReverseResponse createPaymentReverseRequest(PaymentReverseOperation paymentReverseOperation) {
String wechatAppId = paymentReverseOperation.getMerchantKey();
String paymentId = paymentReverseOperation.getPaymentId();
BigDecimal reverseAmt = paymentReverseOperation.getReverseAmt();
String memberId = paymentReverseOperation.getMemberId();
String scenarioType = paymentReverseOperation.getScenarioType();
String orderCode = paymentReverseOperation.getOrderCode();
return createPaymentReverseRequest(paymentId, reverseAmt, wechatAppId, memberId, scenarioType, orderCode);
}
/**
* 创建交易撤销请求
* 延迟分账未确认, 调交易撤销接口退款
* delay模式的商户使用
* @param wechatAppId 微信小程序appId
2023-08-11 11:29:43 +08:00
*/
2023-08-26 18:38:00 +08:00
public PaymentReverseResponse createPaymentReverseRequest(String paymentId, BigDecimal reverseAmt,
String wechatAppId, String memberId, String scenarioType,
String orderCode) {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
2023-08-11 11:29:43 +08:00
// 延迟分账未确认调撤销调撤销接口退款
Map<String, Object> reverseParams = Maps.newHashMap();
reverseParams.put("app_id", config.getAdapayAppId());
2023-08-11 11:29:43 +08:00
reverseParams.put("payment_id", paymentId);
reverseParams.put("reverse_amt", AdapayUtil.formatAmount(reverseAmt));
reverseParams.put("order_no", IdUtils.fastSimpleUUID());
reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
2023-08-26 18:38:00 +08:00
// expand 为扩展域
Map<String, String> expendMap = Maps.newHashMap();
expendMap.put("memberId", memberId);
expendMap.put("scenarioType", scenarioType);
if (StringUtils.isNotBlank(orderCode)) {
expendMap.put("orderCode", orderCode);
}
reverseParams.put("expand", expendMap);
2023-08-17 12:44:36 +08:00
reverseParams.put("reason", expendMap);
2023-08-26 18:38:00 +08:00
2023-08-11 11:44:55 +08:00
Map<String, Object> paymentReverse = null;
2023-08-11 11:29:43 +08:00
try {
paymentReverse = PaymentReverse.create(reverseParams, config.getWechatAppId());
2023-08-11 11:29:43 +08:00
} catch (BaseAdaPayException e) {
log.error("汇付支付创建交易撤销对象error", e);
}
2023-08-11 11:44:55 +08:00
String jsonString = JSON.toJSONString(paymentReverse);
log.info("汇付支付创建交易撤销对象param:{}, result:{}", JSON.toJSONString(reverseParams), jsonString);
return JSONObject.parseObject(jsonString, PaymentReverseResponse.class);
2023-08-11 11:29:43 +08:00
}
2023-08-17 14:25:45 +08:00
/**
* 查询支付撤销对象
*
* @return
*/
2023-08-17 14:50:59 +08:00
public List<PaymentReverseResponse> queryPaymentReverse(String paymentId, String wechatAppId) throws BaseAdaPayException {
2023-08-17 14:25:45 +08:00
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> reverse = Maps.newHashMap();
reverse.put("payment_id", paymentId);
reverse.put("app_id", config.getAdapayAppId());
Map<String, Object> response = PaymentReverse.queryList(reverse, config.getWechatAppId());
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
2023-08-17 14:50:59 +08:00
List<PaymentReverseResponse> payment_reverses = jsonObject.getList("payment_reverses", PaymentReverseResponse.class);
2023-08-17 14:25:45 +08:00
return payment_reverses;
}
2023-08-21 08:52:32 +08:00
2023-12-27 16:27:14 +08:00
/**
* 查询支付退款对象
*/
public List<RefundInfo> queryPaymentRefund(String paymentId, String wechatAppId) throws BaseAdaPayException {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> refundParams = Maps.newHashMap();
refundParams.put("payment_id", paymentId);
refundParams.put("app_id", config.getAdapayAppId());
Map<String, Object> response = Refund.query(refundParams, config.getWechatAppId());
PaymentRefundResponse paymentRefundResponse = JSON.parseObject(JSON.toJSONString(response), PaymentRefundResponse.class);
List<RefundInfo> refunds = paymentRefundResponse.getRefunds();
return refunds;
}
2023-08-21 08:52:32 +08:00
/**
* 查询支付确认对象列表
*/
2023-08-21 16:19:33 +08:00
public QueryPaymentConfirmDetailResponse queryPaymentConfirmList(QueryPaymentConfirmDTO dto) {
QueryPaymentConfirmDetailResponse response = null;
// 查缓存
String redisKey = CacheConstants.PAYMENT_CONFIRM_LIST + dto.getPaymentId();
String redisResult = redisCache.getCacheObject(redisKey);
if (StringUtils.isNotBlank(redisResult)) {
response = JSONObject.parseObject(redisResult, QueryPaymentConfirmDetailResponse.class);
return response;
}
2023-08-21 08:52:32 +08:00
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> param = Maps.newHashMap();
param.put("payment_id", dto.getPaymentId());
param.put("app_id", config.getAdapayAppId());
try {
Map<String, Object> map = PaymentConfirm.queryList(param, config.getWechatAppId());
response = JSON.parseObject(JSON.toJSONString(map), QueryPaymentConfirmDetailResponse.class);
2023-08-21 16:19:33 +08:00
// log.info("queryPaymentConfirmDetailResponse:{}", JSON.toJSONString(queryPaymentConfirmDetailResponse));
redisCache.setCacheObject(redisKey, JSON.toJSONString(response), CacheConstants.cache_expire_time_10d);
2023-08-21 08:52:32 +08:00
} catch (BaseAdaPayException e) {
log.error("查询支付确认对象列表error", e);
}
return response;
2023-08-21 08:52:32 +08:00
}
2023-09-25 16:08:30 +08:00
/**
* 查询支付确认对象详情
*/
public QueryPaymentConfirmDetailResponse.PaymentConfirmInfo queryPaymentConfirmDetail(QueryPaymentConfirmDTO dto) {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> confirmParams = Maps.newHashMap();
confirmParams.put("payment_confirm_id", dto.getPaymentConfirmId());
QueryPaymentConfirmDetailResponse.PaymentConfirmInfo result = null;
try {
Map<String, Object> paymentConfirm = PaymentConfirm.query(confirmParams, config.getWechatAppId());
result = JSON.parseObject(JSON.toJSONString(paymentConfirm), QueryPaymentConfirmDetailResponse.PaymentConfirmInfo.class);
} catch (BaseAdaPayException e) {
throw new RuntimeException(e);
}
return result;
}
2023-08-21 08:52:32 +08:00
/**
* 查询账务流水
*/
public void queryAcctFlowList(QueryAcctFlowDTO dto) throws BaseAdaPayException {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> acctFlowParams = Maps.newHashMap();
acctFlowParams.put("adapay_func_code", "acct.flow.list");
acctFlowParams.put("app_id", config.getAdapayAppId());
acctFlowParams.put("member_id", dto.getAdapayMemberId());
acctFlowParams.put("acct_type", dto.getAcctType());
acctFlowParams.put("page_index", dto.getPageNo());
acctFlowParams.put("page_size", dto.getPageSize());
acctFlowParams.put("begin_date", dto.getBeginDate());
acctFlowParams.put("end_date", dto.getEndDate());
Map<String, Object> acctFlowList = AdapayCommon.queryAdapay(acctFlowParams, config.getWechatAppId());
log.info("查询账务流水param:{}, result:{}", JSON.toJSONString(dto), JSON.toJSONString(acctFlowList));
}
2023-10-24 13:47:42 +08:00
/**
* 查询支付列表
*/
2023-10-24 14:49:49 +08:00
public List<AdaPayment> queryPaymentList(String startTime, String endTime) throws BaseAdaPayException {
List<AdaPayment> resultList = Lists.newArrayList();
2023-10-24 13:47:42 +08:00
String wechatAppId = "wxbb3e0d474569481d";
2023-11-03 16:43:33 +08:00
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
String appId = config.getAdapayAppId();
2023-10-24 13:47:42 +08:00
long begin = DateUtils.dateStrToTimestamp(startTime); // 13位时间戳
long end = DateUtils.dateStrToTimestamp(endTime); // 13位时间戳
2023-10-24 14:49:49 +08:00
int pageNum = 0; // 页面容量,取值范围 1~20默认值为 10
int pageSize = 20; // 页面容量,取值范围 1~20默认值为 10
boolean hasMore;
do {
pageNum += 1;
// 根据时间段查询支付对象列表
Map<String, Object> queryListParam = Maps.newHashMap();
queryListParam.put("app_id", appId);
queryListParam.put("page_index", pageNum);
queryListParam.put("page_size", pageSize);
queryListParam.put("created_gte", begin);
queryListParam.put("created_lte", end);
System.out.println("查询支付对象列表请求参数:" + JSON.toJSONString(queryListParam));
Map<String, Object> paymentListResult = Payment.queryList(queryListParam, wechatAppId);
if (paymentListResult == null) {
break;
}
String jsonString = JSON.toJSONString(paymentListResult);
System.out.println("查询支付对象列表result" + jsonString);
2023-10-24 13:47:42 +08:00
2023-10-24 14:49:49 +08:00
JSONObject jsonObject = JSON.parseObject(jsonString);
List<AdaPayment> list = jsonObject.getList("payments", AdaPayment.class, JSONReader.Feature.FieldBased);
resultList.addAll(list);
hasMore = jsonObject.getBoolean("has_more");
} while (hasMore);
return resultList;
}
/**
* 查询支付列表
*/
2023-11-03 16:43:33 +08:00
public List<AdaPayment> queryPaymentByOrderNo(String orderNo, String wechatAppId) throws BaseAdaPayException {
List<AdaPayment> resultList = Lists.newArrayList();
2023-11-03 16:43:33 +08:00
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
String appId = config.getAdapayAppId();
int pageNum = 0; // 页面容量,取值范围 1~20默认值为 10
int pageSize = 20; // 页面容量,取值范围 1~20默认值为 10
boolean hasMore;
do {
pageNum += 1;
// 根据时间段查询支付对象列表
Map<String, Object> queryListParam = Maps.newHashMap();
queryListParam.put("app_id", appId);
queryListParam.put("page_index", pageNum);
queryListParam.put("page_size", pageSize);
queryListParam.put("order_no", orderNo);
System.out.println("查询支付对象列表请求参数:" + JSON.toJSONString(queryListParam));
Map<String, Object> paymentListResult = Payment.queryList(queryListParam, wechatAppId);
if (paymentListResult == null) {
break;
}
String jsonString = JSON.toJSONString(paymentListResult);
System.out.println("查询支付对象列表result" + jsonString);
JSONObject jsonObject = JSON.parseObject(jsonString);
List<AdaPayment> list = jsonObject.getList("payments", AdaPayment.class, JSONReader.Feature.FieldBased);
resultList.addAll(list);
hasMore = jsonObject.getBoolean("has_more");
} while (hasMore);
return resultList;
}
2024-01-03 17:07:01 +08:00
/**
* 查询支付确认撤销对象
*/
public ConfirmReverseResponse queryConfirmReverse(QueryConfirmReverseDTO dto) throws BaseAdaPayException {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(dto.getWechatAppId());
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> confirmReverseQueryParams = new HashMap<>();
confirmReverseQueryParams.put("adapay_func_code", "payments.confirm.reverse.details");
confirmReverseQueryParams.put("payment_confirm_id", dto.getPaymentConfirmId());
Map<String, Object> confirmReverseQueryResult = AdapayCommon.queryAdapay(confirmReverseQueryParams, config.getWechatAppId());
ConfirmReverseResponse confirmReverseResponse = JSON.parseObject(JSON.toJSONString(confirmReverseQueryResult), ConfirmReverseResponse.class);
log.info("confirmReverseQueryResult:{}", JSON.toJSONString(confirmReverseResponse));
return confirmReverseResponse;
}
2023-06-06 16:18:25 +08:00
}