feat SDK编写

This commit is contained in:
bootx
2024-02-02 21:33:46 +08:00
parent dd1d70dcfb
commit e2ab1ea2f0
57 changed files with 1302 additions and 44 deletions

View File

@@ -5,5 +5,5 @@ package cn.bootx.platform.daxpay.param;
* @author xxm
* @since 2023/12/17
*/
public interface IChannelParam {
public interface ChannelParam {
}

View File

@@ -1,6 +1,6 @@
package cn.bootx.platform.daxpay.param.channel;
import cn.bootx.platform.daxpay.param.IChannelParam;
import cn.bootx.platform.daxpay.param.ChannelParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -10,7 +10,7 @@ import lombok.Data;
*/
@Data
@Schema(title = "支付宝支付参数")
public class AliPayParam implements IChannelParam {
public class AliPayParam implements ChannelParam {
@Schema(description = "授权码(主动扫描用户的付款码)")
private String authCode;

View File

@@ -1,6 +1,6 @@
package cn.bootx.platform.daxpay.param.channel;
import cn.bootx.platform.daxpay.param.IChannelParam;
import cn.bootx.platform.daxpay.param.ChannelParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -12,7 +12,7 @@ import lombok.Data;
*/
@Data
@Schema(title = "储值卡支付参数")
public class VoucherPayParam implements IChannelParam {
public class VoucherPayParam implements ChannelParam {
@Schema(description = "储值卡号")
private String cardNo;

View File

@@ -1,6 +1,6 @@
package cn.bootx.platform.daxpay.param.channel;
import cn.bootx.platform.daxpay.param.IChannelParam;
import cn.bootx.platform.daxpay.param.ChannelParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -12,7 +12,7 @@ import lombok.Data;
*/
@Data
@Schema(title = "钱包支付参数")
public class WalletPayParam implements IChannelParam {
public class WalletPayParam implements ChannelParam {
@Schema(description = "钱包ID")
private Long walletId;

View File

@@ -1,6 +1,6 @@
package cn.bootx.platform.daxpay.param.channel;
import cn.bootx.platform.daxpay.param.IChannelParam;
import cn.bootx.platform.daxpay.param.ChannelParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -10,7 +10,7 @@ import lombok.Data;
*/
@Data
@Schema(title = "微信支付参数")
public class WeChatPayParam implements IChannelParam {
public class WeChatPayParam implements ChannelParam {
@Schema(description = "微信openId")
private String openId;

View File

@@ -48,5 +48,5 @@ public class PayChannelParam {
* @see WalletPayParam
*/
@Schema(description = "附加支付参数")
private String channelExtra;
private String channelParam;
}

View File

@@ -19,7 +19,7 @@ import java.time.LocalDateTime;
public abstract class PayCommonParam {
/** 客户端ip */
@NotBlank(message = "客户端ip不可为空")
// @NotBlank(message = "客户端ip不可为空")
@Schema(description = "客户端ip")
private String clientIp;
@@ -48,12 +48,12 @@ public abstract class PayCommonParam {
/** API版本号 */
@Schema(description = "API版本号")
@NotBlank(message = "API版本号必填")
// @NotBlank(message = "API版本号必填")
private String version = "1.0.0";
/** 请求时间,时间戳转时间 */
@Schema(description = "请求时间,传输时间戳")
@NotNull(message = "请求时间必填")
// @NotNull(message = "请求时间必填")
@JsonDeserialize(using = TimestampToLocalDateTimeDeserializer.class)
private LocalDateTime reqTime;

View File

@@ -50,7 +50,7 @@ public class SimplePayParam extends PayCommonParam{
*/
@Schema(description = "支付通道编码")
@NotBlank(message = "支付通道编码不可为空")
private String payChannel;
private String channel;
/**
* @see PayWayEnum#getCode()
@@ -70,8 +70,8 @@ public class SimplePayParam extends PayCommonParam{
* @see VoucherPayParam
* @see WalletPayParam
*/
@Schema(description = "附加支付参数")
private String channelExtra;
@Schema(description = "附加通道支付参数")
private String channelParam;
}

View File

@@ -14,6 +14,6 @@ import org.slf4j.MDC;
@Schema(title = "支付通用返回参数")
public class CommonResult {
@Schema(description = "请求ID")
private String reqId = MDC.get(CommonCode.TRACE_ID);
@Schema(description = "追踪ID")
private String traceId = MDC.get(CommonCode.TRACE_ID);
}

View File

@@ -29,7 +29,7 @@ public class PayResult extends CommonResult {
* @see PayChannelEnum#ASYNC_TYPE_CODE
*/
@Schema(description = "异步支付通道")
private String asyncPayChannel;
private String asyncChannel;
/** 支付参数体(通常用于发起异步支付的参数) */

View File

@@ -22,4 +22,7 @@ public class RefundResult extends CommonResult {
@Schema(description = "退款订单号, 如果请求时未传, 则默认使用退款ID")
private String refundNo;
@Schema(description = "退款状态")
private String status;
}

View File

@@ -153,7 +153,7 @@ public class PaySignUtil {
// 创建待签名字符串
String data = createLinkString(map);
// 将签名key追加到字符串最后
return "&key=" + signKey;
return data + "&key=" + signKey;
}
/**

View File

@@ -46,7 +46,7 @@ public class VoucherPayService {
VoucherPayParam voucherPayParam;
try {
// 储值卡参数验证
String extraParamsJson = payChannelParam.getChannelExtra();
String extraParamsJson = payChannelParam.getChannelParam();
if (StrUtil.isNotBlank(extraParamsJson)) {
voucherPayParam = JSONUtil.toBean(extraParamsJson, VoucherPayParam.class);
} else {

View File

@@ -32,7 +32,7 @@ public class PayNoticeResult {
* @see PayChannelEnum#ASYNC_TYPE_CODE
*/
@Schema(description = "异步支付通道")
private String asyncPayChannel;
private String asyncChannel;
@Schema(description = "支付金额")
private Integer amount;

View File

@@ -97,7 +97,7 @@ public class PayBuilder {
.setPayWay(channelParam.getWay())
.setAmount(channelParam.getAmount())
.setRefundableBalance(channelParam.getAmount())
.setChannelExtra(channelParam.getChannelExtra());
.setChannelExtra(channelParam.getChannelParam());
}
/**
@@ -126,7 +126,7 @@ public class PayBuilder {
paymentResult = new PayResult();
paymentResult.setPaymentId(payOrder.getId());
paymentResult.setAsyncPay(payOrder.isAsyncPay());
paymentResult.setAsyncPayChannel(payOrder.getAsyncChannel());
paymentResult.setAsyncChannel(payOrder.getAsyncChannel());
paymentResult.setStatus(payOrder.getStatus());
// 设置异步支付参数

View File

@@ -68,7 +68,7 @@ public class PayChannelOrderService {
.setAmount(payChannelParam.getAmount())
.setRefundableBalance(payChannelParam.getAmount())
.setPayTime(LocalDateTime.now())
.setChannelExtra(payChannelParam.getChannelExtra())
.setChannelExtra(payChannelParam.getChannelParam())
.setStatus(payStatus.getCode());
channelOrderManager.deleteByPaymentIdAndAsync(payOrder.getId());
channelOrderManager.save(payChannelOrder);
@@ -77,7 +77,7 @@ public class PayChannelOrderService {
payOrderChannelOpt.get()
.setPayWay(payChannelParam.getWay())
.setPayTime(LocalDateTime.now())
.setChannelExtra(payChannelParam.getChannelExtra())
.setChannelExtra(payChannelParam.getChannelParam())
.setStatus(payStatus.getCode());
channelOrderManager.updateById(payOrderChannelOpt.get());
}

View File

@@ -85,6 +85,7 @@ public class PayAssistService {
asyncPayInfo.setExpiredTime(payParam.getExpiredTime());
return;
}
// 读取本地时间
LocalDateTime paymentExpiredTime = PayUtil.getPaymentExpiredTime(platform.getOrderTimeout());
asyncPayInfo.setExpiredTime(paymentExpiredTime);
}

View File

@@ -102,10 +102,10 @@ public class PayService {
// 组装支付参数
PayParam payParam = new PayParam();
PayChannelParam payChannelParam = new PayChannelParam();
payChannelParam.setChannel(simplePayParam.getPayChannel());
payChannelParam.setChannel(simplePayParam.getChannel());
payChannelParam.setWay(simplePayParam.getPayWay());
payChannelParam.setAmount(simplePayParam.getAmount());
payChannelParam.setChannelExtra(simplePayParam.getChannelExtra());
payChannelParam.setChannelParam(simplePayParam.getChannelParam());
BeanUtil.copyProperties(simplePayParam,payParam, CopyOptions.create().ignoreNullValue());
payParam.setPayChannels(Collections.singletonList(payChannelParam));
// 复用支付下单接口

View File

@@ -52,7 +52,7 @@ public class AliPayStrategy extends AbsPayStrategy {
public void doBeforePayHandler() {
try {
// 支付宝参数验证
String extraParamsJson = this.getPayChannelParam().getChannelExtra();
String extraParamsJson = this.getPayChannelParam().getChannelParam();
if (StrUtil.isNotBlank(extraParamsJson)) {
this.aliPayParam = JSONUtil.toBean(extraParamsJson, AliPayParam.class);
}

View File

@@ -54,7 +54,7 @@ public class WalletPayStrategy extends AbsPayStrategy {
WalletPayParam walletPayParam = new WalletPayParam();
try {
// 钱包参数验证
String extraParamsJson = this.getPayChannelParam().getChannelExtra();
String extraParamsJson = this.getPayChannelParam().getChannelParam();
if (StrUtil.isNotBlank(extraParamsJson)) {
walletPayParam = JSONUtil.toBean(extraParamsJson, WalletPayParam.class);
}

View File

@@ -55,7 +55,7 @@ public class WeChatPayStrategy extends AbsPayStrategy {
public void doBeforePayHandler() {
try {
// 微信参数验证
String extraParamsJson = this.getPayChannelParam().getChannelExtra();
String extraParamsJson = this.getPayChannelParam().getChannelParam();
if (StrUtil.isNotBlank(extraParamsJson)) {
this.weChatPayParam = JSONUtil.toBean(extraParamsJson, WeChatPayParam.class);
}

View File

@@ -42,7 +42,7 @@ public class PayCallbackRecord extends MpCreateEntity implements EntityBaseFunct
* @see PayChannelEnum#getCode()
*/
@DbColumn(comment = "支付通道")
private String payChannel;
private String channel;
/**
* 回调类型

View File

@@ -30,7 +30,7 @@ public class PayCallbackRecordDto extends BaseDto {
* @see PayChannelEnum#getCode()
*/
@Schema(description = "支付通道")
private String payChannel;
private String channel;
/**
* 回调类型

View File

@@ -109,7 +109,7 @@ public abstract class AbsCallbackStrategy implements PayStrategy {
.orElse(null);
PayCallbackRecord payNotifyRecord = new PayCallbackRecord()
.setPayChannel(this.getChannel().getCode())
.setChannel(this.getChannel().getCode())
.setNotifyInfo(JSONUtil.toJsonStr(callbackInfo.getCallbackParam()))
.setOrderId(callbackInfo.getOrderId())
.setGatewayOrderNo(callbackInfo.getGatewayOrderNo())

View File

@@ -30,13 +30,12 @@ public class PayCallbackRecordQuery extends QueryOrder {
* @see PayChannelEnum#getCode()
*/
@Schema(description = "支付通道")
private String payChannel;
private String channel;
/**
* 回调处理状态
* @see PayCallbackStatusEnum
* @see RefundCallbackStatusEnum
*/
@Schema(description = "回调处理状态")
private String status;

View File

@@ -40,7 +40,7 @@ class PaymentSignServiceTest {
p1.setWay("wx_app");
AliPayParam aliPayParam = new AliPayParam();
aliPayParam.setAuthCode("6688");
p1.setChannelExtra(JSONUtil.toJsonStr(aliPayParam));
p1.setChannelParam(JSONUtil.toJsonStr(aliPayParam));
PayChannelParam p2 = new PayChannelParam();
p2.setAmount(100);
@@ -49,7 +49,7 @@ class PaymentSignServiceTest {
WeChatPayParam weChatPayParam = new WeChatPayParam();
weChatPayParam.setOpenId("w2qsz2xawe3gbhyyff28fs01fd");
weChatPayParam.setAuthCode("8866");
p2.setChannelExtra(JSONUtil.toJsonStr(weChatPayParam));
p2.setChannelParam(JSONUtil.toJsonStr(weChatPayParam));
List<PayChannelParam> payWays = Arrays.asList(p1, p2);
payParam.setPayChannels(payWays);