From 73d7c819cf04315fcdbea7630884771338073cf8 Mon Sep 17 00:00:00 2001 From: duzhichao <1098974448@qq.com> Date: Wed, 17 Jun 2026 18:37:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=94=AF=E4=BB=98=E5=AE=9D=E4=BA=8C?= =?UTF-8?q?=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/settings.local.json | 6 +- .../file/controller/FileController.java | 40 ++ .../central/file/service/IFileService.java | 10 + .../service/impl/AbstractIFileService.java | 46 ++ .../order/controller/QrCodeController.java | 54 +- .../order/feign/FileCenterService.java | 14 + .../FileCenterServiceFallbackFactory.java | 11 + .../java/com/central/order/model/QrCode.java | 18 + .../sql/add_qrcode_alipay_fields.sql | 6 + .../config/AlipayAutoConfiguration.java | 7 + .../alipay/service/AlipayQrcodeService.java | 135 +++++ .../alipay/小程序二维码生成与展示业务逻辑.md | 548 ++++++++++++++++++ .../orders/Tourism/components/QrcodeItem.tsx | 4 + .../Tourism/components/QrcodeListModal.tsx | 57 ++ zlt-web/react-web-next/src/services/orders.ts | 5 + 15 files changed, 959 insertions(+), 2 deletions(-) create mode 100644 zlt-business/order-center/src/main/resources/sql/add_qrcode_alipay_fields.sql create mode 100644 zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/service/AlipayQrcodeService.java create mode 100644 zlt-doc/alipay/小程序二维码生成与展示业务逻辑.md diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 3ef0e766..d5c342bf 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -102,7 +102,11 @@ "Bash(grep \"routeActions\\\\|routeActionsTitle\" src/pages/client/components/CenterView/index.tsx)", "Read(//c/Users/10989/.m2/repository/com/alipay/**)", "Bash(\"/e/java/apache-maven-3.9.11-bin/apache-maven-3.9.11/bin/mvn.cmd\" -q -o -pl . compile)", - "Bash(\"/e/java/apache-maven-3.9.11-bin/apache-maven-3.9.11/bin/mvn.cmd\" -q -pl zlt-commons/zlt-alipay-spring-boot-starter -am compile -DskipTests)" + "Bash(\"/e/java/apache-maven-3.9.11-bin/apache-maven-3.9.11/bin/mvn.cmd\" -q -pl zlt-commons/zlt-alipay-spring-boot-starter -am compile -DskipTests)", + "Bash(grep -rn \"alipay\" zlt-business/order-center/src/main/resources/sql/)", + "Bash(ls zlt-business/order-center/src/main/resources/sql/)", + "WebFetch(domain:opendocs.alipay.com)", + "Bash(mvn -v)" ], "deny": [], "ask": [] diff --git a/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java b/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java index c2e156f1..21d4ade6 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java +++ b/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java @@ -201,6 +201,46 @@ public class FileController { return Result.succeed(map); } + /** + * 拉取外部图片 URL 字节并强制入 S3(不进 OSS / 不进智能路由) + * 用于支付宝小程序二维码:alipay.open.app.qrcode.create 返回临时 qr_code_url,需立刻拉回入 S3 + */ + @GetMapping("/qrcode/s3/by-url") + public Result uploadQrCodeToS3ByUrl(@RequestParam("codeId") String codeId, + @RequestParam("qrUrl") String qrUrl, + @RequestParam(value = "suffix", required = false, defaultValue = "png") String suffix) throws Exception { + if (codeId == null || codeId.isEmpty() || qrUrl == null || qrUrl.isEmpty()) { + return Result.failed("codeId 和 qrUrl 不能为空"); + } + ResponseEntity resp = restTemplate.exchange(qrUrl, HttpMethod.GET, HttpEntity.EMPTY, byte[].class); + if (!resp.getStatusCode().is2xxSuccessful() || resp.getBody() == null || resp.getBody().length == 0) { + return Result.failed("拉取二维码图片失败: " + resp.getStatusCode()); + } + String fileName = codeId + "." + suffix; + FileInfo fileInfo = fileService.uploadForS3(fileName, new ByteArrayInputStream(resp.getBody())); + Map map = new LinkedHashMap<>(); + map.put("codeId", codeId); + map.put("fileId", fileInfo.getId()); + map.put("filePath", fileInfo.getPath()); + return Result.succeed(map); + } + + /** + * 直接 S3 预签名(绕过 TimeWindowStorageService 智能路由) + */ + @GetMapping("/files/s3/path") + public String getS3ViewUrlByPath(@RequestParam("path") String path) { + if (path == null || path.isEmpty()) { + return ""; + } + try { + return fileService.getS3ViewUrlByPath(path); + } catch (Exception e) { + log.warn("获取S3预签名URL失败: path={}, err={}", path, e.getMessage()); + return ""; + } + } + @PostMapping("/path") public FileInfo creatFileInfo(@RequestBody String path) { return fileService.createFile(path); diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java b/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java index 6beca9b5..a71671cf 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java @@ -20,6 +20,11 @@ public interface IFileService extends IService { FileInfo uploadForS3(MultipartFile file ) throws Exception; + /** + * 强制以 S3 方式上传字节流(用于支付宝小程序二维码等需绕开 OSS 的场景) + */ + FileInfo uploadForS3(String name, InputStream inputStream) throws Exception; + FileInfo upload(String name, InputStream inputStream) throws Exception; PageResult findList(Map params); @@ -43,4 +48,9 @@ public interface IFileService extends IService { String getViewUrlByPathAndExpires(String name,int expires); String getS3UrlByPath(String path); + + /** + * 强制返回 S3 预签名 URL(绕开智能路由,用于支付宝小程序二维码展示) + */ + String getS3ViewUrlByPath(String path); } diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java index ecf4c43e..7b738a8f 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/AbstractIFileService.java @@ -79,6 +79,26 @@ public abstract class AbstractIFileService extends ServiceImpl generateAlipayQrcode(@PathVariable("id") Long id) throws Exception { + QrCode qrCode = qrCodeService.getById(id); + Assert.notNull(qrCode, "二维码不存在"); + Assert.hasText(qrCode.getCodeId(), "codeId 缺失"); + Assert.hasText(qrCode.getTenantId(), "tenantId 缺失"); + + String qrCodeUrl = alipayQrcodeService.createMiniQrcode( + qrCode.getTenantId(), + qrCode.getCodeId(), + alipayPagePath, + alipayQueryKey, + qrCode.getName()); + if (qrCodeUrl == null || qrCodeUrl.isEmpty()) { + return Result.failed("支付宝二维码生成失败:qr_code_url 为空"); + } + + Result upload = fileCenterService.uploadQrCodeToS3ByUrl(qrCode.getCodeId(), qrCodeUrl, "png"); + if (upload == null || upload.getResp_code() != 0) { + return Result.failed("支付宝二维码上传 S3 失败"); + } + Object fileId = upload.getData().get("fileId"); + Object filePath = upload.getData().get("filePath"); + if (fileId == null || filePath == null) { + return Result.failed("支付宝二维码上传响应缺少 fileId/filePath"); + } + qrCode.setAlipayFileId(fileId.toString()); + qrCode.setAlipayFilePath(filePath.toString()); + qrCodeService.updateById(qrCode); + + // 列表展示用:同步把 view url 拉一次 + qrCode.setViewUrl(fileCenterService.getViewUrlByPath(qrCode.getFilePath())); + qrCode.setAlipayViewUrl(fileCenterService.getS3ViewUrlByPath(qrCode.getAlipayFilePath())); + return Result.succeed(qrCode, "支付宝二维码生成成功"); + } } diff --git a/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java b/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java index e39d22f2..aa08282c 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java +++ b/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java @@ -36,6 +36,20 @@ public interface FileCenterService { @GetMapping("/qrcode/{codeId}") Result uploadQrCodeFile(@PathVariable("codeId") String codeId) throws Exception; + /** + * 拉取外部图片 URL 字节并强制入 S3(用于支付宝小程序二维码) + */ + @GetMapping("/qrcode/s3/by-url") + Result uploadQrCodeToS3ByUrl(@RequestParam("codeId") String codeId, + @RequestParam("qrUrl") String qrUrl, + @RequestParam(value = "suffix", required = false, defaultValue = "png") String suffix) throws Exception; + + /** + * 强制返回 S3 预签名 URL(绕开智能路由) + */ + @GetMapping("/files/s3/path") + String getS3ViewUrlByPath(@RequestParam("path") String path); + @PostMapping("/path") FileInfo creatFileInfo(@RequestBody String path); diff --git a/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java b/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java index 36b3bb6f..dff643fc 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java +++ b/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java @@ -41,6 +41,17 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory uploadQrCodeToS3ByUrl(String codeId, String qrUrl, String suffix) throws Exception { + log.warn("file-center 调用失败,支付宝二维码上传降级返回 null, codeId={}", codeId, cause); + return null; + } + + @Override + public String getS3ViewUrlByPath(String path) { + return ""; + } + @Override public FileInfo creatFileInfo(String path) { return null; diff --git a/zlt-business/order-center/src/main/java/com/central/order/model/QrCode.java b/zlt-business/order-center/src/main/java/com/central/order/model/QrCode.java index e321d574..904035ea 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/model/QrCode.java +++ b/zlt-business/order-center/src/main/java/com/central/order/model/QrCode.java @@ -132,4 +132,22 @@ public class QrCode extends SuperEntity { @Schema(description = "携程产品ID") private Long ctripProductId; + /** + * 支付宝小程序二维码 fileId(S3) + */ + @Schema(description = "支付宝小程序二维码 fileId(S3)") + private String alipayFileId; + + /** + * 支付宝小程序二维码对象路径(S3 bucket/objectKey) + */ + @Schema(description = "支付宝小程序二维码对象路径(S3 bucket/objectKey)") + private String alipayFilePath; + + /** + * 支付宝小程序二维码访问 URL(运行时填充,不入库) + */ + @Schema(description = "支付宝小程序二维码访问 URL(运行时填充,不入库)") + private transient String alipayViewUrl; + } diff --git a/zlt-business/order-center/src/main/resources/sql/add_qrcode_alipay_fields.sql b/zlt-business/order-center/src/main/resources/sql/add_qrcode_alipay_fields.sql new file mode 100644 index 00000000..3950b0fc --- /dev/null +++ b/zlt-business/order-center/src/main/resources/sql/add_qrcode_alipay_fields.sql @@ -0,0 +1,6 @@ +-- 二维码表添加支付宝小程序二维码相关字段 +-- 用途:在同一行 qrcodes 上挂支付宝小程序二维码图(与微信码共用 code_id 与所有业务字段) +-- 一行业务、两张图:用户扫微信码进微信小程序,扫支付宝码进支付宝小程序,后端用同一 code_id 命中同一行 +ALTER TABLE qrcodes + ADD COLUMN alipay_file_id VARCHAR(64) NULL COMMENT '支付宝小程序二维码 fileId(S3)', + ADD COLUMN alipay_file_path VARCHAR(512) NULL COMMENT '支付宝小程序二维码对象 path(S3 bucket/objectKey)'; diff --git a/zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/config/AlipayAutoConfiguration.java b/zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/config/AlipayAutoConfiguration.java index c79387d0..bf5a920a 100644 --- a/zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/config/AlipayAutoConfiguration.java +++ b/zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/config/AlipayAutoConfiguration.java @@ -3,6 +3,7 @@ package com.central.alipay.config; import com.central.alipay.notify.AlipayNotifyVerifier; import com.central.alipay.service.AlipayLoginService; import com.central.alipay.service.AlipayPayService; +import com.central.alipay.service.AlipayQrcodeService; import com.central.alipay.service.AlipayRefundService; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -50,6 +51,12 @@ public class AlipayAutoConfiguration { return new AlipayRefundService(); } + @Bean + public AlipayQrcodeService alipayQrcodeService() { + log.info("AlipayQrcodeService 已加载"); + return new AlipayQrcodeService(); + } + @Bean public AlipayNotifyVerifier alipayNotifyVerifier() { log.info("AlipayNotifyVerifier 已加载"); diff --git a/zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/service/AlipayQrcodeService.java b/zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/service/AlipayQrcodeService.java new file mode 100644 index 00000000..497cedae --- /dev/null +++ b/zlt-commons/zlt-alipay-spring-boot-starter/src/main/java/com/central/alipay/service/AlipayQrcodeService.java @@ -0,0 +1,135 @@ +package com.central.alipay.service; + +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.request.AlipayOpenAppQrcodeCreateRequest; +import com.alipay.api.response.AlipayOpenAppQrcodeCreateResponse; +import com.central.alipay.config.AlipayClientFactory; +import com.central.alipay.entity.AlipayConfig; +import com.central.alipay.feign.AlipayConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; + +/** + * 支付宝小程序二维码服务 + *

+ * 封装 alipay.open.app.qrcode.create: + * - 优先按 type=MINI + 实际 tenantId 取配置;查不到则回退到默认租户(zlt.alipay.qrcode.default-tenant-id,默认 webApp) + * - 复用 AlipayClientFactory 缓存 + * - 支持 ISV 模式 app_auth_token 透传 + * - describe 自动截断到 16 字 + * + * @author duzhichao + * @date 2026-06-17 + */ +@Slf4j +public class AlipayQrcodeService { + + private static final int MAX_DESCRIBE_LENGTH = 16; + private static final String CONFIG_TYPE_MINI = "MINI"; + + @Autowired + private AlipayClientFactory clientFactory; + + @Autowired + private AlipayConfigService alipayConfigService; + + /** + * 默认兜底租户ID。当业务 tenantId 下未配置支付宝小程序时,使用该租户的 type=MINI 配置生成二维码。 + */ + @Value("${zlt.alipay.qrcode.default-tenant-id:webApp}") + private String defaultTenantId; + + /** + * 生成支付宝小程序二维码(返回支付宝 CDN 上的临时 PNG URL) + * + * @param tenantId 租户ID + * @param codeId 业务唯一码(最终拼到 query_param) + * @param urlParam 小程序页面路径(不带前导 /),如 pages/link/link + * @param queryKey 查询键名,如 uuid(最终 query_param=uuid=) + * @param describe 业务描述,超过 16 字自动截断 + */ + public String createMiniQrcode(String tenantId, String codeId, + String urlParam, String queryKey, String describe) { + if (tenantId == null || tenantId.isEmpty()) { + throw new RuntimeException("tenantId 不能为空"); + } + if (codeId == null || codeId.isEmpty()) { + throw new RuntimeException("codeId 不能为空"); + } + if (urlParam == null || urlParam.isEmpty()) { + throw new RuntimeException("urlParam 不能为空"); + } + + AlipayConfig cfg = resolveMiniConfig(tenantId); + AlipayClient client = clientFactory.createAlipayClient(cfg); + + AlipayOpenAppQrcodeCreateRequest request = new AlipayOpenAppQrcodeCreateRequest(); + JSONObject biz = new JSONObject(); + biz.put("url_param", urlParam); + biz.put("query_param", (queryKey == null || queryKey.isEmpty() ? "uuid" : queryKey) + "=" + codeId); + biz.put("describe", trimDescribe(describe)); + request.setBizContent(biz.toJSONString()); + + if (Boolean.TRUE.equals(cfg.getIsServiceMode()) && cfg.getAuthToken() != null) { + request.putOtherTextParam("app_auth_token", cfg.getAuthToken()); + } + + try { + AlipayOpenAppQrcodeCreateResponse response = client.execute(request); + if (response.isSuccess()) { + log.info("支付宝小程序码生成成功, tenantId: {}, codeId: {}, qrCodeUrl: {}", + tenantId, codeId, response.getQrCodeUrl()); + return response.getQrCodeUrl(); + } + log.error("支付宝小程序码生成失败, subCode: {}, subMsg: {}", + response.getSubCode(), response.getSubMsg()); + throw new RuntimeException("支付宝小程序码生成失败: " + response.getSubMsg()); + } catch (AlipayApiException e) { + log.error("支付宝小程序码生成异常, tenantId: {}, codeId: {}", tenantId, codeId, e); + throw new RuntimeException("支付宝小程序码生成异常: " + e.getErrMsg(), e); + } + } + + /** + * 取小程序配置:优先实际租户,失败回退默认租户(webApp)。两个都没有再抛出。 + */ + private AlipayConfig resolveMiniConfig(String tenantId) { + AlipayConfig cfg = safeGetConfig(tenantId); + if (cfg != null) { + return cfg; + } + if (defaultTenantId != null && !defaultTenantId.isEmpty() && !defaultTenantId.equals(tenantId)) { + log.warn("租户 {} 未配置支付宝小程序,回退默认租户 {}", tenantId, defaultTenantId); + AlipayConfig fallback = safeGetConfig(defaultTenantId); + if (fallback != null) { + return fallback; + } + } + throw new RuntimeException("支付宝小程序配置不存在,tenantId: " + tenantId + + (defaultTenantId != null ? ",默认租户 " + defaultTenantId + " 同样未配置" : "")); + } + + /** + * Feign 调用兜底:网络异常/降级等情况下返回 null,由 resolveMiniConfig 走回退分支 + */ + private AlipayConfig safeGetConfig(String tenantId) { + try { + return alipayConfigService.getConfig(CONFIG_TYPE_MINI, tenantId); + } catch (Exception e) { + log.warn("查询支付宝小程序配置失败,tenantId: {}, err: {}", tenantId, e.getMessage()); + return null; + } + } + + private String trimDescribe(String describe) { + if (describe == null || describe.isEmpty()) { + return "二维码"; + } + return describe.length() > MAX_DESCRIBE_LENGTH + ? describe.substring(0, MAX_DESCRIBE_LENGTH) + : describe; + } +} diff --git a/zlt-doc/alipay/小程序二维码生成与展示业务逻辑.md b/zlt-doc/alipay/小程序二维码生成与展示业务逻辑.md new file mode 100644 index 00000000..5eb44e3a --- /dev/null +++ b/zlt-doc/alipay/小程序二维码生成与展示业务逻辑.md @@ -0,0 +1,548 @@ +# 小程序二维码生成与展示业务逻辑 + +> 入口页面:`zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeListModal.tsx`(打卡点二维码列表) +> +> 本文先把现有「微信小程序二维码」的生成与展示链路梳理清楚,再据此给出「支付宝小程序二维码」(`alipay.open.app.qrcode.create`)的对接设计方案。 + +--- + +## 一、微信小程序二维码业务逻辑 + +### 1.1 端到端流程概览 + +``` +React 表单 + │ POST /api-order/qrcode/withPlan + ▼ +order-center QrCodeController.saveOrUpdateQrcodeWithPlan + │ 生成 codeId = UUID.randomUUID() + │ Feign → file-center FileCenterService.uploadQrCodeFile(codeId) + ▼ +file-center FileController.uploadQrCodeFile + │ 1) GET 微信 access_token + │ 2) POST createwxaqrcode body: { "path": pagePath + codeId } + │ 3) 拿到 byte[](JPEG) + │ 4) IFileService.upload(codeId+".jpeg", inputStream) → OSS + │ 5) 返回 { codeId, fileId, filePath } + ▼ +order-center 持久化: + - qrcodes 表写入:codeId / fileId / filePath / tenantId + - package_plan 表写入/更新:vlogCount / videoCount / photoCount / tourismFileIds +``` + +### 1.2 关键代码定位 + +| 角色 | 文件 | +|------|------| +| 前端列表 + 预览 + 路由 | `zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeListModal.tsx` | +| 前端表单(新增/编辑) | `zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeTourismForm.tsx` | +| 前端 API 封装 | `zlt-web/react-web-next/src/services/orders.ts:79-101` | +| 业务控制器 | `zlt-business/order-center/src/main/java/com/central/order/controller/QrCodeController.java` | +| Feign 客户端 | `zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java:36` | +| 文件中心控制器 | `zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java`(生成 L192、查询 URL L159) | +| 实体 | `order-center/src/main/java/com/central/order/model/QrCode.java`(`@TableName("qrcodes")`) | +| Mapper | `order-center/src/main/resources/mapper/QrCodeMapper.xml` | +| OSS 抽象 | `zlt-business/file-center/src/main/java/com/central/file/service/impl/OssService.java` | +| 智能 URL 路由 | `zlt-business/file-center/src/main/java/com/central/file/service/TimeWindowStorageService.java` | +| 微信凭证配置 | Nacos:`zlt.security.tencent.{accessTokenUrl,getwxacodeUrl,pagePath}` | + +### 1.3 生成业务逻辑(写入路径) + +#### 1.3.1 前端入口(QrcodeTourismForm) + +- `QrcodeListModal` 点击"新增" → 打开 `QrcodeTourismForm`。 +- 提交时调 `ordersApi.saveOrUpdateQrcodePlan(payload)`,`payload` 形如: + +```ts +{ + qrCode: { tenantId, tourismId, name, deviceSn, waylineId, price, status, + templateId, enableVideoEdit, isTest, qrcodeType, showVideoEditOnly, + enableCtripOrder, ctripProductId, qrDescribe, materialCount }, + vlogCount, videoCount, photoCount, + tourismFileIds: number[] +} +``` + +后端入口:`POST /api-order/qrcode/withPlan` → `QrCodeController.saveOrUpdateQrcodeWithPlan`。 + +#### 1.3.2 后端编排(order-center) + +文件:`order-center/.../controller/QrCodeController.java:194-254`。 + +1. 校验 `qrCode` 非空。 +2. **新增分支**(`qrCode.id == null`): + - `codeId = UUID.randomUUID().toString()`。 + - Feign 调 `fileCenterService.uploadQrCodeFile(codeId)`。 + - 回填:`qrCode.codeId / filePath / fileId / tenantId(取自 tourism.tenantId)`。 + - `qrCodeService.saveOrUpdate(qrCode)` 写 `qrcodes` 表。 +3. **修改分支**:直接 `saveOrUpdate`,不重新生成图片。 +4. 同步 `PackagePlan`(按 `codeId` 找到则更新,否则新建),把 `vlogCount / videoCount / photoCount / tourismFileIds` 写进去(`tourismFileIds` 用逗号字符串保存)。 + +整体加 `@Transactional(rollbackFor = Exception.class)`。 + +#### 1.3.3 文件中心生成 + 入 OSS(file-center) + +文件:`file-center/.../controller/FileController.java:192-255`。 + +```java +@GetMapping("/qrcode/{codeId}") +public Result uploadQrCodeFile(@PathVariable String codeId) { + String accessToken = getAccessTokenUrl(); // 调 access_token 接口 + InputStream qr = getQRCode(accessToken, codeId); // 调 createwxaqrcode 拿字节 + FileInfo fileInfo = fileService.upload(codeId + ".jpeg", qr); // 写 OSS + return Result.succeed(Map.of( + "codeId", codeId, + "fileId", fileInfo.getId(), + "filePath", fileInfo.getPath() + )); +} +``` + +对应外部调用: + +| 步骤 | 方法 | URL | 关键参数 | +|------|------|-----|----------| +| 取 access_token | `GET` | `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=...&secret=...` | 直接用 Nacos 里拼好的整串 URL | +| 生成小程序码 | `POST` | `https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=` | body: `{ "path": "/pages/link/link?uuid=" }` | +| 入 OSS | `IFileService.upload` | 抽象层 → `OssTemplate.upload(name, is, len, "image/jpeg")` | OSS 对象 key = `.jpeg` | + +要点: +- `codeId`(UUID)一码三用:① 透传给小程序的 `?uuid=` 参数;② OSS 对象 key 前缀;③ 业务表 `qrcodes.code_id` 主键。 +- 用的是旧版 `createwxaqrcode`(仅传 `path`),**不是** `getwxacodeunlimit`: + - 不支持 `scene`,参数都拼在 URL 里。 + - 小程序页面必须已发布。 +- 微信凭证目前是**全局静态**配置(`zlt.security.tencent.*`),未走多租户 `wechat_config` 表。 +- 上传时 `contentType` 写死 `image/jpeg`(`OssService.uploadFile`)。 + +### 1.4 展示业务逻辑(读取路径) + +#### 1.4.1 后端列表(order-center) + +文件:`QrCodeController.java:65-79`。 + +```java +@GetMapping +public PageResult list(@RequestParam Map params) { + PageResult page = qrCodeService.findList(params); // qrcodes 表分页 + if (page.getResp_code() == 0) { + for (QrCode q : page.getData()) { + q.setViewUrl(fileCenterService.getViewUrlByPath(q.getFilePath())); // 实时签名 + } + } + return page; +} +``` + +#### 1.4.2 智能 URL 路由(file-center) + +`FileController.getViewUrlByPath` → `TimeWindowStorageService.getSmartViewUrlByPath`: + +- 热数据(`createTime <= zlt.storage.time-router.days`)→ Aliyun OSS 预签名 URL(可叠加 `cdn.oss.domain` = `cdn.goflytec.com`)。 +- 冷数据 → MinIO(S3)预签名(可叠加 `cdn.s3.domain` = `minicdn.goflytec.com`)。 + +#### 1.4.3 前端展示 + +- `QrcodeListModal.tsx:131-146`:列 `viewUrl` 用 `` 直接渲染,缩略 60×60,点击放大走 Antd `Modal`(L327-331)。 +- `viewUrl` **不入库**(实体 `QrCode.viewUrl` 是 `transient`),每次列表都重新签名,避免预签名 URL 过期问题。 +- 表格其他扩展列:`code_id` / `wayline_id` 加复制按钮、`price` 单位为分(前端自动除以 100 显示元)、`templateId` 走 `ordersApi.getVideoTemplateByTemplateId` 懒加载映射成中文模板名。 + +### 1.5 数据库结构 + +#### 1.5.1 `qrcodes` 表(`@TableName("qrcodes")`) + +| 字段 | 含义 | +|------|------| +| `id` | 主键 | +| `code_id` | UUID。扫码透传 `uuid`、OSS 对象 key 前缀 | +| `tenant_id` | 租户 ID(来自所属景区) | +| `tourism_id` | 景区 ID | +| `name` | 二维码名称 | +| `wayline_id` / `device_sn` | 关联航线 / 设备 | +| `price` | 价格(分) | +| `template_id` | 视频模板 ID | +| `file_id` / `file_path` | 文件中心返回的 fileId 与 OSS 路径 | +| `status` | 0 启用 / 1 禁用 | +| `enable_video_edit` | 是否一键成片 | +| `material_count` | 素材数量 | +| `is_test` | 是否测试码 | +| `qrcode_type` | 1 游客下单 / 2 定时巡查 / 3 自定义 | +| `show_video_edit_only` | 是否只显示一键成片 | +| `enable_ctrip_order` / `ctrip_product_id` | 携程联动 | +| `payee_account` / `payee_type` / `profit_rate` / `payee_status` / `payee_fail_reason` / `enable_profit` | 分润 | +| `qr_describe` | 描述 | +| `is_del` / `create_time` / `update_time` | 软删 + 审计 | + +> `view_url` 在实体里是 `transient`,**不持久化**,每次查询动态生成。 + +#### 1.5.2 `package_plan` 表(关联用 `code_id`) + +- `vlog_count` / `video_count` / `photo_count` +- `tourism_file_ids`:逗号拼接的素材 ID 列表 + +### 1.6 隐含约定(移植到其他平台时要小心) + +1. `codeId` 是业务主键,**写库前一刻才生成**,并立即用于"上传文件名 / 三方接口入参 / 表字段"三处,三处必须保持一致。 +2. 文件 `viewUrl` 永远是临时签名,前端不要做缓存(包括复制走的"图片地址")。 +3. 上传与生成是同一次 RPC(Feign 调用),失败时通过 `@Transactional` 整体回滚,不会留下"DB 有记录但 OSS 没文件"的脏数据。 +4. WeChat 这条链路目前 **不是多租户**(凭证写死在 Nacos)。如果要按租户挂不同小程序,需要走 `wechat_config` + `WxMaService` 模式,本文档不涉及。 + +--- + +## 二、支付宝小程序二维码 — 对接设计 + +> 目标接口:`alipay.open.app.qrcode.create` —— [官方文档](https://opendocs.alipay.com/mini/a25c5d8f_alipay.open.app.qrcode.create?pathHash=2334bbff&scene=common) + +### 2.0 两条核心设计原则(与微信链路的关键差异) + +**原则 A — 一行业务、两张图。** +微信码与支付宝码指向**同一个打卡点**,业务参数(航线、价格、设备、模板、分润、素材列表……)完全一致;用户扫哪张码进哪个小程序,但落到后端都是同一个 `codeId`,查同一行 `qrcodes`。 + +> 因此 **不引入 `provider` 列、不在 `qrcodes` 中写两条记录**。改为:在同一行上挂第二张图的 `file_id` / `file_path`,列表里同行展示两张缩略图。 + +**原则 B — 支付宝二维码图片走 S3,不进智能路由。** +支付宝的二维码字节直接存 MinIO(S3),读取时也直接调 S3 预签名 URL(或 CDN 域名 `minicdn.goflytec.com`),**不走 `TimeWindowStorageService` 的冷热路由**。微信码继续走当前 OSS + 智能路由不变。 + +> 这样能让支付宝资产生命周期与 S3 完全对齐,便于独立审计和迁移。 + +### 2.1 现有可复用资产盘点 + +| 资产 | 位置 | 用途 | +|------|------|------| +| 支付宝 SDK | `zlt-alipay-spring-boot-starter/pom.xml`(`alipay-sdk-java 4.40.816.ALL`) | 提供 `AlipayOpenAppQrcodeCreateRequest` | +| 多租户配置表 | `alipay_config`(实体 `AlipayConfig`) | `type=MINI` 即小程序配置(按你的决策选 MINI) | +| 客户端工厂 | `AlipayClientFactory.createAlipayClient(AlipayConfig)` | 已支持公钥 / 证书模式 + 缓存 | +| Feign 客户端 | `AlipayConfigService.getConfig("MINI", tenantId)` | 取当前租户的小程序配置 | +| 服务封装风格 | `AlipayPayService` / `AlipayLoginService` / `AlipayRefundService` | 仿照同风格新增 `AlipayQrcodeService` | +| S3 上传能力 | `IFileService.uploadForS3(MultipartFile)`(已有)
`S3Template.upload(name, InputStream)`(已有) | 字节直入 S3,绕过 OSS | +| S3 预签名 | `S3Service.getViewUrlByPath(path)` 60 分钟 | 列表 `alipayViewUrl` 实时签名来源 | + +### 2.2 接口规范摘要(`alipay.open.app.qrcode.create`) + +请求 bizContent: + +| 字段 | 必填 | 说明 | +|------|------|------| +| `url_param` | 是 | 小程序页面路径,如 `pages/link/link`(不带前导 `/`) | +| `query_param` | 否 | URL 参数串,如 `uuid=`(多个用 `&` 拼) | +| `describe` | 是 | 业务描述,≤16 字符 | + +响应字段: + +| 字段 | 说明 | +|------|------| +| `qr_code_url` | 支付宝 CDN 上的二维码图片 URL(PNG),临时链接 → **必须立即拉回字节落 S3** | + +调用注意: +- 应用需在支付宝开放平台开通对应能力。 +- `url_param` 必须是已发布版本中存在的 `app.json` 页面。 +- ISV 模式下要带 `app_auth_token`(沿用 `AlipayPayService` 的处理方式)。 + +### 2.3 数据模型(同行双图) + +#### 2.3.1 数据库迁移 + +新建 `order-center/src/main/resources/sql/add_qrcode_alipay_fields.sql`: + +```sql +-- 在同一行 qrcodes 上挂支付宝二维码图(与微信码共用 code_id 与所有业务字段) +ALTER TABLE qrcodes + ADD COLUMN alipay_file_id VARCHAR(64) NULL COMMENT '支付宝小程序二维码 fileId(S3)', + ADD COLUMN alipay_file_path VARCHAR(512) NULL COMMENT '支付宝小程序二维码对象 path(S3 bucket/objectKey)'; +``` + +> **不加索引**:支付宝码不参与查询过滤,只是同行附属资源。 +> +> **不加 `provider` 列**:原因见 §2.0 原则 A。 + +#### 2.3.2 实体改造 + +`QrCode.java` 新增字段: + +```java +@Schema(description = "支付宝小程序二维码 fileId(S3)") +private String alipayFileId; + +@Schema(description = "支付宝小程序二维码对象路径(S3 bucket/objectKey)") +private String alipayFilePath; + +@Schema(description = "支付宝小程序二维码访问 URL(运行时填充,不入库)") +private transient String alipayViewUrl; +``` + +`QrCodeMapper.xml` `findList` 不需要改(无新过滤条件)。 + +### 2.4 调用流程 + +#### 2.4.1 生成(写入路径) + +支付宝码独立于 `withPlan` 主流程,不和创建打卡点耦合。**入口设计为:对一条已存在的 `qrcodes` 行调用一次"生成支付宝码"**: + +``` +React 列表行 → 点击「生成支付宝二维码」 + │ POST /api-order/qrcode/{id}/alipay + ▼ +order-center QrCodeController.generateAlipayQrcode(id) + │ 1) qrCode = qrCodeService.getById(id)(必须存在 codeId、tenantId) + │ 2) qrCodeUrl = AlipayQrcodeService.createMiniQrcode( + │ tenantId = qrCode.tenantId, + │ codeId = qrCode.codeId, + │ urlParam = ${zlt.security.alipay.pagePath}, + │ queryParam = uuid=, + │ describe = trim16(qrCode.name)) + │ 3) Feign → file-center FileCenterService.uploadQrCodeToS3ByUrl( + │ codeId, qrCodeUrl, "png") + ▼ +file-center FileController.uploadQrCodeToS3ByUrl + │ RestTemplate 拉取 qrCodeUrl 字节 + │ IFileService.uploadForS3(.png, inputStream) ← 直接走 S3,不走 OSS + │ 返回 { codeId, fileId, filePath } + ▼ +order-center 回填 + - qrcodes.alipay_file_id = fileId + - qrcodes.alipay_file_path = filePath + - update by id +``` + +幂等:再次调用即重新生成(旧 `alipay_file_path` 被覆盖;不主动删 S3 旧对象,由 S3 生命周期策略自行清理)。 + +#### 2.4.2 展示(读取路径) + +`QrCodeController.list` 在补 `viewUrl` 时**额外**补 `alipayViewUrl`: + +```java +for (QrCode q : page.getData()) { + q.setViewUrl(fileCenterService.getViewUrlByPath(q.getFilePath())); // 微信,走智能路由 + if (q.getAlipayFilePath() != null) { + q.setAlipayViewUrl( + fileCenterService.getS3ViewUrlByPath(q.getAlipayFilePath())); // 支付宝,强制走 S3 + } +} +``` + +`getS3ViewUrlByPath` 是 file-center 新增端点,内部直调 `S3Service.getViewUrlByPath(path)`,**不进 `TimeWindowStorageService`**。 + +### 2.5 拆分到代码层 + +#### 2.5.1 Alipay 二维码服务(zlt-alipay-spring-boot-starter) + +新增 `AlipayQrcodeService`: + +```java +public class AlipayQrcodeService { + + @Autowired private AlipayClientFactory clientFactory; + @Autowired private AlipayConfigService alipayConfigService; + + public String createMiniQrcode(String tenantId, String codeId, + String urlParam, String queryKey, String describe) { + AlipayConfig cfg = alipayConfigService.getConfig("MINI", tenantId); + if (cfg == null) throw new RuntimeException("支付宝小程序配置不存在: " + tenantId); + AlipayClient client = clientFactory.createAlipayClient(cfg); + + AlipayOpenAppQrcodeCreateRequest req = new AlipayOpenAppQrcodeCreateRequest(); + JSONObject biz = new JSONObject(); + biz.put("url_param", urlParam); // 如 pages/link/link + biz.put("query_param", queryKey + "=" + codeId);// 如 uuid= + biz.put("describe", trim16(describe)); + req.setBizContent(biz.toJSONString()); + + if (Boolean.TRUE.equals(cfg.getIsServiceMode()) && cfg.getAuthToken() != null) { + req.putOtherTextParam("app_auth_token", cfg.getAuthToken()); + } + + AlipayOpenAppQrcodeCreateResponse resp = client.execute(req); + if (!resp.isSuccess()) { + throw new RuntimeException("支付宝小程序码生成失败: " + resp.getSubMsg()); + } + return resp.getQrCodeUrl(); + } + + private String trim16(String s) { + if (s == null) return "二维码"; + return s.length() > 16 ? s.substring(0, 16) : s; + } +} +``` + +并在 `AlipayAutoConfiguration` 注册为 `@Bean`。 + +#### 2.5.2 文件中心新增端点(file-center) + +需要两个端点 + 一个新的 `IFileService` 重载: + +**`IFileService.uploadForS3(String name, InputStream is)`**(新方法,强制 S3): + +```java +@Override +public FileInfo uploadForS3(String name, InputStream inputStream) throws IOException { + if (s3Template == null) throw new RuntimeException("S3未配置"); + ObjectInfo info = s3Template.upload(name, inputStream); + FileInfo fileInfo = FileUtil.getFileInfo(name, inputStream); + fileInfo.setPath(info.getObjectPath()); + fileInfo.setUrl(buildCdnUrl(info.getObjectPath())); + fileInfo.setSource("s3"); + baseMapper.insert(fileInfo); + return fileInfo; +} +``` + +**`FileController` 新增两个端点**: + +```java +/** 支付宝小程序码:拉外部 URL 字节,直接入 S3(不进 OSS / 不进智能路由) */ +@GetMapping("/qrcode/s3/by-url") +public Result uploadQrCodeToS3ByUrl(@RequestParam String codeId, + @RequestParam String qrUrl, + @RequestParam(defaultValue = "png") String suffix) throws Exception { + ResponseEntity resp = restTemplate.exchange(qrUrl, HttpMethod.GET, HttpEntity.EMPTY, byte[].class); + if (!resp.getStatusCode().is2xxSuccessful() || resp.getBody() == null) { + return Result.failed("拉取二维码失败: " + resp.getStatusCode()); + } + FileInfo fi = fileService.uploadForS3(codeId + "." + suffix, + new ByteArrayInputStream(resp.getBody())); + return Result.succeed(Map.of("codeId", codeId, "fileId", fi.getId(), "filePath", fi.getPath())); +} + +/** 直接 S3 预签名(绕过 TimeWindowStorageService) */ +@GetMapping("/files/s3/path") +public String getS3ViewUrlByPath(@RequestParam String path) { + return s3Service.getViewUrlByPath(path); +} +``` + +`FileCenterService`(Feign) + `FileCenterServiceFallbackFactory` 同步加: + +```java +@GetMapping("/qrcode/s3/by-url") +Result uploadQrCodeToS3ByUrl(@RequestParam("codeId") String codeId, + @RequestParam("qrUrl") String qrUrl, + @RequestParam("suffix") String suffix); + +@GetMapping("/files/s3/path") +String getS3ViewUrlByPath(@RequestParam("path") String path); +``` + +#### 2.5.3 业务控制器入口(order-center) + +`QrCodeController` 新增: + +```java +@Operation(summary = "为已存在的二维码生成支付宝小程序码") +@PostMapping("/{id}/alipay") +@Transactional(rollbackFor = Exception.class) +public Result generateAlipayQrcode(@PathVariable Long id) throws Exception { + QrCode q = qrCodeService.getById(id); + Assert.notNull(q, "二维码不存在"); + Assert.hasText(q.getCodeId(), "codeId 缺失"); + Assert.hasText(q.getTenantId(),"tenantId 缺失"); + + String qrUrl = alipayQrcodeService.createMiniQrcode( + q.getTenantId(), q.getCodeId(), + alipayPagePath, alipayQueryKey, q.getName()); + + Result upload = fileCenterService.uploadQrCodeToS3ByUrl( + q.getCodeId(), qrUrl, "png"); + if (upload.getResp_code() != 0) return Result.failed("支付宝二维码上传失败"); + + q.setAlipayFileId(upload.getData().get("fileId").toString()); + q.setAlipayFilePath(upload.getData().get("filePath").toString()); + qrCodeService.updateById(q); + return Result.succeed(q, "支付宝二维码生成成功"); +} +``` + +`list(...)` 末尾追加补 `alipayViewUrl` 的逻辑(见 §2.4.2)。 + +配置: + +```properties +# zlt-config 各 application-*.properties +zlt.security.alipay.pagePath=pages/link/link +zlt.security.alipay.queryKey=uuid +``` + +#### 2.5.4 前端改造 + +**`QrcodeItem.tsx`** 新增字段: + +```ts +alipayFileId?: string; +alipayFilePath?: string; +alipayViewUrl?: string; +``` + +**`services/orders.ts`** 新增: + +```ts +generateAlipayQrcode: async (id: number) => { + const res = await request(`/api-order/qrcode/${id}/alipay`, { method: 'POST' }); + return (res as any).data || res; +}, +``` + +**`QrcodeListModal.tsx`** 改动: +- 新增列「支付宝二维码」(在现有「二维码」列右侧): + - `alipayViewUrl` 存在 → 渲染缩略图,点击放大(复用现有 `previewOpen` Modal)。 + - 不存在 → 渲染 ``,点击调 `generateAlipayQrcode(id)` 并刷新表格。 +- 新增/编辑表单 **不动**。当前业务字段仍由 `QrcodeTourismForm` 管,支付宝码是行级附属操作。 +- 操作列可加「重新生成支付宝码」入口(与列内按钮等价,便于已生成的码重置)。 + +### 2.6 风险点与回归项 + +| 风险 | 缓解 | +|------|------| +| `qr_code_url` 临时 URL 拉取期间过期 | 拿到后立即拉取并入 S3;任何步骤失败 → `@Transactional` 回滚,行上 `alipay_file_path` 保持原值 | +| ISV 模式 `app_auth_token` 缺失 | `AlipayQrcodeService` 自动注入,与 `AlipayPayService` 一致 | +| `describe` 限 16 字 | 服务里 `trim16()` 兜底 | +| `url_param` 必须是已发布页面 | 配置项独立 (`zlt.security.alipay.pagePath`);上线前由开放平台审核保证 | +| 旧数据兼容 | 新列允许 NULL;老数据 `alipayViewUrl=null`,前端按"未生成"展示 | +| 文件中心新接口安全 | `/qrcode/s3/by-url` / `/files/s3/path` 仅供 Feign 内调,可由网关白名单或 IP 限制 | +| 同一 codeId 重复点击"生成" | 接口幂等:每次会拿新 `qrCodeUrl`,覆盖 `alipay_file_path`;S3 旧对象不主动删,靠生命周期策略 | +| S3 未配置导致 `uploadForS3` 抛错 | 控制器层捕获并返回 `Result.failed`,前端弹错;不影响微信码 | + +### 2.7 上线步骤 + +1. 跑 `add_qrcode_alipay_fields.sql`。 +2. 部署 `zlt-alipay-spring-boot-starter`、`order-center`、`file-center`(一起,因 Feign 契约改动)。 +3. 在 `alipay_config` 录入 `type=MINI` 配置(appId / 私钥 / 支付宝公钥)。 +4. 支付宝开放平台开通能力 + 配置 `pages/link/link` 页面白名单。 +5. 后台对一条已有微信码的行点「生成支付宝码」,验证: + - 列表新列出现支付宝缩略图,点击放大正常; + - 用支付宝扫码进入小程序对应页,`options.uuid` 与微信扫码后取到的一致; + - 进入业务流程(下单等)后端读取 `qrcodes.code_id` 命中**同一行**,价格 / 航线 / 设备 / 模板等均正确。 + +--- + +## 附录 A:相关 SQL/接口对照表 + +| 用途 | 微信 | 支付宝 | +|------|------|--------| +| 凭证来源 | Nacos `zlt.security.tencent.*`(全局) | DB `alipay_config(type=MINI, tenant_id=?)` | +| 二维码接口 | `cgi-bin/wxaapp/createwxaqrcode` | `alipay.open.app.qrcode.create` | +| 透传参数 | URL `?uuid=` | `query_param=uuid=` | +| 接口返回 | `byte[]`(JPEG) | `qr_code_url`(PNG,需二次拉取) | +| 存储后端 | OSS(智能路由 OSS↔MinIO) | **S3(MinIO,固定)** | +| 存储文件名 | `.jpeg` | `.png` | +| 业务表行 | 同一行 `qrcodes`(共享 `code_id` 与全部业务字段) | | +| 行内字段 | `file_id` / `file_path` / `view_url`(transient) | `alipay_file_id` / `alipay_file_path` / `alipay_view_url`(transient) | +| 写入入口 | `POST /qrcode/withPlan`(创建打卡点时同时生成) | `POST /qrcode/{id}/alipay`(按行追加) | +| 读取入口(拼图 URL) | `GET /files/path`(智能路由) | `GET /files/s3/path`(直连 S3) | +| 文件中心上传端点 | `GET /qrcode/{codeId}` | `GET /qrcode/s3/by-url?codeId=&qrUrl=&suffix=png` | + +## 附录 B:核心文件清单(变更预期) + +- 新增: + - `zlt-business/order-center/src/main/resources/sql/add_qrcode_alipay_fields.sql` + - `zlt-commons/zlt-alipay-spring-boot-starter/.../service/AlipayQrcodeService.java` +- 修改: + - `zlt-commons/zlt-alipay-spring-boot-starter/.../config/AlipayAutoConfiguration.java`(注册 Bean) + - `zlt-business/file-center/.../service/IFileService.java`(新增 `uploadForS3(name, InputStream)` 重载) + - `zlt-business/file-center/.../service/impl/AbstractIFileService.java`(实现新重载) + - `zlt-business/file-center/.../controller/FileController.java`(新增 `/qrcode/s3/by-url`、`/files/s3/path`) + - `zlt-business/order-center/.../feign/FileCenterService.java`(新增 Feign 方法) + - `zlt-business/order-center/.../feign/fallback/FileCenterServiceFallbackFactory.java` + - `zlt-business/order-center/.../controller/QrCodeController.java`(新增 `POST /qrcode/{id}/alipay`,`list` 补 `alipayViewUrl`) + - `zlt-business/order-center/.../model/QrCode.java`(新增 `alipayFileId` / `alipayFilePath` / `alipayViewUrl`) + - `zlt-config` 各 `application-*.properties`(`zlt.security.alipay.pagePath` / `queryKey`) + - 前端:`QrcodeItem.tsx` / `QrcodeListModal.tsx` / `services/orders.ts` + - 前端:`QrcodeItem.tsx` / `QrcodeTourismForm.tsx` / `QrcodeListModal.tsx` / `services/orders.ts` diff --git a/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeItem.tsx b/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeItem.tsx index 9fe723d5..34f3076b 100644 --- a/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeItem.tsx +++ b/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeItem.tsx @@ -32,6 +32,10 @@ export interface QrcodeItem { qrDescribe?: string; enableCtripOrder?: number; // 是否创建携程订单(0:否,1:是) ctripProductId?: string; // 携程产品ID(enableCtripOrder=1 时必填) + // 支付宝小程序二维码(同行追加,与微信码共用 codeId) + alipayFileId?: string; + alipayFilePath?: string; + alipayViewUrl?: string; // 后端动态生成的 S3 预签名 URL,不入库 } export interface QrcodeFormProps { open: boolean; diff --git a/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeListModal.tsx b/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeListModal.tsx index ac93efe6..0f766323 100644 --- a/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeListModal.tsx +++ b/zlt-web/react-web-next/src/pages/orders/Tourism/components/QrcodeListModal.tsx @@ -42,6 +42,22 @@ const QrcodeListModal: React.FC = ({ open, onOpenChange, t const [current, setCurrent] = useState(undefined); const [previewOpen, setPreviewOpen] = useState(false); const [previewImage, setPreviewImage] = useState(''); + const [alipayLoadingId, setAlipayLoadingId] = useState(undefined); + + const handleGenerateAlipay = useCallback(async (id: number) => { + setAlipayLoadingId(id); + const hide = message.loading('正在生成支付宝二维码...'); + try { + await ordersApi.generateAlipayQrcode(id); + message.success('支付宝二维码生成成功'); + actionRef.current?.reload(); + } catch (e) { + message.error('支付宝二维码生成失败'); + } finally { + hide(); + setAlipayLoadingId(undefined); + } + }, []); // 模板ID -> 模板名称(通过接口懒加载) const templateNameMapRef = useRef>({}); @@ -144,6 +160,47 @@ const title = useMemo(() => `打卡点二维码列表${tourismName ? `(${touri ); }, }, + { + title: '支付宝二维码', + dataIndex: 'alipayViewUrl', + width: 130, + render: (url: string, record: QrcodeItem) => { + if (url) { + return ( +

+ 支付宝二维码 { + setPreviewImage(url); + setPreviewOpen(true); + }} + /> + +
+ ); + } + return ( + + ); + }, + }, { title: '设备SN', dataIndex: 'deviceSn', width: 150 }, { title: '价格', diff --git a/zlt-web/react-web-next/src/services/orders.ts b/zlt-web/react-web-next/src/services/orders.ts index 6d697799..01f6c716 100644 --- a/zlt-web/react-web-next/src/services/orders.ts +++ b/zlt-web/react-web-next/src/services/orders.ts @@ -93,6 +93,11 @@ export const ordersApi = { const res = await request(`/api-order/qrcode/${id}`, { method: 'DELETE' }); return (res as any).data || res; }, + // 为已存在的二维码生成支付宝小程序二维码(同行追加,不另起一行) + generateAlipayQrcode: async (id: number) => { + const res = await request(`/api-order/qrcode/${id}/alipay`, { method: 'POST' }); + return (res as any).data || res; + }, // 根据景区ID查询二维码列表 qrcodeListByTourism: async (params: { current?: number; pageSize?: number; tourismId: number; [k: string]: any }) => { const { current, pageSize, ...rest } = params || {};