diff --git a/src/main/java/com/cultural/heritage/controller/file/FileController.java b/src/main/java/com/cultural/heritage/controller/file/FileController.java index 8703859..3b1a812 100644 --- a/src/main/java/com/cultural/heritage/controller/file/FileController.java +++ b/src/main/java/com/cultural/heritage/controller/file/FileController.java @@ -10,6 +10,7 @@ import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.enums.FileUploadBizEnum; import com.cultural.heritage.service.file.IHweiYunOBSService; import com.cultural.heritage.service.user.UserService; +import com.cultural.heritage.utils.RegexUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; @@ -53,8 +54,11 @@ public class FileController { if (loginUser == null) { throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR, "未登录"); } + // 获取文件名 String filePath = getFilePath(multipartFile, uploadFileRequest); - + // 格式化图片特殊字符 + filePath = RegexUtils.encodeUrl(filePath); + // 上传文件至华为云服务器 iHweiYunOBSService.fileUpload(multipartFile, filePath); return ResultUtils.success(filePath, "上传成功"); @@ -80,15 +84,6 @@ public class FileController { - - - - - - - - - /** * 校验文件 * @param multipartFile 文件 diff --git a/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java b/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java index 030b1eb..d1ce821 100644 --- a/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java +++ b/src/main/java/com/cultural/heritage/controller/wx/WeChatController.java @@ -138,7 +138,7 @@ public class WeChatController { * Web端管理员分页查看文章 * @return 用户地址列表 */ - @GetMapping("/query") + @PostMapping("/query/web") @Operation(summary = "Web端管理员分页查看文章", description = "参数:无,权限:web端管理员,方法名:listArticleByPage") public BaseResponse> listArticleByPage(@RequestBody OfficialAccountArticleQueryRequest officialAccountArticleQueryRequest) { if (officialAccountArticleQueryRequest == null) throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -170,7 +170,6 @@ public class WeChatController { - @PostMapping("/getArticle") @Hidden public BaseResponse> getArticleInfo() { diff --git a/src/main/java/com/cultural/heritage/utils/DecoderUtils.java b/src/main/java/com/cultural/heritage/utils/DecoderUtils.java index 1d61770..c979128 100644 --- a/src/main/java/com/cultural/heritage/utils/DecoderUtils.java +++ b/src/main/java/com/cultural/heritage/utils/DecoderUtils.java @@ -11,4 +11,5 @@ public class DecoderUtils { return new String(decodedBytes, StandardCharsets.UTF_8); } + } diff --git a/src/main/java/com/cultural/heritage/utils/RegexUtils.java b/src/main/java/com/cultural/heritage/utils/RegexUtils.java index 266c4de..6bc5126 100644 --- a/src/main/java/com/cultural/heritage/utils/RegexUtils.java +++ b/src/main/java/com/cultural/heritage/utils/RegexUtils.java @@ -2,6 +2,9 @@ package com.cultural.heritage.utils; import org.apache.commons.lang3.StringUtils; +import java.util.HashMap; +import java.util.Map; + import static com.cultural.heritage.constant.RegexConstant.*; @@ -54,4 +57,31 @@ public class RegexUtils { } return !str.matches(regex); } + + + + + + + public static String encodeUrl(String input) { + Map replaceMap = new HashMap<>(); + replaceMap.put(" ", "%20"); + replaceMap.put("\\+", "%2B"); + replaceMap.put("\\?", "%3F"); + replaceMap.put("#", "%23"); + replaceMap.put("&", "%26"); + replaceMap.put("/", "%2F"); + replaceMap.put(":", "%3A"); + replaceMap.put("\\(", "%28"); + replaceMap.put("\\)", "%29"); + replaceMap.put("!", "%21"); + + for (Map.Entry entry : replaceMap.entrySet()) { + input = input.replaceAll(entry.getKey(), entry.getValue()); + } + return input; + } + + + }