fix:支付宝支付

This commit is contained in:
2026-06-24 16:58:10 +08:00
parent 73d7c819cf
commit 7550fbed35
4 changed files with 18 additions and 46 deletions
@@ -63,6 +63,12 @@ public class FileController {
@Value("${zlt.security.tencent.getwxacodeUrl}")
private String getwxacodeUrl;
@Value("${cdn.s3.domain:minicdn.goflytec.com}")
private String s3CdnDomain;
@Value("${cdn.s3.enabled:true}")
private boolean s3CdnEnabled;
private final RestTemplate restTemplate = new RestTemplate();
@Value("${zlt.security.tencent.pagePath}")
@@ -226,19 +232,19 @@ public class FileController {
}
/**
* 直接 S3 预签名(绕过 TimeWindowStorageService 智能路由)
* 直接 S3 无过期访问地址(绕过 TimeWindowStorageService 智能路由)
* 用于支付宝小程序二维码:与 AbstractIFileService.uploadForS3 上传时设置的 fileInfo.url 完全一致 ——
* 直接拼 https://<s3CdnDomain>/<objectPath>,不签名、不带过期、可被 CDN 缓存。
*/
@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 "";
if (s3CdnEnabled && s3CdnDomain != null && !s3CdnDomain.isEmpty()) {
return "https://" + s3CdnDomain + "/" + path;
}
return path;
}
@PostMapping("/path")
@@ -48,9 +48,4 @@ public interface IFileService extends IService<FileInfo> {
String getViewUrlByPathAndExpires(String name,int expires);
String getS3UrlByPath(String path);
/**
* 强制返回 S3 预签名 URL(绕开智能路由,用于支付宝小程序二维码展示)
*/
String getS3ViewUrlByPath(String path);
}
@@ -181,32 +181,6 @@ public abstract class AbstractIFileService extends ServiceImpl<FileMapper, FileI
public abstract String getDownloadUrl(String path);
/**
* 强制返回 S3 预签名 URL(绕开智能路由 / 智能存储路由),用于支付宝小程序二维码等需要稳定 S3 入口的场景。
* 默认返回 60 分钟预签名;S3 未配置时抛运行时异常,由调用方决定是否降级。
*/
@Override
public String getS3ViewUrlByPath(String path) {
if (s3Template == null) {
throw new RuntimeException("S3服务未配置,无法获取S3预签名URL");
}
if (path == null || path.isEmpty()) {
return "";
}
try {
int splitIndex = path.lastIndexOf('/');
if (splitIndex < 0) {
return "";
}
String bucketName = path.substring(0, splitIndex);
String objectName = path.substring(splitIndex + 1);
return s3Template.getViewUrl(bucketName, objectName, 60);
} catch (Exception e) {
log.warn("获取S3预签名URL失败: path={}, err={}", path, e.getMessage());
return "";
}
}
@Override
public FileInfo getFileInfo(String id) {
return baseMapper.selectById(id);