mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-09 22:45:58 +08:00
feat(checkout): 重构收银台相关参数和接口
- 更新了 CheckoutAuthCodeParam、CheckoutAuthUrlParam 和 CheckoutPayParam等参数类的结构和字段- 修改了 CheckoutController 中的接口,增加了生成授权链接和获取授权结果的功能 - 重构了 CheckoutService 中的 generateAuthUrl 和 auth 方法,支持聚合支付类型 - 更新了 AbsCheckoutStrategy 和 WechatCheckoutStrategy 中的 generateAuthUrl 方法签名
This commit is contained in:
@@ -9,7 +9,6 @@ import org.dromara.daxpay.channel.wechat.service.assist.WechatAuthService;
|
||||
import org.dromara.daxpay.core.enums.ChannelAuthStatusEnum;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.core.param.assist.AuthCodeParam;
|
||||
import org.dromara.daxpay.core.param.cashier.CashierCodeAuthUrlParam;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutPayParam;
|
||||
import org.dromara.daxpay.core.param.trade.pay.PayParam;
|
||||
import org.dromara.daxpay.core.result.assist.AuthResult;
|
||||
@@ -41,8 +40,8 @@ public class WechatCheckoutStrategy extends AbsCheckoutStrategy {
|
||||
* 生成授权链接, 主要是微信类通道使用, 用于获取OpenId
|
||||
*/
|
||||
@Override
|
||||
public String generateAuthUrl(CashierCodeAuthUrlParam param) {
|
||||
String redirectUrl = StrUtil.format("/checkout/wechat/{}", param.getCashierCode());
|
||||
public String generateAuthUrl(String orderNo) {
|
||||
String redirectUrl = StrUtil.format("/checkout/wechat/{}", orderNo);
|
||||
return wechatAuthService.generateInnerAuthUrl(redirectUrl);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,23 +3,30 @@ package org.dromara.daxpay.core.param.checkout;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.daxpay.core.enums.CheckoutAggregateEnum;
|
||||
|
||||
/**
|
||||
* 获取通道收银认证结果参数
|
||||
* 获取收银台认证结果参数
|
||||
* @author xxm
|
||||
* @since 2024/9/28
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "收银台认证参数")
|
||||
@Schema(title = "获取收银台认证结果参数")
|
||||
public class CheckoutAuthCodeParam {
|
||||
|
||||
@Schema(description = "应用号")
|
||||
private String appId;
|
||||
/** 要支付的订单号 */
|
||||
@Schema(description = "要支付的订单号")
|
||||
private String orderNo;
|
||||
|
||||
@Schema(description = "收银台类型")
|
||||
private String cashierType;
|
||||
/**
|
||||
* 聚合支付类型
|
||||
* @see CheckoutAggregateEnum
|
||||
*/
|
||||
@Schema(description = "聚合支付类型")
|
||||
private String aggregateType;
|
||||
|
||||
/** 认证Code */
|
||||
@Schema(description = "认证Code")
|
||||
private String authCode;
|
||||
}
|
||||
|
||||
@@ -6,22 +6,22 @@ import lombok.experimental.Accessors;
|
||||
import org.dromara.daxpay.core.enums.CheckoutAggregateEnum;
|
||||
|
||||
/**
|
||||
* 获取通道收银认证url参数
|
||||
* 收银台认证链接生成参数
|
||||
* @author xxm
|
||||
* @since 2024/9/28
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "通道收银认证参数")
|
||||
@Schema(title = "收银台认证链接生成参数")
|
||||
public class CheckoutAuthUrlParam {
|
||||
|
||||
@Schema(description = "要支付的订单号")
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 聚合支付类型
|
||||
* @see CheckoutAggregateEnum
|
||||
*/
|
||||
@Schema(description = "聚合支付类型")
|
||||
private String aggregateType;
|
||||
|
||||
@Schema(description = "收银台类型")
|
||||
private String cashierType;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,4 @@ public class CheckoutPayParam {
|
||||
|
||||
@Schema(description = "付款码")
|
||||
private String barCode;
|
||||
|
||||
@Schema(description = "描述")
|
||||
private String description;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ import org.dromara.daxpay.core.enums.PayMethodEnum;
|
||||
public class CheckoutAggregateConfigResult {
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
* 聚合支付类型
|
||||
* @see CheckoutAggregateEnum
|
||||
*/
|
||||
@Schema(description = "支付类型")
|
||||
@Schema(description = "聚合支付类型")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ public class CheckoutAggregateOrderAndConfigResult {
|
||||
private CheckoutOrderResult order;
|
||||
|
||||
/** 收银台配置信息 */
|
||||
@Schema(description = "配置信息")
|
||||
@Schema(description = "收银台配置信息")
|
||||
private CheckoutConfigResult config;
|
||||
|
||||
/** 收银台聚合配置信息 */
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CashierCodeController {
|
||||
return Res.ok(cashierCodeService.generateAuthUrl(param));
|
||||
}
|
||||
|
||||
@Operation(summary = "授权获取结果")
|
||||
@Operation(summary = "获取授权结果")
|
||||
@PostMapping("/auth")
|
||||
public Result<AuthResult> auth(@RequestBody CashierCodeAuthCodeParam param){
|
||||
ValidationUtil.validateParam(param);
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package org.dromara.daxpay.service.controller.unipay;
|
||||
|
||||
import cn.bootx.platform.core.annotation.IgnoreAuth;
|
||||
import cn.bootx.platform.core.rest.Res;
|
||||
import cn.bootx.platform.core.rest.result.Result;
|
||||
import cn.bootx.platform.core.util.ValidationUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutAuthCodeParam;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutAuthUrlParam;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutCreatParam;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutPayParam;
|
||||
import org.dromara.daxpay.core.result.DaxResult;
|
||||
import org.dromara.daxpay.core.result.assist.AuthResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutAggregateOrderAndConfigResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutOrderAndConfigResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutPayResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutUrlResult;
|
||||
import org.dromara.daxpay.core.util.DaxRes;
|
||||
import org.dromara.daxpay.service.common.anno.PaymentVerify;
|
||||
@@ -37,22 +43,42 @@ public class CheckoutController {
|
||||
return DaxRes.ok(checkoutService.creat(checkoutParam));
|
||||
}
|
||||
|
||||
@IgnoreAuth
|
||||
@Operation(summary = "获取收银台订单和配置信息")
|
||||
@GetMapping("/getOrderAndConfig")
|
||||
public Result<CheckoutOrderAndConfigResult> getOrderAndConfig(String orderNo, String checkoutType){
|
||||
return Res.ok(checkoutQueryService.getOrderAndConfig(orderNo, checkoutType));
|
||||
}
|
||||
|
||||
@IgnoreAuth
|
||||
@Operation(summary = "获取聚合支付配置")
|
||||
@GetMapping("/getAggregateConfig")
|
||||
public Result<CheckoutAggregateOrderAndConfigResult> getAggregateConfig(String orderNo, String checkoutType){
|
||||
return Res.ok(checkoutQueryService.getAggregateConfig(orderNo, checkoutType));
|
||||
public Result<CheckoutAggregateOrderAndConfigResult> getAggregateConfig(String orderNo, String aggregateType){
|
||||
return Res.ok(checkoutQueryService.getAggregateConfig(orderNo, aggregateType));
|
||||
}
|
||||
|
||||
@IgnoreAuth
|
||||
@Operation(summary = "获取收银台所需授权链接, 用于获取OpenId一类的信息")
|
||||
@PostMapping("/generateAuthUrl")
|
||||
public Result<String> generateAuthUrl(@RequestBody CheckoutAuthUrlParam param){
|
||||
ValidationUtil.validateParam(param);
|
||||
return Res.ok(checkoutService.generateAuthUrl(param));
|
||||
}
|
||||
|
||||
@IgnoreAuth
|
||||
@Operation(summary = "获取授权结果")
|
||||
@PostMapping("/auth")
|
||||
public Result<AuthResult> auth(@RequestBody CheckoutAuthCodeParam param){
|
||||
ValidationUtil.validateParam(param);
|
||||
return Res.ok(checkoutService.auth(param));
|
||||
}
|
||||
|
||||
|
||||
@IgnoreAuth
|
||||
@Operation(summary = "发起支付")
|
||||
@PostMapping("/pay")
|
||||
public Result<Void> pay(@RequestBody CheckoutPayParam checkoutParam){
|
||||
return Res.ok();
|
||||
public Result<CheckoutPayResult> pay(@RequestBody CheckoutPayParam checkoutParam){
|
||||
return Res.ok(checkoutService.pay(checkoutParam));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ public class CheckoutQueryService {
|
||||
.setAmount(payOrder.getAmount())
|
||||
.setBizOrderNo(payOrder.getBizOrderNo())
|
||||
.setOrderNo(payOrder.getOrderNo());
|
||||
checkoutInfoResult.setOrder(order);
|
||||
// 获取收银台配置
|
||||
checkoutInfoResult.setConfig(this.getConfig(payOrder.getAppId()));
|
||||
// 获取聚合支付配置
|
||||
|
||||
@@ -13,10 +13,10 @@ import org.dromara.daxpay.core.enums.PayStatusEnum;
|
||||
import org.dromara.daxpay.core.exception.ConfigNotExistException;
|
||||
import org.dromara.daxpay.core.exception.TradeProcessingException;
|
||||
import org.dromara.daxpay.core.exception.UnsupportedAbilityException;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutAggregatePayParam;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutCreatParam;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutPayParam;
|
||||
import org.dromara.daxpay.core.param.assist.AuthCodeParam;
|
||||
import org.dromara.daxpay.core.param.checkout.*;
|
||||
import org.dromara.daxpay.core.param.trade.pay.PayParam;
|
||||
import org.dromara.daxpay.core.result.assist.AuthResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutPayResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutUrlResult;
|
||||
import org.dromara.daxpay.core.result.trade.pay.PayResult;
|
||||
@@ -195,34 +195,35 @@ public class CheckoutService {
|
||||
return payService.pay(payParam, payOrder);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 生成授权链接跳转链接, 主要是微信类通道使用, 用于获取OpenId
|
||||
// */
|
||||
// public String generateAuthUrl(CheckoutAggregatePayParam param){
|
||||
// // 订单信息
|
||||
// PayOrder payOrder = checkoutAssistService.getOrderAndCheck(param.getOrderNo());
|
||||
// // 获取聚合类型
|
||||
// CheckoutAggregateConfig aggregateConfig = checkoutAggregateConfigManager.findByAppIdAndType(payOrder.getAppId(), param.getAggregateType())
|
||||
// .orElseThrow(() -> new ConfigNotExistException("聚合支付配置项不存在"));
|
||||
// paymentAssistService.initMchApp(aggregateConfig.getAppId());
|
||||
// // 获取策略
|
||||
// var cashierStrategy = PaymentStrategyFactory.create(aggregateConfig.getChannel(), AbsCheckoutStrategy.class);
|
||||
// return cashierStrategy.generateAuthUrl(param);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 授权结果
|
||||
// */
|
||||
// public AuthResult auth(org.dromara.daxpay.service.param.cashier.AuthCodeParam param) {
|
||||
// // 查询配置
|
||||
// var cashierConfig = codeConfigService.findByCashierType(param.getCode(),param.getType());
|
||||
// paymentAssistService.initMchApp(cashierConfig.getAppId());
|
||||
// // 获取策略
|
||||
// AbsCashierCodeStrategy cashierStrategy = PaymentStrategyFactory.create(cashierConfig.getChannel(), AbsCashierCodeStrategy.class);
|
||||
// AuthCodeParam authCodeParam = new AuthCodeParam()
|
||||
// .setCashierType(param.getType())
|
||||
// .setAuthCode(param.getAuthCode())
|
||||
// .setAppId(cashierConfig.getAppId());
|
||||
// return cashierStrategy.doAuth(authCodeParam);
|
||||
// }
|
||||
/**
|
||||
* 生成授权链接跳转链接, 主要是微信类通道使用, 用于获取OpenId
|
||||
*/
|
||||
public String generateAuthUrl(CheckoutAuthUrlParam param){
|
||||
// 订单信息
|
||||
PayOrder payOrder = checkoutAssistService.getOrderAndCheck(param.getOrderNo());
|
||||
// 获取聚合类型
|
||||
var aggregateConfig = checkoutAggregateConfigManager.findByAppIdAndType(payOrder.getAppId(), param.getAggregateType())
|
||||
.orElseThrow(() -> new ConfigNotExistException("聚合支付配置项不存在"));
|
||||
paymentAssistService.initMchApp(aggregateConfig.getAppId());
|
||||
// 获取策略
|
||||
var checkoutStrategy = PaymentStrategyFactory.create(aggregateConfig.getChannel(), AbsCheckoutStrategy.class);
|
||||
return checkoutStrategy.generateAuthUrl(param.getOrderNo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权结果
|
||||
*/
|
||||
public AuthResult auth(CheckoutAuthCodeParam param) {
|
||||
// 订单信息
|
||||
PayOrder payOrder = checkoutAssistService.getOrderAndCheck(param.getOrderNo());
|
||||
// 获取聚合类型
|
||||
var aggregateConfig = checkoutAggregateConfigManager.findByAppIdAndType(payOrder.getAppId(), param.getAggregateType())
|
||||
.orElseThrow(() -> new ConfigNotExistException("聚合支付配置项不存在"));
|
||||
paymentAssistService.initMchApp(payOrder.getAppId());
|
||||
// 获取策略
|
||||
var checkoutStrategy = PaymentStrategyFactory.create(aggregateConfig.getChannel(), AbsCheckoutStrategy.class);
|
||||
AuthCodeParam authCodeParam = new AuthCodeParam()
|
||||
.setAuthCode(param.getAuthCode());
|
||||
return checkoutStrategy.doAuth(authCodeParam);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.dromara.daxpay.service.strategy;
|
||||
|
||||
import org.dromara.daxpay.core.param.assist.AuthCodeParam;
|
||||
import org.dromara.daxpay.core.param.cashier.CashierCodeAuthUrlParam;
|
||||
import org.dromara.daxpay.core.param.checkout.CheckoutPayParam;
|
||||
import org.dromara.daxpay.core.param.trade.pay.PayParam;
|
||||
import org.dromara.daxpay.core.result.assist.AuthResult;
|
||||
@@ -16,7 +15,7 @@ public abstract class AbsCheckoutStrategy implements PaymentStrategy{
|
||||
/**
|
||||
* 生成授权链接, 主要是微信类通道使用, 用于获取OpenId
|
||||
*/
|
||||
public String generateAuthUrl(CashierCodeAuthUrlParam param) {
|
||||
public String generateAuthUrl(String orderNo) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user