fix:支付宝二维码

This commit is contained in:
2026-06-17 18:37:12 +08:00
parent 0ac3bece42
commit 73d7c819cf
15 changed files with 959 additions and 2 deletions
@@ -1,5 +1,6 @@
package com.central.order.controller;
import com.central.alipay.service.AlipayQrcodeService;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.common.utils.StringUtils;
@@ -17,10 +18,11 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.Assert;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -59,6 +61,15 @@ public class QrCodeController {
@Autowired
private IPackagePlanService packagePlanService;
@Autowired
private AlipayQrcodeService alipayQrcodeService;
@Value("${zlt.security.alipay.pagePath:pages/link/link}")
private String alipayPagePath;
@Value("${zlt.security.alipay.queryKey:uuid}")
private String alipayQueryKey;
/**
* 列表
*/
@@ -73,6 +84,9 @@ public class QrCodeController {
if (pageResult.getResp_code() == 0){
for (QrCode qrCode: pageResult.getData()){
qrCode.setViewUrl(fileCenterService.getViewUrlByPath(qrCode.getFilePath()));
if (qrCode.getAlipayFilePath() != null && !qrCode.getAlipayFilePath().isEmpty()) {
qrCode.setAlipayViewUrl(fileCenterService.getS3ViewUrlByPath(qrCode.getAlipayFilePath()));
}
}
}
return pageResult;
@@ -252,4 +266,42 @@ public class QrCodeController {
return result;
}
@Operation(summary = "为已存在的二维码生成支付宝小程序码(同行追加,不另起一行)")
@PostMapping("/{id}/alipay")
@Transactional(rollbackFor = Exception.class)
public Result<QrCode> 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<Map> 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, "支付宝二维码生成成功");
}
}
@@ -36,6 +36,20 @@ public interface FileCenterService {
@GetMapping("/qrcode/{codeId}")
Result<Map> uploadQrCodeFile(@PathVariable("codeId") String codeId) throws Exception;
/**
* 拉取外部图片 URL 字节并强制入 S3(用于支付宝小程序二维码)
*/
@GetMapping("/qrcode/s3/by-url")
Result<Map> 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);
@@ -41,6 +41,17 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCen
return null;
}
@Override
public Result<Map> 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;
@@ -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;
}
@@ -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)';