ref 数据结构/逻辑重构

This commit is contained in:
xxm1995
2024-04-24 20:39:48 +08:00
parent 6b4ac780d3
commit ad495b4a08
123 changed files with 681 additions and 2059 deletions

View File

@@ -0,0 +1,24 @@
package cn.bootx.platform.daxpay.demo.code;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 聚合支付相关枚举
* @author xxm
* @since 2024/2/9
*/
@Getter
@AllArgsConstructor
public enum AggregatePayEnum {
UA_ALI_PAY("Alipay", "支付宝"),
UA_WECHAT_PAY("MicroMessenger", "微信支付"),
UA_UNION_PAY("CloudPay", "云闪付");
/** 支付渠道字符编码 */
private final String code;
/** 名称 */
private final String name;
}

View File

@@ -22,7 +22,7 @@ public class AggregatePayInfo {
private String businessNo;
@Schema(description = "是否分账")
private boolean allocation;
private Boolean allocation;
/** 支付金额 */
@Schema(description = "支付金额")

View File

@@ -21,7 +21,7 @@ public class AggregateSimplePayParam {
private String businessNo;
@Schema(description = "是否分账")
private boolean allocation;
private Boolean allocation;
@Schema(description = "标题")
@NotNull

View File

@@ -20,10 +20,10 @@ public class CashierSimplePayParam {
@Schema(description = "业务号")
@NotNull
private String businessNo;
private String bizOrderNo;
@Schema(description = "是否分账")
private boolean allocation;
private Boolean allocation;
@Schema(description = "标题")
@NotNull
@@ -36,7 +36,7 @@ public class CashierSimplePayParam {
@Schema(description = "openId(微信支付时使用)")
private String openId;
@Schema(description = "支付")
@Schema(description = "支付")
@NotNull
private String channel;

View File

@@ -13,6 +13,7 @@ import lombok.Setter;
@Getter
@Setter
public class PayOrderResult {
/** 支付ID */
private Long paymentId;

View File

@@ -3,23 +3,23 @@ package cn.bootx.platform.daxpay.demo.service;
import cn.bootx.platform.common.core.exception.BizException;
import cn.bootx.platform.common.redis.RedisClient;
import cn.bootx.platform.common.spring.util.WebServletUtil;
import cn.bootx.platform.daxpay.demo.code.AggregatePayEnum;
import cn.bootx.platform.daxpay.demo.configuration.DaxPayDemoProperties;
import cn.bootx.platform.daxpay.demo.domain.AggregatePayInfo;
import cn.bootx.platform.daxpay.demo.param.AggregateSimplePayParam;
import cn.bootx.platform.daxpay.demo.result.PayOrderResult;
import cn.bootx.platform.daxpay.demo.result.WxJsapiSignResult;
import cn.bootx.platform.daxpay.sdk.code.AggregatePayEnum;
import cn.bootx.platform.daxpay.sdk.code.PayChannelEnum;
import cn.bootx.platform.daxpay.sdk.code.PayWayEnum;
import cn.bootx.platform.daxpay.sdk.code.PayMethodEnum;
import cn.bootx.platform.daxpay.sdk.model.assist.WxAccessTokenModel;
import cn.bootx.platform.daxpay.sdk.model.assist.WxAuthUrlModel;
import cn.bootx.platform.daxpay.sdk.model.pay.PayOrderModel;
import cn.bootx.platform.daxpay.sdk.model.pay.PayModel;
import cn.bootx.platform.daxpay.sdk.net.DaxPayKit;
import cn.bootx.platform.daxpay.sdk.param.assist.WxAccessTokenParam;
import cn.bootx.platform.daxpay.sdk.param.assist.WxAuthUrlParam;
import cn.bootx.platform.daxpay.sdk.param.channel.BarCodePayParam;
import cn.bootx.platform.daxpay.sdk.param.channel.WeChatPayParam;
import cn.bootx.platform.daxpay.sdk.param.pay.SimplePayParam;
import cn.bootx.platform.daxpay.sdk.param.pay.PayParam;
import cn.bootx.platform.daxpay.sdk.response.DaxPayResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.net.URLEncodeUtil;
@@ -58,7 +58,7 @@ public class AggregateService {
AggregatePayInfo aggregatePayInfo = new AggregatePayInfo()
.setTitle(param.getTitle())
.setBusinessNo(param.getBusinessNo())
.setAllocation(param.isAllocation())
.setAllocation(param.getAllocation())
.setAmount(amount);
String code = IdUtil.getSnowflakeNextIdStr();
String serverUrl = daxPayDemoProperties.getServerUrl();
@@ -143,17 +143,17 @@ public class AggregateService {
public WxJsapiSignResult wxJsapiPrePay(String aggregateCode, String openId) {
AggregatePayInfo aggregatePayInfo = getInfo(aggregateCode);
// 拼装支付发起参数
SimplePayParam simplePayParam = new SimplePayParam();
simplePayParam.setBusinessNo(aggregatePayInfo.getBusinessNo());
PayParam simplePayParam = new PayParam();
simplePayParam.setBizOrderNo(aggregatePayInfo.getBusinessNo());
simplePayParam.setTitle(aggregatePayInfo.getTitle());
simplePayParam.setAmount(aggregatePayInfo.getAmount());
simplePayParam.setChannel(PayChannelEnum.WECHAT.getCode());
simplePayParam.setPayWay(PayWayEnum.JSAPI.getCode());
simplePayParam.setMethod(PayMethodEnum.JSAPI.getCode());
// 设置微信专属请求参数
WeChatPayParam weChatPayParam = new WeChatPayParam();
weChatPayParam.setOpenId(openId);
simplePayParam.setChannelParam(weChatPayParam);
simplePayParam.setExtraParam(weChatPayParam);
String ip = Optional.ofNullable(WebServletUtil.getRequest())
.map(ServletUtil::getClientIP)
@@ -164,7 +164,7 @@ public class AggregateService {
// 同步回调地址 无效
simplePayParam.setReturnUrl(StrUtil.format("{}/result/success", daxPayDemoProperties.getFrontH5Url()));
DaxPayResult<PayOrderModel> execute = DaxPayKit.execute(simplePayParam);
DaxPayResult<PayModel> execute = DaxPayKit.execute(simplePayParam);
// 判断是否支付成功
if (execute.getCode() != 0){
throw new BizException(execute.getMsg());
@@ -177,25 +177,25 @@ public class AggregateService {
*/
public PayOrderResult aliH5Pay(String code) {
AggregatePayInfo aggregatePayInfo = getInfo(code);
SimplePayParam simplePayParam = new SimplePayParam();
simplePayParam.setBusinessNo(aggregatePayInfo.getBusinessNo());
simplePayParam.setTitle(aggregatePayInfo.getTitle());
simplePayParam.setAmount(aggregatePayInfo.getAmount());
simplePayParam.setChannel(PayChannelEnum.ALI.getCode());
simplePayParam.setPayWay(PayWayEnum.WAP.getCode());
PayParam payParam = new PayParam();
payParam.setBizOrderNo(aggregatePayInfo.getBusinessNo());
payParam.setTitle(aggregatePayInfo.getTitle());
payParam.setAmount(aggregatePayInfo.getAmount());
payParam.setChannel(PayChannelEnum.ALI.getCode());
payParam.setMethod(PayMethodEnum.WAP.getCode());
String ip = Optional.ofNullable(WebServletUtil.getRequest())
.map(ServletUtil::getClientIP)
.orElse("127.0.0.1");
simplePayParam.setClientIp(ip);
payParam.setClientIp(ip);
// 异步回调地址
simplePayParam.setNotNotify(true);
payParam.setNotNotify(true);
// 支付成功同步回调地址
simplePayParam.setReturnUrl(StrUtil.format("{}/result/success", daxPayDemoProperties.getFrontH5Url()));
payParam.setReturnUrl(StrUtil.format("{}/result/success", daxPayDemoProperties.getFrontH5Url()));
// 中途退出 目前经测试不生效
simplePayParam.setQuitUrl(StrUtil.format("{}/result/error", daxPayDemoProperties.getFrontH5Url()));
payParam.setQuitUrl(StrUtil.format("{}/result/error", daxPayDemoProperties.getFrontH5Url()));
DaxPayResult<PayOrderModel> execute = DaxPayKit.execute(simplePayParam);
DaxPayResult<PayModel> execute = DaxPayKit.execute(payParam);
// 判断是否支付成功
if (execute.getCode() != 0){
@@ -217,23 +217,23 @@ public class AggregateService {
.multiply(BigDecimal.valueOf(100))
.intValue();
SimplePayParam simplePayParam = new SimplePayParam();
simplePayParam.setBusinessNo(param.getBusinessNo());
simplePayParam.setAllocation(param.isAllocation());
PayParam simplePayParam = new PayParam();
simplePayParam.setBizOrderNo(param.getBusinessNo());
simplePayParam.setAllocation(param.getAllocation());
simplePayParam.setTitle(param.getTitle());
simplePayParam.setAmount(amount);
simplePayParam.setChannel(payChannel.getCode());
simplePayParam.setPayWay(PayWayEnum.BARCODE.getCode());
simplePayParam.setMethod(PayMethodEnum.BARCODE.getCode());
BarCodePayParam barCodePayParam = new BarCodePayParam();
barCodePayParam.setAuthCode(param.getAuthCode());
simplePayParam.setChannelParam(barCodePayParam);
simplePayParam.setExtraParam(barCodePayParam);
String ip = Optional.ofNullable(WebServletUtil.getRequest())
.map(ServletUtil::getClientIP)
.orElse("127.0.0.1");
simplePayParam.setClientIp(ip);
DaxPayResult<PayOrderModel> execute = DaxPayKit.execute(simplePayParam);
DaxPayResult<PayModel> execute = DaxPayKit.execute(simplePayParam);
// 判断是否支付成功
if (execute.getCode() != 0){

View File

@@ -2,24 +2,24 @@ package cn.bootx.platform.daxpay.demo.service;
import cn.bootx.platform.common.core.exception.BizException;
import cn.bootx.platform.common.spring.util.WebServletUtil;
import cn.bootx.platform.daxpay.demo.code.AggregatePayEnum;
import cn.bootx.platform.daxpay.demo.configuration.DaxPayDemoProperties;
import cn.bootx.platform.daxpay.demo.param.CashierSimplePayParam;
import cn.bootx.platform.daxpay.demo.result.PayOrderResult;
import cn.bootx.platform.daxpay.sdk.code.AggregatePayEnum;
import cn.bootx.platform.daxpay.sdk.code.PayChannelEnum;
import cn.bootx.platform.daxpay.sdk.code.PayMethodEnum;
import cn.bootx.platform.daxpay.sdk.code.PayStatusEnum;
import cn.bootx.platform.daxpay.sdk.code.PayWayEnum;
import cn.bootx.platform.daxpay.sdk.model.assist.WxAccessTokenModel;
import cn.bootx.platform.daxpay.sdk.model.assist.WxAuthUrlModel;
import cn.bootx.platform.daxpay.sdk.model.pay.PayModel;
import cn.bootx.platform.daxpay.sdk.model.pay.PayOrderModel;
import cn.bootx.platform.daxpay.sdk.model.pay.QueryPayOrderModel;
import cn.bootx.platform.daxpay.sdk.net.DaxPayKit;
import cn.bootx.platform.daxpay.sdk.param.assist.WxAccessTokenParam;
import cn.bootx.platform.daxpay.sdk.param.assist.WxAuthUrlParam;
import cn.bootx.platform.daxpay.sdk.param.channel.AliPayParam;
import cn.bootx.platform.daxpay.sdk.param.channel.WeChatPayParam;
import cn.bootx.platform.daxpay.sdk.param.pay.QueryPayOrderParam;
import cn.bootx.platform.daxpay.sdk.param.pay.SimplePayParam;
import cn.bootx.platform.daxpay.sdk.param.pay.PayParam;
import cn.bootx.platform.daxpay.sdk.param.pay.QueryPayParam;
import cn.bootx.platform.daxpay.sdk.response.DaxPayResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
@@ -50,38 +50,38 @@ public class CashierService {
*/
public PayOrderResult simplePayCashier(CashierSimplePayParam param){
// 将参数转换为简单支付参数
SimplePayParam simplePayParam = new SimplePayParam();
simplePayParam.setBusinessNo(param.getBusinessNo());
simplePayParam.setAllocation(param.isAllocation());
PayParam simplePayParam = new PayParam();
simplePayParam.setBizOrderNo(param.getChannel());
simplePayParam.setAllocation(param.getAllocation());
int amount = param.getAmount()
.multiply(BigDecimal.valueOf(100))
.intValue();
simplePayParam.setTitle(param.getTitle());
simplePayParam.setAmount(amount);
simplePayParam.setChannel(param.getChannel());
simplePayParam.setPayWay(param.getPayWay());
simplePayParam.setMethod(param.getPayWay());
// 支付宝通道
if (Objects.equals(PayChannelEnum.ALI.getCode(), param.getChannel())){
// 付款码支付
if (Objects.equals(PayWayEnum.BARCODE.getCode(), param.getPayWay())){
if (Objects.equals(PayMethodEnum.BARCODE.getCode(), param.getPayWay())){
AliPayParam aliPayParam = new AliPayParam();
aliPayParam.setAuthCode(param.getAuthCode());
simplePayParam.setChannelParam(aliPayParam);
simplePayParam.setExtraParam(aliPayParam);
}
}
// 微信通道
if (Objects.equals(PayChannelEnum.WECHAT.getCode(), param.getChannel())){
WeChatPayParam wechatPayParam = new WeChatPayParam();
// 付款码支付
if (Objects.equals(PayWayEnum.BARCODE.getCode(), param.getPayWay())){
if (Objects.equals(PayMethodEnum.BARCODE.getCode(), param.getPayWay())){
wechatPayParam.setAuthCode(param.getAuthCode());
simplePayParam.setChannelParam(wechatPayParam);
simplePayParam.setExtraParam(wechatPayParam);
}
// 微信jsapi 方式支付
if (Objects.equals(PayWayEnum.JSAPI.getCode(), param.getPayWay())){
if (Objects.equals(PayMethodEnum.JSAPI.getCode(), param.getPayWay())){
wechatPayParam.setOpenId(param.getOpenId());
simplePayParam.setChannelParam(wechatPayParam);
simplePayParam.setExtraParam(wechatPayParam);
}
}
String ip = Optional.ofNullable(WebServletUtil.getRequest())
@@ -92,19 +92,19 @@ public class CashierService {
simplePayParam.setReturnUrl(StrUtil.format("{}/result/success", daxPayDemoProperties.getFrontH5Url()));
// 发起支付
DaxPayResult<PayOrderModel> execute = DaxPayKit.execute(simplePayParam);
DaxPayResult<PayModel> execute = DaxPayKit.execute(simplePayParam);
// 判断是否支付成功
if (execute.getCode() != 0){
throw new BizException(execute.getMsg());
}
// 判断是否发起支付成功
PayOrderModel payOrderModel = execute.getData();
PayModel payModel = execute.getData();
// 状态 支付中或支付完成返回
List<String> list = Arrays.asList(PayStatusEnum.PROGRESS.getCode(), PayStatusEnum.SUCCESS.getCode());
if (list.contains(payOrderModel.getStatus())){
if (list.contains(payModel.getStatus())){
PayOrderResult payOrderResult = new PayOrderResult();
BeanUtil.copyProperties(payOrderModel, payOrderResult);
BeanUtil.copyProperties(payModel, payOrderResult);
return payOrderResult;
} else {
throw new BizException("订单状态异常,无法进行支付");
@@ -115,9 +115,9 @@ public class CashierService {
* 查询订单是否支付成功
*/
public boolean queryPayOrderSuccess(String businessNo){
QueryPayOrderParam queryPayOrderParam = new QueryPayOrderParam();
queryPayOrderParam.setBusinessNo(businessNo);
DaxPayResult<QueryPayOrderModel> execute = DaxPayKit.execute(queryPayOrderParam);
QueryPayParam queryPayOrderParam = new QueryPayParam();
queryPayOrderParam.setBizOrderNoeNo(businessNo);
DaxPayResult<PayOrderModel> execute = DaxPayKit.execute(queryPayOrderParam);
// 未查询到订单
if (execute.getCode() == 10010){
return false;
@@ -126,7 +126,7 @@ public class CashierService {
if (execute.getCode() != 0){
throw new BizException(execute.getMsg());
}
QueryPayOrderModel data = execute.getData();
PayOrderModel data = execute.getData();
String status = data.getStatus();
if (Objects.equals(status, PayStatusEnum.PROGRESS.getCode())){
return false;