mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	调整渠道支付通知地址为统一的地址
This commit is contained in:
		@@ -24,9 +24,9 @@ public interface PayErrorCodeCoreConstants {
 | 
			
		||||
    ErrorCode CHANNEL_NOT_EXISTS = new ErrorCode(1007001003, "支付渠道不存在");
 | 
			
		||||
    ErrorCode CHANNEL_EXIST_SAME_CHANNEL_ERROR = new ErrorCode(1007001005, "已存在相同的渠道");
 | 
			
		||||
    ErrorCode CHANNEL_WECHAT_VERSION_2_MCH_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v2版本中商户密钥不可为空");
 | 
			
		||||
    ErrorCode CHANNEL_WECHAT_VERSION_3_PRIVATE_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本apiclient_key.pem不可为空");
 | 
			
		||||
    ErrorCode CHANNEL_WECHAT_VERSION_3_CERT_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本中apiclient_cert.pem不可为空");
 | 
			
		||||
 | 
			
		||||
    ErrorCode CHANNEL_WECHAT_VERSION_3_PRIVATE_KEY_IS_NULL = new ErrorCode(1007001007,"微信渠道v3版本apiclient_key.pem不可为空");
 | 
			
		||||
    ErrorCode CHANNEL_WECHAT_VERSION_3_CERT_KEY_IS_NULL = new ErrorCode(1007001008,"微信渠道v3版本中apiclient_cert.pem不可为空");
 | 
			
		||||
    ErrorCode PAY_CHANNEL_NOTIFY_VERIFY_FAILED = new ErrorCode(1007001009, "渠道通知校验失败");
 | 
			
		||||
    /**
 | 
			
		||||
     * ========== ORDER 模块 1-007-002-000 ==========
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,25 @@
 | 
			
		||||
package cn.iocoder.yudao.coreservice.modules.pay.service.order;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 支付通用 Core Service
 | 
			
		||||
 *
 | 
			
		||||
 * @author jason
 | 
			
		||||
 */
 | 
			
		||||
public interface PayCommonCoreService {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 验证是否是渠道通知
 | 
			
		||||
     * @param notifyData 通知数据
 | 
			
		||||
     */
 | 
			
		||||
    void verifyNotifyData(Long channelId, PayNotifyDataDTO notifyData);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 支付宝的支付回调通知,和退款回调通知 地址是同一个
 | 
			
		||||
     * 是否是退款回调通知
 | 
			
		||||
     * @param notifyData  通知数据
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    boolean isRefundNotify(Long channelId, PayNotifyDataDTO notifyData);
 | 
			
		||||
}
 | 
			
		||||
@@ -43,10 +43,9 @@ public interface PayOrderCoreService {
 | 
			
		||||
    * 通知支付单成功
 | 
			
		||||
    *
 | 
			
		||||
    * @param channelId 渠道编号
 | 
			
		||||
    * @param channelCode 渠道编码
 | 
			
		||||
    * @param notifyData 通知数据
 | 
			
		||||
    */
 | 
			
		||||
   void notifyPayOrder(Long channelId, String channelCode, PayNotifyDataDTO notifyData) throws Exception;
 | 
			
		||||
   void notifyPayOrder(Long channelId,  PayNotifyDataDTO notifyData) throws Exception;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -23,11 +23,10 @@ public interface PayRefundCoreService {
 | 
			
		||||
    /**
 | 
			
		||||
     * 渠道的退款通知
 | 
			
		||||
     * @param channelId  渠道编号
 | 
			
		||||
     * @param channelCode 渠道编码
 | 
			
		||||
     * @param notifyData  通知数据
 | 
			
		||||
     * @throws Exception 退款通知异常
 | 
			
		||||
     */
 | 
			
		||||
    void notifyPayRefund(Long channelId, String channelCode, PayNotifyDataDTO notifyData) throws Exception;
 | 
			
		||||
    void notifyPayRefund(Long channelId, PayNotifyDataDTO notifyData) throws Exception;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,62 @@
 | 
			
		||||
package cn.iocoder.yudao.coreservice.modules.pay.service.order.impl;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
 | 
			
		||||
import cn.iocoder.yudao.coreservice.modules.pay.service.merchant.PayChannelCoreService;
 | 
			
		||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayCommonCoreService;
 | 
			
		||||
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
 | 
			
		||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
 | 
			
		||||
import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_CHANNEL_CLIENT_NOT_FOUND;
 | 
			
		||||
import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_CHANNEL_NOTIFY_VERIFY_FAILED;
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 支付通用 Core Service 实现类
 | 
			
		||||
 *
 | 
			
		||||
 * @author jason
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class PayCommonCoreServiceImpl implements PayCommonCoreService {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    private PayChannelCoreService payChannelCoreService;
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    private PayClientFactory payClientFactory;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void verifyNotifyData(Long channelId, PayNotifyDataDTO notifyData) {
 | 
			
		||||
        // 校验支付渠道是否有效
 | 
			
		||||
        PayChannelDO channel = payChannelCoreService.validPayChannel(channelId);
 | 
			
		||||
        // 校验支付客户端是否正确初始化
 | 
			
		||||
        PayClient client = payClientFactory.getPayClient(channel.getId());
 | 
			
		||||
        if (client == null) {
 | 
			
		||||
            log.error("[notifyPayOrder][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
 | 
			
		||||
            throw exception(PAY_CHANNEL_CLIENT_NOT_FOUND);
 | 
			
		||||
        }
 | 
			
		||||
        boolean verifyResult = client.verifyNotifyData(notifyData);
 | 
			
		||||
        if(!verifyResult){
 | 
			
		||||
            //渠道通知验证失败
 | 
			
		||||
            throw exception(PAY_CHANNEL_NOTIFY_VERIFY_FAILED);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isRefundNotify(Long channelId, PayNotifyDataDTO notifyData) {
 | 
			
		||||
        // 校验支付渠道是否有效
 | 
			
		||||
        PayChannelDO channel = payChannelCoreService.validPayChannel(channelId);
 | 
			
		||||
        // 校验支付客户端是否正确初始化
 | 
			
		||||
        PayClient client = payClientFactory.getPayClient(channel.getId());
 | 
			
		||||
        if (client == null) {
 | 
			
		||||
            log.error("[notifyPayOrder][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
 | 
			
		||||
            throw exception(PAY_CHANNEL_CLIENT_NOT_FOUND);
 | 
			
		||||
        }
 | 
			
		||||
        return client.isRefundNotify(notifyData);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -155,24 +155,22 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据支付渠道的编码,生成支付渠道的返回地址
 | 
			
		||||
     * @param channel
 | 
			
		||||
     * @return
 | 
			
		||||
     * @param channel 支付渠道
 | 
			
		||||
     * @return 支付成功返回的地址。 配置地址 + "/" + channel id
 | 
			
		||||
     */
 | 
			
		||||
    private String genChannelReturnUrl(PayChannelDO channel) {
 | 
			
		||||
        return payProperties.getPayReturnUrl() + "/" + StrUtil.replace(channel.getCode(), "_", "-")
 | 
			
		||||
                + "/" + channel.getId();
 | 
			
		||||
        return payProperties.getPayReturnUrl() + "/" + channel.getId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据支付渠道的编码,生成支付渠道的回调地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param channel 支付渠道
 | 
			
		||||
     * @return 支付渠道的回调地址
 | 
			
		||||
     * @return 支付渠道的回调地址  配置地址 + "/" + channel id
 | 
			
		||||
     */
 | 
			
		||||
    private String genChannelPayNotifyUrl(PayChannelDO channel) {
 | 
			
		||||
        // _ 转化为 - 的原因,是因为 URL 我们统一采用中划线的原则
 | 
			
		||||
        return payProperties.getPayNotifyUrl() + "/" + StrUtil.replace(channel.getCode(), "_", "-")
 | 
			
		||||
                + "/" + channel.getId();
 | 
			
		||||
        //去掉channel code, 似乎没啥用, 用统一的回调地址
 | 
			
		||||
        return payProperties.getPayNotifyUrl() + "/" + channel.getId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String generateOrderExtensionNo() {
 | 
			
		||||
@@ -195,7 +193,7 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional
 | 
			
		||||
    public void notifyPayOrder(Long channelId, String channelCode, PayNotifyDataDTO notifyData) throws Exception {
 | 
			
		||||
    public void notifyPayOrder(Long channelId,  PayNotifyDataDTO notifyData) throws Exception {
 | 
			
		||||
        // TODO 芋艿,记录回调日志
 | 
			
		||||
        log.info("[notifyPayOrder][channelId({}) 回调数据({})]", channelId, notifyData.getBody());
 | 
			
		||||
 | 
			
		||||
@@ -207,7 +205,7 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService {
 | 
			
		||||
            log.error("[notifyPayOrder][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
 | 
			
		||||
            throw exception(PAY_CHANNEL_CLIENT_NOT_FOUND);
 | 
			
		||||
        }
 | 
			
		||||
        //TODO @jason 校验 是否支付宝调用。 使用 支付宝publickey 或者payclient 加一个校验方法
 | 
			
		||||
 | 
			
		||||
        // 解析支付结果
 | 
			
		||||
        PayOrderNotifyRespDTO notifyRespDTO = client.parseOrderNotify(notifyData);
 | 
			
		||||
 | 
			
		||||
@@ -222,7 +220,7 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService {
 | 
			
		||||
            throw exception(PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING);
 | 
			
		||||
        }
 | 
			
		||||
        // 1.2 更新 PayOrderExtensionDO
 | 
			
		||||
        //TODO @jason notifyRespDTO.getTradeStatus() 需要根据不同的状态更新成不同的值 PayOrderStatusEnum
 | 
			
		||||
        //TODO 支付宝交易超时 TRADE_FINISHED 需要更新交易关闭
 | 
			
		||||
        int updateCounts = payOrderExtensionCoreMapper.updateByIdAndStatus(orderExtension.getId(),
 | 
			
		||||
                PayOrderStatusEnum.WAITING.getStatus(), PayOrderExtensionDO.builder().id(orderExtension.getId())
 | 
			
		||||
                        .status(PayOrderStatusEnum.SUCCESS.getStatus()).channelNotifyData(notifyData.getBody()).build());
 | 
			
		||||
@@ -241,7 +239,7 @@ public class PayOrderCoreServiceImpl implements PayOrderCoreService {
 | 
			
		||||
        }
 | 
			
		||||
        // 2.2 更新 PayOrderDO
 | 
			
		||||
        updateCounts = payOrderCoreMapper.updateByIdAndStatus(order.getId(), PayOrderStatusEnum.WAITING.getStatus(),
 | 
			
		||||
                PayOrderDO.builder().status(PayOrderStatusEnum.SUCCESS.getStatus()).channelId(channelId).channelCode(channelCode)
 | 
			
		||||
                PayOrderDO.builder().status(PayOrderStatusEnum.SUCCESS.getStatus()).channelId(channelId).channelCode(channel.getCode())
 | 
			
		||||
                        .successTime(notifyRespDTO.getSuccessTime()).successExtensionId(orderExtension.getId())
 | 
			
		||||
                        .channelOrderNo(notifyRespDTO.getChannelOrderNo()).channelUserId(notifyRespDTO.getChannelUserId())
 | 
			
		||||
                        .notifyTime(new Date()).build());
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,9 @@ public class PayRefundChannelQueryHandler extends PayRefundAbstractChannelPostHa
 | 
			
		||||
        //更新退款单表
 | 
			
		||||
        PayRefundDO updateRefundDO = new PayRefundDO();
 | 
			
		||||
        updateRefundDO.setId(respBO.getRefundId())
 | 
			
		||||
                .setStatus(refundStatus.getStatus());
 | 
			
		||||
                .setStatus(refundStatus.getStatus())
 | 
			
		||||
                .setChannelErrorCode(respBO.getChannelErrCode())
 | 
			
		||||
                .setChannelErrorMsg(respBO.getChannelErrMsg());
 | 
			
		||||
        updatePayRefund(updateRefundDO);
 | 
			
		||||
 | 
			
		||||
        PayOrderDO updateOrderDO = new PayOrderDO();
 | 
			
		||||
 
 | 
			
		||||
@@ -182,7 +182,7 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void notifyPayRefund(Long channelId, String channelCode, PayNotifyDataDTO notifyData) {
 | 
			
		||||
    public void notifyPayRefund(Long channelId, PayNotifyDataDTO notifyData) {
 | 
			
		||||
        log.info("[notifyPayRefund][channelId({}) 回调数据({})]", channelId, notifyData.getBody());
 | 
			
		||||
        // 校验支付渠道是否有效
 | 
			
		||||
        PayChannelDO channel = payChannelCoreService.validPayChannel(channelId);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user