支付回调 重试机制
扫码支付 条码校验
This commit is contained in:
@@ -37,7 +37,7 @@ public class NotifyController {
|
|||||||
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
||||||
AssertUtil.isNull(czg, "支付回调数据为空");
|
AssertUtil.isNull(czg, "支付回调数据为空");
|
||||||
log.info("支付回调数据为:{}", czg);
|
log.info("支付回调数据为:{}", czg);
|
||||||
orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg);
|
orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg, 0);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class OrderPayment implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String tradeNumber;
|
private String tradeNumber;
|
||||||
|
|
||||||
@Column(onInsertValue = "now()")
|
@Column(onUpdateValue = "now()")
|
||||||
private LocalDateTime payTime;
|
private LocalDateTime payTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
|
|||||||
|
|
||||||
CzgResult<Object> mergeOrder(MergeOrderDTO param);
|
CzgResult<Object> mergeOrder(MergeOrderDTO param);
|
||||||
|
|
||||||
void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
|
void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson,int retryCount);
|
||||||
|
|
||||||
void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
|
void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ import java.math.BigDecimal;
|
|||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.MAX_RETRIES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单表 服务层实现。
|
* 订单表 服务层实现。
|
||||||
@@ -106,6 +111,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
private ShopCouponService couponService;
|
private ShopCouponService couponService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopActivateCouponRecordService couponRecordService;
|
private ShopActivateCouponRecordService couponRecordService;
|
||||||
|
// 延迟 5 秒
|
||||||
|
private static final long DELAY = 5;
|
||||||
|
//重试次数
|
||||||
|
private static final int MAX_RETRIES = 3;
|
||||||
|
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param) {
|
public Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param) {
|
||||||
@@ -604,11 +614,16 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson) {
|
public void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson, int retryCount) {
|
||||||
CzgPayNotifyDTO czgCallBackDto = JSONObject.parseObject(resultJson.toString(), CzgPayNotifyDTO.class);
|
CzgPayNotifyDTO czgCallBackDto = JSONObject.parseObject(resultJson.toString(), CzgPayNotifyDTO.class);
|
||||||
OrderPayment payment = paymentService.queryChain().eq(OrderPayment::getOrderNo, orderNo).one();
|
OrderPayment payment = paymentService.queryChain().eq(OrderPayment::getOrderNo, orderNo).one();
|
||||||
if (payment == null) {
|
if (payment == null) {
|
||||||
log.error("订单支付回调失败,支付记录不存在,payment:{}", payment);
|
if (retryCount < MAX_RETRIES) {
|
||||||
|
log.info("支付记录不存在,第 {} 次重试,将在 {} 秒后进行", retryCount + 1, DELAY);
|
||||||
|
executorService.schedule(() -> payCallBackOrder(orderNo, resultJson, retryCount + 1), DELAY, TimeUnit.SECONDS);
|
||||||
|
} else {
|
||||||
|
log.error("订单支付回调失败, 达到最大重试次数, 支付记录不存在, orderNo: {}", orderNo);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(payment.getTradeNumber())) {
|
if (StrUtil.isNotBlank(payment.getTradeNumber())) {
|
||||||
|
|||||||
@@ -772,14 +772,15 @@ public class PayServiceImpl implements PayService {
|
|||||||
|
|
||||||
private CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData) {
|
private CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData) {
|
||||||
AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试");
|
AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试");
|
||||||
|
if (bizData.getAuthCode().length() > 26) {
|
||||||
|
throw new CzgException("支付失败,不支持的条码");
|
||||||
|
}
|
||||||
ShopMerchant shopMerchant = getMerchant(shopId);
|
ShopMerchant shopMerchant = getMerchant(shopId);
|
||||||
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
|
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
|
||||||
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
|
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
|
||||||
String firstTwoDigitsStr = bizData.getAuthCode().substring(0, 2);
|
String firstTwoDigitsStr = bizData.getAuthCode().substring(0, 2);
|
||||||
|
|
||||||
// 将截取的字符串转换为整数
|
// 将截取的字符串转换为整数
|
||||||
int firstTwoDigits = Integer.parseInt(firstTwoDigitsStr);
|
int firstTwoDigits = Integer.parseInt(firstTwoDigitsStr);
|
||||||
|
|
||||||
// 判断范围
|
// 判断范围
|
||||||
if (firstTwoDigits >= 10 && firstTwoDigits <= 15) {
|
if (firstTwoDigits >= 10 && firstTwoDigits <= 15) {
|
||||||
//微信支付
|
//微信支付
|
||||||
|
|||||||
Reference in New Issue
Block a user