mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-03 11:06:46 +00:00
ref 同步接口调整
This commit is contained in:
@@ -31,10 +31,4 @@ public class SyncResult extends PaymentCommonResult {
|
||||
@Schema(description = "支付网关同步状态")
|
||||
private String status = FAIL.getCode();
|
||||
|
||||
@Schema(description = "是否进行了修复")
|
||||
private Boolean repair;
|
||||
|
||||
@Schema(description = "修复号")
|
||||
private String repairNo;
|
||||
|
||||
}
|
||||
|
@@ -176,7 +176,7 @@ public class ClientNoticeService {
|
||||
throw new RepetitiveOperationException("支付同步处理中,请勿重复操作");
|
||||
}
|
||||
// 查询任务, 进行发送
|
||||
ClientNoticeTask task = null;
|
||||
ClientNoticeTask task;
|
||||
try {
|
||||
task = taskManager.findById(taskId).orElse(null);
|
||||
// 不存在任务直接跳过
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package cn.daxpay.single.service.core.payment.sync.service;
|
||||
|
||||
import cn.bootx.platform.common.core.exception.BizException;
|
||||
import cn.bootx.platform.common.core.exception.RepetitiveOperationException;
|
||||
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
@@ -65,7 +64,7 @@ public class PaySyncService {
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
||||
public SyncResult sync(PaySyncParam param) {
|
||||
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNo())
|
||||
.orElseThrow(() -> new BizException("支付订单不存在"));
|
||||
.orElseThrow(() -> new PayFailureException("支付订单不存在"));
|
||||
// 钱包支付钱包不需要
|
||||
if (PayChannelEnum.WALLET.getCode().equals(payOrder.getChannel())){
|
||||
throw new PayFailureException("订单没有异步支付方式,不需要同步");
|
||||
@@ -92,20 +91,20 @@ public class PaySyncService {
|
||||
AbsPaySyncStrategy syncPayStrategy = PaySyncStrategyFactory.create(payOrder.getChannel());
|
||||
syncPayStrategy.initPayParam(payOrder);
|
||||
// 执行操作, 获取支付网关同步的结果
|
||||
PaySyncResult syncResult = syncPayStrategy.doSyncStatus();
|
||||
PaySyncResult paySyncResult = syncPayStrategy.doSyncStatus();
|
||||
// 判断是否同步成功
|
||||
if (Objects.equals(syncResult.getSyncStatus(), PaySyncStatusEnum.FAIL)){
|
||||
if (Objects.equals(paySyncResult.getSyncStatus(), PaySyncStatusEnum.FAIL)){
|
||||
// 同步失败, 返回失败响应, 同时记录失败的日志
|
||||
this.saveRecord(payOrder, syncResult, false, null, syncResult.getErrorMsg());
|
||||
throw new PayFailureException(syncResult.getErrorMsg());
|
||||
this.saveRecord(payOrder, paySyncResult, false, null, paySyncResult.getErrorMsg());
|
||||
throw new PayFailureException(paySyncResult.getErrorMsg());
|
||||
}
|
||||
// 支付订单的网关订单号是否一致, 不一致进行更新
|
||||
if (!Objects.equals(syncResult.getOutOrderNo(), payOrder.getOutOrderNo())){
|
||||
payOrder.setOutOrderNo(syncResult.getOutOrderNo());
|
||||
if (!Objects.equals(paySyncResult.getOutOrderNo(), payOrder.getOutOrderNo())){
|
||||
payOrder.setOutOrderNo(paySyncResult.getOutOrderNo());
|
||||
payOrderService.updateById(payOrder);
|
||||
}
|
||||
// 判断网关状态是否和支付单一致, 同时特定情况下更新网关同步状态
|
||||
boolean statusSync = this.checkAndAdjustSyncStatus(syncResult,payOrder);
|
||||
boolean statusSync = this.checkAndAdjustSyncStatus(paySyncResult,payOrder);
|
||||
PayRepairResult repairResult = new PayRepairResult();
|
||||
try {
|
||||
// 状态不一致,执行支付单修复逻辑
|
||||
@@ -116,22 +115,19 @@ public class PaySyncService {
|
||||
repairInfo.setSource(PayRepairSourceEnum.SYNC);
|
||||
}
|
||||
// 设置支付单完成时间
|
||||
repairInfo.setFinishTime(syncResult.getPayTime());
|
||||
repairResult = this.repairHandler(syncResult, payOrder);
|
||||
repairInfo.setFinishTime(paySyncResult.getPayTime());
|
||||
repairResult = this.repairHandler(paySyncResult, payOrder);
|
||||
}
|
||||
} catch (PayFailureException e) {
|
||||
// 同步失败, 返回失败响应, 同时记录失败的日志
|
||||
syncResult.setSyncStatus(PaySyncStatusEnum.FAIL);
|
||||
this.saveRecord(payOrder, syncResult, false, null, e.getMessage());
|
||||
paySyncResult.setSyncStatus(PaySyncStatusEnum.FAIL);
|
||||
this.saveRecord(payOrder, paySyncResult, false, null, e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
|
||||
// 同步成功记录日志
|
||||
this.saveRecord( payOrder, syncResult, !statusSync, repairResult.getRepairNo(), null);
|
||||
return new SyncResult()
|
||||
.setStatus(syncResult.getSyncStatus().getCode())
|
||||
.setRepair(!statusSync)
|
||||
.setRepairNo(repairResult.getRepairNo());
|
||||
this.saveRecord( payOrder, paySyncResult, !statusSync, repairResult.getRepairNo(), null);
|
||||
return new SyncResult().setStatus(paySyncResult.getSyncStatus().getCode());
|
||||
} finally {
|
||||
lockTemplate.releaseLock(lock);
|
||||
}
|
||||
@@ -223,7 +219,7 @@ public class PaySyncService {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new BizException("代码有问题");
|
||||
throw new PayFailureException("代码有问题");
|
||||
}
|
||||
}
|
||||
return repair;
|
||||
|
@@ -83,21 +83,21 @@ public class RefundSyncService {
|
||||
// 同步前处理, 主要预防请求过于迅速
|
||||
syncPayStrategy.doBeforeHandler();
|
||||
// 执行操作, 获取支付网关同步的结果
|
||||
RefundSyncResult syncResult = syncPayStrategy.doSyncStatus();
|
||||
RefundSyncResult refundSyncResult = syncPayStrategy.doSyncStatus();
|
||||
|
||||
// 判断是否同步成功
|
||||
if (Objects.equals(syncResult.getSyncStatus(), RefundSyncStatusEnum.FAIL)) {
|
||||
if (Objects.equals(refundSyncResult.getSyncStatus(), RefundSyncStatusEnum.FAIL)) {
|
||||
// 同步失败, 返回失败响应, 同时记录失败的日志
|
||||
this.saveRecord(refundOrder, syncResult, false, null, syncResult.getErrorMsg());
|
||||
throw new PayFailureException(syncResult.getErrorMsg());
|
||||
this.saveRecord(refundOrder, refundSyncResult, false, null, refundSyncResult.getErrorMsg());
|
||||
throw new PayFailureException(refundSyncResult.getErrorMsg());
|
||||
}
|
||||
// 订单的通道交易号是否一致, 不一致进行更新
|
||||
if (Objects.nonNull(syncResult.getOutRefundNo()) && !Objects.equals(syncResult.getOutRefundNo(), refundOrder.getOutRefundNo())){
|
||||
refundOrder.setOutRefundNo(syncResult.getOutRefundNo());
|
||||
if (Objects.nonNull(refundSyncResult.getOutRefundNo()) && !Objects.equals(refundSyncResult.getOutRefundNo(), refundOrder.getOutRefundNo())){
|
||||
refundOrder.setOutRefundNo(refundSyncResult.getOutRefundNo());
|
||||
refundOrderManager.updateById(refundOrder);
|
||||
}
|
||||
// 判断网关状态是否和支付单一致
|
||||
boolean statusSync = this.checkSyncStatus(syncResult, refundOrder);
|
||||
boolean statusSync = this.checkSyncStatus(refundSyncResult, refundOrder);
|
||||
RefundRepairResult repairResult = new RefundRepairResult();
|
||||
try {
|
||||
// 状态不一致,执行退款单修复逻辑
|
||||
@@ -107,21 +107,18 @@ public class RefundSyncService {
|
||||
if (Objects.isNull(repairInfo.getSource())){
|
||||
repairInfo.setSource(PayRepairSourceEnum.SYNC);
|
||||
}
|
||||
repairInfo.setFinishTime(syncResult.getFinishTime());
|
||||
repairResult = this.repairHandler(syncResult, refundOrder);
|
||||
repairInfo.setFinishTime(refundSyncResult.getFinishTime());
|
||||
repairResult = this.repairHandler(refundSyncResult, refundOrder);
|
||||
}
|
||||
} catch (PayFailureException e) {
|
||||
// 同步失败, 返回失败响应, 同时记录失败的日志
|
||||
syncResult.setSyncStatus(RefundSyncStatusEnum.FAIL);
|
||||
this.saveRecord(refundOrder, syncResult, false, null, e.getMessage());
|
||||
refundSyncResult.setSyncStatus(RefundSyncStatusEnum.FAIL);
|
||||
this.saveRecord(refundOrder, refundSyncResult, false, null, e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
// 同步成功记录日志
|
||||
this.saveRecord(refundOrder, syncResult, !statusSync, repairResult.getRepairNo(), null);
|
||||
return new SyncResult()
|
||||
.setStatus(syncResult.getSyncStatus().getCode())
|
||||
.setRepair(!statusSync)
|
||||
.setRepairNo(repairResult.getRepairNo());
|
||||
this.saveRecord(refundOrder, refundSyncResult, !statusSync, repairResult.getRepairNo(), null);
|
||||
return new SyncResult().setStatus(refundSyncResult.getSyncStatus().getCode());
|
||||
} finally {
|
||||
lockTemplate.releaseLock(lock);
|
||||
}
|
||||
|
@@ -366,11 +366,11 @@ public class UnionPayKit extends UnionPayService {
|
||||
X509CertSelector selector = new X509CertSelector();
|
||||
selector.setCertificate(cert);
|
||||
|
||||
Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
|
||||
Set<TrustAnchor> trustAnchors = new HashSet<>();
|
||||
trustAnchors.add(new TrustAnchor(rootCert, null));
|
||||
PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(trustAnchors, selector);
|
||||
|
||||
Set<X509Certificate> intermediateCerts = new HashSet<X509Certificate>();
|
||||
Set<X509Certificate> intermediateCerts = new HashSet<>();
|
||||
intermediateCerts.add(rootCert);
|
||||
intermediateCerts.add(middleCert);
|
||||
intermediateCerts.add(cert);
|
||||
@@ -389,9 +389,6 @@ public class UnionPayKit extends UnionPayService {
|
||||
catch (java.security.cert.CertPathBuilderException e) {
|
||||
LOG.error("verify certificate chain fail.", e);
|
||||
}
|
||||
catch (CertificateExpiredException e) {
|
||||
LOG.error("", e);
|
||||
}
|
||||
catch (GeneralSecurityException e) {
|
||||
LOG.error("", e);
|
||||
}
|
||||
@@ -516,9 +513,13 @@ public class UnionPayKit extends UnionPayService {
|
||||
@Override
|
||||
public String buildRequest(Map<String, Object> orderInfo, MethodType method) {
|
||||
StringBuffer sf = new StringBuffer();
|
||||
sf.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + payConfigStorage.getInputCharset() + "\"/></head><body>");
|
||||
sf.append("<form id = \"pay_form\" action=\"" + getFrontTransUrl() + "\" method=\"post\">");
|
||||
if (null != orderInfo && 0 != orderInfo.size()) {
|
||||
sf.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=")
|
||||
.append(payConfigStorage.getInputCharset())
|
||||
.append("\"/></head><body>");
|
||||
sf.append("<form id = \"pay_form\" action=\"")
|
||||
.append(getFrontTransUrl())
|
||||
.append("\" method=\"post\">");
|
||||
if (null != orderInfo && !orderInfo.isEmpty()) {
|
||||
for (Map.Entry<String, Object> entry : orderInfo.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
|
Reference in New Issue
Block a user