公告结构化

This commit is contained in:
zhangqinbin
2023-12-13 14:55:31 +08:00
parent dada7c283a
commit 0022ad6280
3 changed files with 91 additions and 31 deletions

View File

@ -7,10 +7,12 @@ import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity; import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity;
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
import com.chinaunicom.mall.ebtp.common.log.OperationLogDetail; import com.chinaunicom.mall.ebtp.common.log.OperationLogDetail;
import com.chinaunicom.mall.ebtp.common.log.enums.EbtpLogBusinessModule; import com.chinaunicom.mall.ebtp.common.log.enums.EbtpLogBusinessModule;
import com.chinaunicom.mall.ebtp.common.log.enums.EbtpLogType; import com.chinaunicom.mall.ebtp.common.log.enums.EbtpLogType;
import com.chinaunicom.mall.ebtp.extend.feign.client.UnicomOAuthClient; import com.chinaunicom.mall.ebtp.extend.feign.client.UnicomOAuthClient;
import com.chinaunicom.mall.ebtp.extend.shortmessage.utils.RSA;
import com.chinaunicom.mall.ebtp.extend.wps.entity.KingSoftFileSaveVo; import com.chinaunicom.mall.ebtp.extend.wps.entity.KingSoftFileSaveVo;
import com.chinaunicom.mall.ebtp.extend.wps.enums.WpsExceptionEnum; import com.chinaunicom.mall.ebtp.extend.wps.enums.WpsExceptionEnum;
import com.chinaunicom.mall.ebtp.extend.wps.service.WpsService; import com.chinaunicom.mall.ebtp.extend.wps.service.WpsService;
@ -124,11 +126,41 @@ public class WpsController {
* @param in * @param in
* @return * @return
*/ */
// @ApiOperation("(金山)获得编辑或查看链接")
// @PostMapping("/kingSoft/getWpsUrl")
// public BaseResponse<String> getKSWpsUrl(@RequestBody WpsClientInVo in) {
// String str = this.wpsService.getKSWpsUrl(in);
// return BaseResponse.success(str);
// }
/**
* (金山)获得编辑或查看链接
*
* @return
*/
@ApiOperation("(金山)获得编辑或查看链接") @ApiOperation("(金山)获得编辑或查看链接")
@PostMapping("/kingSoft/getWpsUrl") @GetMapping("/kingSoft/getWpsUrl")
public BaseResponse<String> getKSWpsUrl(@RequestBody WpsClientInVo in) { public void getWpsUrlBy(HttpServletRequest request, HttpServletResponse response, @RequestParam("key") String key) {
String str = this.wpsService.getKSWpsUrl(in); //cookie传输token
return BaseResponse.success(str); Optional<Cookie> cookie = Optional.ofNullable(request.getCookies())
.flatMap(cookies -> Stream.of(cookies)
.filter(item -> StringUtils.equals(item.getName(), COOKIE_TOKEN_CODE)
).findFirst());
if (cookie.isPresent()) {
String authToken = cookie.get().getValue();
WpsClientInVo in = this.wpsService.getKSWpsUrlDecrypt(key);
in.setUserToken(authToken);
String str = this.wpsService.getKSWpsUrl(in);
try {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println(str);
}catch (Exception e){
e.printStackTrace();
}
}else{
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("无效请求",true);
}
} }
/** /**
* (金山)获得编辑或查看链接 * (金山)获得编辑或查看链接
@ -150,32 +182,9 @@ public class WpsController {
in.setType(type); in.setType(type);
String str = this.wpsService.getKSWpsUrl(in); String str = this.wpsService.getKSWpsUrl(in);
try { try {
String token = userToken;
// Optional<Cookie> optionalCookie = Optional.ofNullable(request.getCookies())
// .flatMap(cookies ->
// Stream.of(cookies)
// .filter(item -> StringUtils.equals(item.getName(), COOKIE_TOKEN_CODE))
// .findFirst());
//
// if (optionalCookie.isPresent()) {
// token = optionalCookie.get().getValue();
// log.info("cookie:",token);
// }else{
// log.error("未获取到cookie");
// }
// log.info("传入token : cookie:"+userToken);
// log.info("传入token : token:"+token);
response.setContentType("text/html;charset=utf-8"); response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
// response.setHeader("Cookie","mall3_token="+userToken);
// Cookie theC = new Cookie("mall3_token",userToken);
// theC.setMaxAge(-1);
// theC.setPath("/");
// response.addCookie(theC);
out.println(str); out.println(str);
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
@ -210,9 +219,11 @@ public class WpsController {
Optional<AttachmentDetail> optional = attachmentClient.findByBusinessId(businessIdList); Optional<AttachmentDetail> optional = attachmentClient.findByBusinessId(businessIdList);
String fileLength = "10";
String fileName = fileId; String fileName = fileId;
byte buf[] = new byte[0]; String text = " ";
byte buf[] = text.getBytes();
String fileLength = String.valueOf(buf.length);
if(optional!=null&&optional.get()!=null){ if(optional!=null&&optional.get()!=null){
AttachmentDetail detail = optional.get(); AttachmentDetail detail = optional.get();

View File

@ -20,11 +20,13 @@ public interface WpsService{
Object saveWpsFile(String token, String userId, String userName, String fileId, String fileName, File file); Object saveWpsFile(String token, String userId, String userName, String fileId, String fileName, File file);
WpsClientInVo getKSWpsUrlDecrypt(String key);
String getKSWpsUrl(WpsClientInVo in); String getKSWpsUrl(WpsClientInVo in);
byte[] getKSWpsFile(String id); byte[] getKSWpsFile(String id);
public String downloadDecrypt(String key); String downloadDecrypt(String key);
Map<String,String> saveKSFile(KingSoftFileSaveVo vo); Map<String,String> saveKSFile(KingSoftFileSaveVo vo);
} }

View File

@ -80,6 +80,9 @@ public class WpsServiceImpl implements WpsService {
@Resource @Resource
private UnicomOAuthClient unicomOAuthClient; private UnicomOAuthClient unicomOAuthClient;
@Resource
private IBaseCacheUserService iBaseCacheUserService;
@Value("${mconfig.wps.bssAppId}") @Value("${mconfig.wps.bssAppId}")
private String bss_app_id; private String bss_app_id;
@Value("${mconfig.wps.bssAppSecret}") @Value("${mconfig.wps.bssAppSecret}")
@ -262,6 +265,45 @@ public class WpsServiceImpl implements WpsService {
return wpsFile; return wpsFile;
} }
@Override
public WpsClientInVo getKSWpsUrlDecrypt(String key){
String val = RSA.decrypt(key,kswprivateKey);
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("请求参数无效",val.indexOf("_")<0);
//fileId_yyyyMMddHHmmss_type
String[] value = val.split("_");
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("请求参数无效",value.length<4);
String fileId = value[0];
String time = value[1];
String type = value[2];
String extension = value[3];
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
long newDateLong = System.currentTimeMillis();
long inDateLong = 0;
try {
Date inDate = format.parse(time);
inDateLong = inDate.getTime();
}catch (Exception e){
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("请求时间戳错误",true);
}
//time_limit = "120000";
log.info("newDateLong:"+newDateLong);
log.info("inDateLong:"+inDateLong);
if(newDateLong-inDateLong>Long.valueOf(kswTimeLimit)){//
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("请求已失效-",true);
}
WpsClientInVo in = new WpsClientInVo();
in.setFileId(fileId);
in.setFileName(fileId+"."+extension);
in.setType(type);
return in;
}
private Map<String,String> validateWps(String token,String fileId,Optional op,String permission){ private Map<String,String> validateWps(String token,String fileId,Optional op,String permission){
Map<String,String> mess= new HashMap<>(); Map<String,String> mess= new HashMap<>();
mess.put("result","20501007"); mess.put("result","20501007");
@ -593,6 +635,7 @@ public class WpsServiceImpl implements WpsService {
String token = value[1]; String token = value[1];
String time = value[2]; String time = value[2];
String md = value[3]; String md = value[3];
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("令牌无效",val.length()<4);
String o_key = MdConstants.getSha256(time+fileId+appName+token);// String o_key = MdConstants.getSha256(time+fileId+appName+token);//
@ -705,7 +748,11 @@ public class WpsServiceImpl implements WpsService {
wpsService.kswpublicKey = "MIGfMA0GCSqGSIb3DQEBA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-ebtp-extend"; wpsService.appName = "biz-service-ebtp-extend";
String key = wpsService.getDownloadEncrypt("1679764839191080961","3a1f5aae-3cd2-4599-87b0-712e40625c7c"); String jm = RSA.encrypt("1679764839191080961_20231213145159_0_doc",wpsService.kswpublicKey);
System.out.println(jm);
String jem = RSA.decrypt(jm,wpsService.kswprivateKey);
System.out.println(jem);
//String key = wpsService.getDownloadEncrypt("1679764839191080961","3a1f5aae-3cd2-4599-87b0-712e40625c7c");
//加解密 //加解密
// String key = URLDecoder.decode( "FkvDifsfK8frde0ywRzdPMmOlR4%2FO8C4VORaw%2FwshgBt%2B49Z2%2B0al4KwyQ97Js8Yh24%2ByMT%2Fln4Aqx%2BVZNkGqOh0OxP1H3qj%2BP%2BlP1Sybvs5I0q%2BtFpW9nMQcGAsenFNLgcFtUtsQAJG4ALG4cH34TnDnSjuivM9tmA1Gt%2BzsJU%3D","utf-8"); // String key = URLDecoder.decode( "FkvDifsfK8frde0ywRzdPMmOlR4%2FO8C4VORaw%2FwshgBt%2B49Z2%2B0al4KwyQ97Js8Yh24%2ByMT%2Fln4Aqx%2BVZNkGqOh0OxP1H3qj%2BP%2BlP1Sybvs5I0q%2BtFpW9nMQcGAsenFNLgcFtUtsQAJG4ALG4cH34TnDnSjuivM9tmA1Gt%2BzsJU%3D","utf-8");
// String val = RSA.decrypt(key,wpsService.kswprivateKey); // String val = RSA.decrypt(key,wpsService.kswprivateKey);