From ee6ca428fa66c7a51dcb61d666cb611e086f6765 Mon Sep 17 00:00:00 2001 From: zhangqinbin <181961702@qq.com> Date: Thu, 21 Dec 2023 15:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=91=8A=E7=BB=93=E6=9E=84=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extend/wps/controller/WpsController.java | 21 ++++++++++++++----- .../wps/service/impl/WpsServiceImpl.java | 5 +++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java index b6e8569..25010a4 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java @@ -37,6 +37,7 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -44,6 +45,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Stream; +import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.AUTHORIZATION_HEADER; import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.COOKIE_TOKEN_CODE; @Slf4j @@ -149,6 +151,13 @@ public class WpsController { ).findFirst()); if (cookie.isPresent()) { + log.info(String.valueOf(request.getRequestURL())); + String protocol = request.getScheme(); // 获取协议,如HTTP或HTTPS + String ip = request.getRemoteAddr(); // 获取客户端IP地址 + int port = request.getServerPort(); // 获取服务器端口号 + String host = protocol+"://"+ip+":"+port; + log.info("getWpsUrlBy:"+host); + String authToken = cookie.get().getValue(); WpsClientInVo in = this.wpsService.getKSWpsUrlDecrypt(key,fileName); in.setUserToken(authToken); @@ -245,23 +254,25 @@ public class WpsController { @ApiOperation("(金山)沃文档回调-查询文档") @GetMapping("/kingSoft/file2") public boolean getKSFile2(HttpServletRequest request,HttpServletResponse response, @RequestParam("key") String key) { - String fileId = this.wpsService.downloadDecrypt(key); + //带后缀 + String fileNameE = this.wpsService.downloadDecrypt(key); + + String[] fileId = fileNameE.split("."); List businessIdList = new ArrayList<>(); - businessIdList.add(fileId); + businessIdList.add(fileId[0]); Optional optional = attachmentClient.findByBusinessId(businessIdList); - - String fileName = fileId; + String fileName = fileNameE; String text = " "; byte buf[] = text.getBytes(); String fileLength = String.valueOf(buf.length); if(optional!=null&&optional.get()!=null){ AttachmentDetail detail = optional.get(); - List entityList = detail.get(fileId); + List entityList = detail.get(fileId[0]); if(entityList!=null&&entityList.size()>0) { Optional optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); fileLength = String.valueOf(optional1.get().length); diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java index cf26ae1..7c65e45 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java @@ -551,7 +551,7 @@ public class WpsServiceImpl implements WpsService { byte[] b = getFileByFileId(in.getFileId(),in.getFileName()); String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); try { - callBackUrl = kswdownloadUrl+"?key="+URLEncoder.encode(getDownloadEncrypt(in.getFileId(),in.getUserToken()), "utf-8"); + callBackUrl = kswdownloadUrl+"?key="+URLEncoder.encode(getDownloadEncrypt(in.getFileId(),in.getFileExtension(),in.getUserToken()), "utf-8"); }catch (UnsupportedEncodingException e){ log.error("url转换失败",e); @@ -610,9 +610,10 @@ public class WpsServiceImpl implements WpsService { return ret.getData(); } - private String getDownloadEncrypt(String fileId,String token){ + private String getDownloadEncrypt(String fileId,String fileExtension,String token){ String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); //fileId+ebtp+token+time md5加密 + fileId = fileId+"."+fileExtension; String mdKey = MdConstants.getSha256(time+fileId+appName+token); log.info("mdKey:"+mdKey); //fileId|token|yyyyMMddHHmmss|md5加密