ref 回调通知和接口管理,swagger 开启自动平铺属性选项

This commit is contained in:
DaxPay
2024-05-01 17:37:27 +08:00
parent 66921cc1a7
commit b7a6674096
17 changed files with 53 additions and 69 deletions

View File

@@ -3,7 +3,7 @@ package cn.bootx.platform.daxpay.admin.controller.system;
import cn.bootx.platform.common.core.rest.Res;
import cn.bootx.platform.common.core.rest.ResResult;
import cn.bootx.platform.daxpay.service.core.system.payinfo.service.PayWayInfoService;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayWayInfoDto;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayMethodInfoDto;
import cn.bootx.platform.daxpay.service.param.system.payinfo.PayWayInfoParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -26,13 +26,13 @@ public class PayWayInfoController {
@Operation(summary = "获取全部")
@GetMapping("/findAll")
public ResResult<List<PayWayInfoDto>> findAll(){
public ResResult<List<PayMethodInfoDto>> findAll(){
return Res.ok(payWayInfoService.findAll());
}
@Operation(summary = "根据ID获取")
@GetMapping("/findById")
public ResResult<PayWayInfoDto> findById(Long id){
public ResResult<PayMethodInfoDto> findById(Long id){
return Res.ok(payWayInfoService.findById(id));
}

View File

@@ -26,10 +26,4 @@ public class ApiInfoLocal {
/** 响应参数是否签名 */
private boolean resSign;
/** 回调信息是否签名 */
private boolean noticeSign;
/** 是否记录请求的信息 */
private boolean record;
}

View File

@@ -2,10 +2,12 @@ package cn.bootx.platform.daxpay.service.core.payment.notice.result;
import cn.bootx.platform.daxpay.code.PayChannelEnum;
import cn.bootx.platform.daxpay.code.RefundStatusEnum;
import cn.bootx.platform.daxpay.result.PaymentCommonResult;
import cn.bootx.platform.daxpay.serializer.LocalDateTimeToTimestampSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
@@ -15,10 +17,11 @@ import java.time.LocalDateTime;
* @author xxm
* @since 2024/2/22
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@Schema(title = "退款通知消息")
public class RefundNoticeResult {
public class RefundNoticeResult extends PaymentCommonResult {
/** 退款号 */
@Schema(description = "退款号")
@@ -59,8 +62,4 @@ public class RefundNoticeResult {
/** 商户扩展参数,回调时会原样返回 */
@Schema(description = "商户扩展参数,回调时会原样返回")
private String attach;
/** 签名 */
@Schema(description = "签名")
private String sign;
}

View File

@@ -7,6 +7,7 @@ import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder;
import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrderExtra;
import cn.bootx.platform.daxpay.service.core.order.refund.entity.RefundOrder;
import cn.bootx.platform.daxpay.service.core.order.refund.entity.RefundOrderExtra;
import cn.bootx.platform.daxpay.service.core.payment.common.service.PaymentSignService;
import cn.bootx.platform.daxpay.service.core.payment.notice.result.PayNoticeResult;
import cn.bootx.platform.daxpay.service.core.payment.notice.result.RefundNoticeResult;
import cn.bootx.platform.daxpay.service.core.system.config.entity.PlatformConfig;
@@ -30,6 +31,7 @@ import java.util.Objects;
public class ClientNoticeAssistService {
private final PlatformConfigService configService;
private final PaymentSignService paymentSignService;
/**
@@ -63,7 +65,8 @@ public class ClientNoticeAssistService {
.setContent(JacksonUtil.toJson(payNoticeResult))
.setNoticeType(ClientNoticeTypeEnum.PAY.getType())
.setSendCount(0)
.setOrderId(order.getId())
.setTradeId(order.getId())
.setTradeNo(order.getOrderNo())
.setOrderStatus(order.getStatus());
}
@@ -71,7 +74,6 @@ public class ClientNoticeAssistService {
* 构建出退款通知任务对象
*/
public ClientNoticeTask buildRefundTask(RefundOrder order, RefundOrderExtra orderExtra){
// 创建退款通知内容
RefundNoticeResult payNoticeResult = new RefundNoticeResult()
.setRefundNo(order.getRefundNo())
@@ -82,21 +84,16 @@ public class ClientNoticeAssistService {
.setStatus(order.getStatus())
.setAttach(orderExtra.getAttach());
PlatformConfig config = configService.getConfig();
// 签名
if (Objects.equals(config.getSignType(), PaySignTypeEnum.MD5.getCode())){
payNoticeResult.setSign(PaySignUtil.md5Sign(payNoticeResult,config.getSignSecret()));
} else if (Objects.equals(config.getSignType(), PaySignTypeEnum.HMAC_SHA256.getCode())) {
payNoticeResult.setSign(PaySignUtil.hmacSha256Sign(payNoticeResult,config.getSignSecret()));
} else {
}
paymentSignService.sign(payNoticeResult);
return new ClientNoticeTask()
.setUrl(orderExtra.getNotifyUrl())
// 时间序列化进行了重写
.setContent(JacksonUtil.toJson(payNoticeResult))
.setNoticeType(ClientNoticeTypeEnum.REFUND.getType())
.setSendCount(0)
.setOrderId(order.getId())
.setTradeId(order.getId())
.setTradeNo(order.getRefundNo())
.setOrderStatus(order.getStatus());
}

View File

@@ -91,14 +91,14 @@ public class ClientNoticeService {
if (Objects.isNull(orderExtra)){
Optional<PayOrderExtra> extraOpt = payOrderExtraManager.findById(order.getId());
if (!extraOpt.isPresent()){
log.error("未找到支付扩展信息,数据错误,订单ID{}",order.getId());
log.error("未找到支付扩展信息,数据错误,订单{}",order.getOrderNo());
return;
}
orderExtra = extraOpt.get();
}
// 判断是否需要进行通知
if (StrUtil.isBlank(orderExtra.getNotifyUrl())){
log.info("支付订单无需通知,订单ID{}",order.getId());
log.info("支付订单无需通知,订单{}",order.getOrderNo());
return;
}
@@ -211,7 +211,7 @@ public class ClientNoticeService {
.execute();
body = execute.body();
} catch (Exception e) {
log.error("发送通知失败数据错误任务ID{}",task.getOrderId());
log.error("发送通知失败数据错误任务ID{}",task.getTradeId());
log.error("错误内容",e);
record.setErrorMsg(e.getMessage());
}
@@ -248,7 +248,7 @@ public class ClientNoticeService {
.execute();
body = execute.body();
} catch (Exception e) {
log.error("发送通知失败数据错误任务ID{}",task.getOrderId());
log.error("发送通知失败数据错误任务ID{}",task.getTradeId());
log.error("错误内容",e);
record.setErrorMsg(e.getMessage());
}

View File

@@ -61,12 +61,6 @@ public class PayApiConfig extends MpBaseEntity implements EntityBaseFunction<Pay
@DbColumn(comment = "响应参数是否签名")
private boolean resSign;
@DbColumn(comment = "回调信息是否签名")
private boolean noticeSign;
@DbColumn(comment = "是否记录请求的信息")
private boolean record;
@DbColumn(comment = "备注")
private String remark;

View File

@@ -60,9 +60,7 @@ public class PayApiConfigService {
.setReqSign(api.isReqSign())
.setResSign(api.isResSign())
.setNotice(api.isNotice())
.setNoticeUrl(api.getNoticeUrl())
.setNoticeSign(api.isNoticeSign())
.setRecord(api.isRecord());
.setNoticeUrl(api.getNoticeUrl());
}

View File

@@ -1,7 +1,7 @@
package cn.bootx.platform.daxpay.service.core.system.payinfo.convert;
import cn.bootx.platform.daxpay.service.core.system.payinfo.entity.PayWayInfo;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayWayInfoDto;
import cn.bootx.platform.daxpay.service.core.system.payinfo.entity.PayMethodInfo;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayMethodInfoDto;
import cn.bootx.platform.daxpay.service.param.system.payinfo.PayWayInfoParam;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@@ -15,7 +15,7 @@ import org.mapstruct.factory.Mappers;
public interface PayWayInfoConvert {
PayWayInfoConvert CONVERT = Mappers.getMapper(PayWayInfoConvert.class);
PayWayInfo convert(PayWayInfoParam in);
PayMethodInfo convert(PayWayInfoParam in);
PayWayInfoDto convert(PayWayInfo in);
PayMethodInfoDto convert(PayMethodInfo in);
}

View File

@@ -3,7 +3,7 @@ package cn.bootx.platform.daxpay.service.core.system.payinfo.entity;
import cn.bootx.platform.common.core.function.EntityBaseFunction;
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
import cn.bootx.platform.daxpay.service.core.system.payinfo.convert.PayWayInfoConvert;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayWayInfoDto;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayMethodInfoDto;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
@@ -23,8 +23,8 @@ import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
@DbTable(comment = "支付方式")
@TableName("pay_way_info")
public class PayWayInfo extends MpBaseEntity implements EntityBaseFunction<PayWayInfoDto> {
@TableName("pay_method_info")
public class PayMethodInfo extends MpBaseEntity implements EntityBaseFunction<PayMethodInfoDto> {
/** 需要与系统中配置的枚举一致 */
@DbColumn(comment = "代码")
@@ -40,7 +40,7 @@ public class PayWayInfo extends MpBaseEntity implements EntityBaseFunction<PayWa
@DbColumn(comment = "备注")
private String remark;
public static PayWayInfoDto convert(PayWayInfo in) {
public static PayMethodInfoDto convert(PayMethodInfo in) {
return PayWayInfoConvert.CONVERT.convert(in);
}
@@ -48,7 +48,7 @@ public class PayWayInfo extends MpBaseEntity implements EntityBaseFunction<PayWa
* 转换
*/
@Override
public PayWayInfoDto toDto() {
public PayMethodInfoDto toDto() {
return PayWayInfoConvert.CONVERT.convert(this);
}
}

View File

@@ -4,7 +4,7 @@ import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.util.ResultConvertUtil;
import cn.bootx.platform.daxpay.service.core.system.payinfo.dao.PayWayInfoManager;
import cn.bootx.platform.daxpay.service.core.system.payinfo.entity.PayWayInfo;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayWayInfoDto;
import cn.bootx.platform.daxpay.service.dto.system.payinfo.PayMethodInfoDto;
import cn.bootx.platform.daxpay.service.param.system.payinfo.PayWayInfoParam;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
@@ -29,7 +29,7 @@ public class PayWayInfoService {
/**
* 列表
*/
public List<PayWayInfoDto> findAll(){
public List<PayMethodInfoDto> findAll(){
return manager.findAll().stream()
.map(PayWayInfo::toDto)
.collect(Collectors.toList());
@@ -38,7 +38,7 @@ public class PayWayInfoService {
/**
* 单条
*/
public PayWayInfoDto findById(Long id){
public PayMethodInfoDto findById(Long id){
return ResultConvertUtil.dtoConvert(manager.findById(id));
}

View File

@@ -30,9 +30,13 @@ import java.time.LocalDateTime;
@TableName("pay_client_notice_task")
public class ClientNoticeTask extends MpBaseEntity implements EntityBaseFunction<ClientNoticeTaskDto> {
/** 本地订单ID */
@DbColumn(comment = "本地订单ID")
private Long orderId;
/** 本地交易ID */
@DbColumn(comment = "本地交易ID")
private Long tradeId;
/** 本地订单号 */
@DbColumn(comment = "本地订单号")
private String tradeNo;
/**
* 消息类型

View File

@@ -20,9 +20,13 @@ import java.time.LocalDateTime;
@Schema(title = "消息通知任务")
public class ClientNoticeTaskDto extends BaseDto {
/** 本地订单ID */
@Schema(description = "本地订单ID")
private Long orderId;
/** 本地交易ID */
@Schema(description = "本地交易ID")
private Long tradeId;
/** 本地订单号 */
@Schema(description = "本地订单号")
private String tradeNo;
/**
* 回调类型

View File

@@ -46,15 +46,6 @@ public class PayApiConfigDto extends BaseDto {
@Schema(description = "请求参数是否签名")
private boolean reqSign;
@Schema(description = "响应参数是否签名")
private boolean resSign;
@Schema(description = "回调信息是否签名")
private boolean noticeSign;
@Schema(description = "是否记录请求的信息")
private boolean record;
@Schema(description = "备注")
private String remark;

View File

@@ -15,7 +15,7 @@ import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
@Schema(title = "支付方式信息")
public class PayWayInfoDto extends BaseDto {
public class PayMethodInfoDto extends BaseDto {
/** 需要与系统中配置的枚举一致 */
@Schema(description = "代码")

View File

@@ -32,9 +32,6 @@ public class PayApiConfigParam {
@Schema(description = "响应参数是否签名")
private boolean resSign;
@Schema(description = "回调信息是否签名")
private boolean noticeSign;
@Schema(description = "是否记录请求的信息")
private boolean record;

View File

@@ -53,6 +53,10 @@ spring:
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
# swagger openapi 接口文档配置
springdoc:
# 自动展开参数
default-flat-param-object: true
# 开发时显示debug日志
logging:
level: