mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-12 23:45:39 +08:00
refactor(demo): 移除通道连通性演示代码, 保留 artemis 消息队列演示
This commit is contained in:
@@ -35,14 +35,6 @@
|
||||
<artifactId>common-artemis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 支付宝通道模块 -->
|
||||
<!-- 提供 AlipayChannelClient (@HttpExchange) 及 AlipayPayReq/AlipayPayResp DTO, 供 Demo 控制器直接调用子应用 -->
|
||||
<dependency>
|
||||
<groupId>cn.daxpay.open</groupId>
|
||||
<artifactId>daxpay-channel-alipay</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
package cn.daxpay.open.demo.channel.controller;
|
||||
|
||||
import cn.daxpay.open.channel.alipay.client.AlipayChannelClient;
|
||||
import cn.daxpay.open.channel.alipay.dto.AlipayPayReq;
|
||||
import cn.daxpay.open.channel.alipay.dto.AlipayPayResp;
|
||||
import cn.daxpay.open.demo.channel.param.ChannelDemoPayParam;
|
||||
import cn.daxpay.open.demo.channel.result.ChannelDemoPayResult;
|
||||
import cn.daxpay.open.platform.core.annotation.IgnoreAuth;
|
||||
import cn.daxpay.open.platform.core.rest.Res;
|
||||
import cn.daxpay.open.platform.core.rest.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
/// # 通道连通性 Demo 接口
|
||||
///
|
||||
/// 演示主应用通过 @HttpExchange 客户端调用子应用 dax-pay-channel-one 的完整链路。
|
||||
/// 前端发起请求 → 主应用构建 AlipayPayReq → AlipayChannelClient 发送 HTTP → 子应用接收并处理 → 响应返回。
|
||||
///
|
||||
/// 鉴权: URL 前缀 `/demo/**` 已在白名单, 类上叠加 `@IgnoreAuth` 双保险。
|
||||
@Slf4j
|
||||
@IgnoreAuth
|
||||
@Validated
|
||||
@Tag(name = "通道连通性演示")
|
||||
@RestController
|
||||
@RequestMapping("/demo/channel")
|
||||
@RequiredArgsConstructor
|
||||
public class ChannelDemoController {
|
||||
|
||||
private static final BigDecimal HUNDRED = new BigDecimal("100");
|
||||
|
||||
private final AlipayChannelClient alipayChannelClient;
|
||||
|
||||
/// 发起 Demo 支付请求到子应用
|
||||
///
|
||||
/// 通过 @HttpExchange 声明式客户端将请求转发到 dax-pay-channel-one 的 `/channel/pay` 端点。
|
||||
/// config 传空 Map, 子应用进入 Demo 模式返回模拟响应。
|
||||
@Operation(summary = "发起通道 Demo 支付")
|
||||
@PostMapping("/pay")
|
||||
public Result<ChannelDemoPayResult> pay(@Validated @RequestBody ChannelDemoPayParam param) {
|
||||
log.info("🚀 Demo: 主应用发起通道支付请求, bizOrderNo={}", param.getBizOrderNo());
|
||||
|
||||
// 构建通道请求
|
||||
AlipayPayReq req = new AlipayPayReq();
|
||||
req.setChannel("alipay");
|
||||
req.setBizOrderNo(param.getBizOrderNo());
|
||||
req.setAmount(param.getAmount().multiply(HUNDRED).longValue());
|
||||
req.setSubject(param.getSubject());
|
||||
req.setMethod(param.getMethod());
|
||||
// 空配置 → 子应用进入 Demo 模式
|
||||
req.setConfig(Map.of());
|
||||
|
||||
// 调用子应用 (通过 @HttpExchange, OTel 自动透传 traceId)
|
||||
var channelResult = alipayChannelClient.pay(req);
|
||||
if (channelResult.getCode() != 0) {
|
||||
throw new RuntimeException("通道支付失败: " + channelResult.getMsg());
|
||||
}
|
||||
|
||||
AlipayPayResp resp = channelResult.getData();
|
||||
|
||||
// 构建返回结果 (包含双端 traceId 用于链路对照)
|
||||
ChannelDemoPayResult result = new ChannelDemoPayResult();
|
||||
result.setBizOrderNo(resp.getBizOrderNo());
|
||||
result.setOutOrderNo(resp.getOutOrderNo());
|
||||
result.setPayBody(resp.getPayBody());
|
||||
result.setPayBodyType(resp.getPayBodyType());
|
||||
result.setMainAppTraceId(MDC.get("traceId"));
|
||||
result.setSubAppTraceId(channelResult.getTraceId());
|
||||
|
||||
log.info("✅ Demo: 收到子应用响应, outOrderNo={}, subAppTraceId={}",
|
||||
result.getOutOrderNo(), result.getSubAppTraceId());
|
||||
|
||||
return Res.ok(result);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package cn.daxpay.open.demo.channel.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/// # 通道连通性 Demo 支付参数
|
||||
///
|
||||
/// 前端表单提交的简化参数, 不涉及真实支付订单实体。
|
||||
@Data
|
||||
@Schema(description = "通道 Demo 支付参数")
|
||||
public class ChannelDemoPayParam {
|
||||
|
||||
/// 商户订单号
|
||||
@Schema(description = "商户订单号")
|
||||
@NotBlank(message = "{validation.field.bizOrderNo.notBlank}")
|
||||
private String bizOrderNo;
|
||||
|
||||
/// 支付金额(元)
|
||||
@Schema(description = "支付金额(元)")
|
||||
@NotNull(message = "{validation.field.amount.notNull}")
|
||||
@DecimalMin(value = "0.01", message = "{validation.field.amount.min}")
|
||||
private BigDecimal amount;
|
||||
|
||||
/// 支付标题
|
||||
@Schema(description = "支付标题")
|
||||
@NotBlank(message = "{validation.field.subject.notBlank}")
|
||||
private String subject;
|
||||
|
||||
/// 支付方式(alipay_wap / alipay_app / alipay_page / alipay_qr)
|
||||
@Schema(description = "支付方式", example = "alipay_qr")
|
||||
@NotBlank(message = "{validation.field.method.notBlank}")
|
||||
private String method;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package cn.daxpay.open.demo.channel.result;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/// # 通道连通性 Demo 支付结果
|
||||
///
|
||||
/// 展示主应用 → 子应用往返的完整信息, 包含双端 traceId 用于链路对照。
|
||||
@Data
|
||||
@Schema(description = "通道 Demo 支付结果")
|
||||
public class ChannelDemoPayResult {
|
||||
|
||||
/// 商户订单号
|
||||
@Schema(description = "商户订单号")
|
||||
private String bizOrderNo;
|
||||
|
||||
/// 通道侧订单号
|
||||
@Schema(description = "通道侧订单号")
|
||||
private String outOrderNo;
|
||||
|
||||
/// 支付内容(支付链接 / 二维码 / 表单等)
|
||||
@Schema(description = "支付内容")
|
||||
private String payBody;
|
||||
|
||||
/// 支付内容类型(qr_code / form / order_id)
|
||||
@Schema(description = "支付内容类型")
|
||||
private String payBodyType;
|
||||
|
||||
/// 主应用 traceId
|
||||
@Schema(description = "主应用 traceId")
|
||||
private String mainAppTraceId;
|
||||
|
||||
/// 子应用 traceId
|
||||
@Schema(description = "子应用 traceId")
|
||||
private String subAppTraceId;
|
||||
}
|
||||
Reference in New Issue
Block a user