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);
@@ -5,9 +5,11 @@ import com.central.alipay.entity.AlipayConfig;
import com.central.alipay.notify.AlipayNotifyVerifier;
import com.central.alipay.service.AlipayPayService;
import com.central.alipay.service.AlipayRefundService;
import com.central.common.context.LoginUserContextHolder;
import com.central.common.context.TenantContextHolder;
import com.central.common.feign.UserService;
import com.central.common.model.LoginAppUser;
import com.central.common.model.Result;
import com.central.common.model.SysUser;
import com.central.common.utils.SecurityTenantUtils;
import com.central.order.enums.OrderStatus;
@@ -83,7 +85,7 @@ public class AliPayController {
required = true,
content = @Content(schema = @Schema(example = "{\"orderId\": 1001, \"buyerId\": \"2088xxxxxxxxxxxx\"}")))
@PostMapping("/order/pay")
public Map<String, Object> payOrder(@RequestBody Map<String, Object> body) {
public Result<AlipayTradeCreateResponse> payOrder(@RequestBody Map<String, Object> body) {
Object rawOrderId = body.get("orderId");
Assert.notNull(rawOrderId, "orderId 不能为空");
Long orderId = Long.valueOf(rawOrderId.toString());
@@ -91,7 +93,7 @@ public class AliPayController {
Assert.notNull(order, "订单不存在: " + orderId);
// 校验当前登录用户拥有该订单(防止替他人订单发起支付)
LoginAppUser currentUser = SecurityTenantUtils.getCurrentUser();
LoginAppUser currentUser = LoginUserContextHolder.getUser();
Assert.notNull(currentUser, "未登录或登录已过期");
if (order.getUserId() == null || !order.getUserId().equals(currentUser.getId())) {
throw new IllegalStateException("无权操作他人订单, orderId: " + orderId);
@@ -143,16 +145,11 @@ public class AliPayController {
}
AlipayTradeCreateResponse response = alipayPayService.create(config, req);
Map<String, Object> result = new HashMap<>();
if (response.isSuccess()) {
result.put("tradeNo", response.getTradeNo());
result.put("outTradeNo", response.getOutTradeNo());
return Result.succeed(response,response.getMsg());
} else {
result.put("error", response.getSubMsg());
result.put("code", response.getCode());
return Result.failed(response.getMsg());
}
return result;
}
// ==================== 支付异步回调 ====================