测试支付宝 分账请求;

This commit is contained in:
terrfly 2023-03-30 14:15:53 +08:00
parent 6761b75e96
commit 01ef834bfa
5 changed files with 30 additions and 51 deletions

View File

@ -41,10 +41,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
/**
* 分账接口 支付宝官方
@ -220,12 +217,12 @@ public class AlipayDivisionService implements IDivisionService {
// 创建返回结果
HashMap<Long, ChannelRetMsg> resultMap = new HashMap<>();
// 同批次分账记录结果集
HashMap<String, RoyaltyDetail> aliAcMap = new HashMap<>();
try {
// 当无分账用户时 支付宝不允许发起分账请求 支付宝没有完结接口直接响应成功即可
if(recordList.isEmpty()){
throw new BizException("payOrderId:" + payOrder.getPayOrderId() + "分账记录为空。recordList" + recordList);
// 得到所有的 accNo recordId map
Map<String, Long> accnoAndRecordIdSet = new HashMap<>();
for (PayOrderDivisionRecord record : recordList) {
accnoAndRecordIdSet.put(record.getAccNo(), record.getRecordId());
}
AlipayTradeOrderSettleQueryRequest request = new AlipayTradeOrderSettleQueryRequest();
@ -235,27 +232,37 @@ public class AlipayDivisionService implements IDivisionService {
//统一放置 isv接口必传信息
AlipayKit.putApiIsvInfo(mchAppConfigContext, request, model);
// 支付宝分账请求单号
model.setSettleNo(recordList.get(0).getBatchOrderId());
//结算请求流水号由商家自定义32个字符以内仅可包含字母数字下划线需保证在商户端不重复
model.setOutRequestNo(payOrder.getPayOrderId());
//支付宝订单号
model.setTradeNo(payOrder.getChannelOrderNo());
model.setOutRequestNo(recordList.get(0).getBatchOrderId());
model.setTradeNo(payOrder.getChannelOrderNo()); //支付宝订单号
//调起支付宝分账接口
if(log.isInfoEnabled()){
log.info("订单:[{}], 支付宝查询分账请求:{}", recordList.get(0).getBatchOrderId(), JSON.toJSONString(model));
}
AlipayTradeOrderSettleQueryResponse alipayResp = configContextQueryService.getAlipayClientWrapper(mchAppConfigContext).execute(request);
log.info("订单:[{}], 支付宝查询分账响应:{}", payOrder.getPayOrderId(), alipayResp.getBody());
if(alipayResp.isSuccess()){
List<RoyaltyDetail> detailList = alipayResp.getRoyaltyDetailList();
if (CollectionUtil.isNotEmpty(detailList)) {
// 遍历匹配与当前账户相同的分账单
detailList.stream().forEach(item -> {
// 我方系统的分账接收记录ID
Long recordId = accnoAndRecordIdSet.get(item.getTransIn());
// 分账操作类型为转账类型
if ("transfer".equals(item.getOperationType())) {
aliAcMap.put(item.getTransIn(), item);
if ("transfer".equals(item.getOperationType()) && recordId != null) {
// 仅返回分账记录为最终态的结果 处理中的分账单不做返回处理
if ("SUCCESS".equals(item.getState())) {
resultMap.put(recordId, ChannelRetMsg.confirmSuccess(null));
}else if ("FAIL".equals(item.getState())) {
resultMap.put(recordId, ChannelRetMsg.confirmFail(null, item.getErrorCode(), item.getErrorDesc()));
}
}
});
}
@ -264,30 +271,6 @@ public class AlipayDivisionService implements IDivisionService {
throw new BizException("支付宝分账查询响应异常:" + alipayResp.getSubMsg());
}
// 返回结果
recordList.stream().forEach(record -> {
// 对应入账账号匹配
if (aliAcMap.get(record.getAccNo()) != null) {
RoyaltyDetail detail = aliAcMap.get(record.getAccNo());
ChannelRetMsg channelRetMsg = new ChannelRetMsg();
// 错误码
channelRetMsg.setChannelErrCode(detail.getErrorCode());
// 错误信息
channelRetMsg.setChannelErrMsg(detail.getErrorDesc());
// 仅返回分账记录为最终态的结果 处理中的分账单不做返回处理
if ("SUCCESS".equals(detail.getState())) {
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_SUCCESS);
resultMap.put(record.getRecordId(), channelRetMsg);
}else if ("FAIL".equals(detail.getState())) {
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_FAIL);
resultMap.put(record.getRecordId(), channelRetMsg);
}
}
});
}catch (Exception e) {
log.error("查询分账信息异常", e);
throw new BizException(e.getMessage());

View File

@ -254,10 +254,6 @@ public class WxpayDivisionService implements IDivisionService {
// 创建返回结果
HashMap<Long, ChannelRetMsg> resultMap = new HashMap<>();
try {
// 当无分账用户时 支付宝不允许发起分账请求 支付宝没有完结接口直接响应成功即可
if(recordList.isEmpty()){
throw new BizException("payOrderId:" + payOrder.getPayOrderId() + "分账记录为空。recordList" + recordList);
}
WxServiceWrapper wxServiceWrapper = configContextQueryService.getWxServiceWrapper(mchAppConfigContext);

View File

@ -103,10 +103,10 @@ public class PayOrderDivisionRecordReissueTask {
continue;
}
// 查询转账接口是否存在
IDivisionService divisionService = SpringBeansUtil.getBean(batchRecord.getIfCode() + "DivisionService", IDivisionService.class);
IDivisionService divisionService = SpringBeansUtil.getBean(payOrder.getIfCode() + "DivisionService", IDivisionService.class);
if (divisionService == null) {
log.error("查询转账接口不存在:{}", batchRecord.getIfCode());
log.error("查询分账接口不存在:{}", payOrder.getIfCode());
continue;
}
MchAppConfigContext mchAppConfigContext = configContextQueryService.queryMchInfoAndAppInfo(payOrder.getMchNo(), payOrder.getAppId());

View File

@ -33,7 +33,7 @@ public class PayOrderDivisionRecordService extends ServiceImpl<PayOrderDivisionR
PayOrderDivisionRecord updateRecord = new PayOrderDivisionRecord();
updateRecord.setState(state);
updateRecord.setChannelRespResult(channelRespResult);
updateRecord.setChannelRespResult( state == PayOrderDivisionRecord.STATE_SUCCESS ? "" : channelRespResult); // 若明确成功清空错误信息
update(updateRecord, PayOrderDivisionRecord.gw().eq(PayOrderDivisionRecord::getRecordId, recordId).eq(PayOrderDivisionRecord::getState, PayOrderDivisionRecord.STATE_ACCEPT));
}

View File

@ -43,7 +43,7 @@
<!-- batch_order_id 去重, 查询出所有的 分账已受理状态的订单, 支持分页。 -->
<select id="distinctBatchOrderIdList" resultMap="BaseResultMap">
select DISTINCT batch_order_id from t_pay_order_division_record
select DISTINCT batch_order_id, pay_order_id from t_pay_order_division_record
<where>
<if test="ew != null">