政企WPS

This commit is contained in:
zhangqinbin
2023-12-22 08:59:13 +08:00
parent 09c8cd8ce6
commit 0304f25a2b
4 changed files with 36 additions and 17 deletions

View File

@ -299,11 +299,9 @@ public class RSA {
System.out.println(keyMap); System.out.println(keyMap);
//取得公钥和么私钥 //取得公钥和么私钥
//keyMap = initKey(); //keyMap = initKey();
//String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCgkWYQFjlRrCsQQBNZj6uo8KEQamePmxaC6O4JI5SoELnXPlTCJIlQTG1Xzn/ajqjDV4/5ZmZAH+auST4j9L5qH8qnoxT1AN+yhUY6hMV9qxF00e1gBc81mYJO2nwwaQjRsGEoq86e9dP1zX5kOk8vMZN6/g508a1K2IWNwpGp0wIDAQAB";
String publicKey = getPublicKey(keyMap); String publicKey = getPublicKey(keyMap);
System.out.println("字符类型公钥:" + publicKey); System.out.println("字符类型公钥:" + publicKey);
//String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKCRZhAWOVGsKxBAE1mPq6jwoRBqZ4+bFoLo7gkjlKgQudc+VMIkiVBMbVfOf9qOqMNXj/lmZkAf5q5JPiP0vmofyqejFPUA37KFRjqExX2rEXTR7WAFzzWZgk7afDBpCNGwYSirzp710/XNfmQ6Ty8xk3r+DnTxrUrYhY3CkanTAgMBAAECgYA8WMkqLKAYUQPSVLKxC20xzlZKbCNF9rzMMK0d5DB/xeGCwxtp5/9vnXnO8X5d7xYAbM1gp5qwaQzy3fYr31UcxHiFTcZMgvN6z32FNBEkejCLaKIFZjaMBn36dStdzpAP+OOclwpXDGpGQO0UKLKshAfl5dsS+fq+nHpOugz52QJBAPUCG9Xzy5TrMiqL9n1TLe1qR+ALfELZHFheevIkyShJtcqlte8u640H0CHDXF9lniisMFn4xChqkxiTUsees58CQQCnxYDP+JfmqORO4Cx2DLCCqOpaOkuxdZo8eSh80s3zbmtdqoMpeYZglVNLuSYKNul8WWF3qeGqcnLULDE6P31NAkEAtSLt+WvYoyyPVi1L+rO4TMI6iUV0hOeGsT6InuTbY1G7eSqyKzcBJq8UDSIl9NFn8KH8zUfBni/MuGqS1Mpb+QJATiPTBwpF1Yy8KXCHxMPMQk7iN/wG3TRlDd1wWhLlEYhQQWP1iw+q4rkp/o7RhNhmjyAiIVXiYTzE9sVOeE6x0QJBAJYmBmOKfxw3rzpjDU+e9I6w0AbpiBzlnviEToZfnDwVH9mjF++H/wDRTDqozIiAE2aN/wqXwqhoWGgVWMlp9Xc=";
String privateKey = getPrivateKey(keyMap);// String privateKey = getPrivateKey(keyMap);//
System.out.println("字符类型私钥:" + privateKey); System.out.println("字符类型私钥:" + privateKey);

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.api.AttachmentClient; import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.api.AttachmentClient;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail; 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.ebtp.mall.cloud.attachment.sdk.model.UploadObject;
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.exception.common.CommonExceptionEnum;
@ -293,18 +294,10 @@ public class WpsController {
String fileName = fileIdName; String fileName = fileIdName;
String text = " "; String text = " ";
byte buf[] = text.getBytes(); byte buf[] = text.getBytes();
try {
File tempFile = File.createTempFile("tempDoc", ".doc");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(tempFile));
buf = IOUtils.toByteArray(bis);
tempFile.deleteOnExit();
}catch (Exception e){
log.error("读取异常",e);
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("模板文件读取异常",true);
}
String fileLength = String.valueOf(buf.length); String fileLength = String.valueOf(buf.length);
//是否有上传文件
Boolean uploadB = true;
if(optional!=null&&optional.get()!=null){ if(optional!=null&&optional.get()!=null){
AttachmentDetail detail = optional.get(); AttachmentDetail detail = optional.get();
List<AttachmentEntity> entityList = detail.get(fileId[0]); List<AttachmentEntity> entityList = detail.get(fileId[0]);
@ -313,8 +306,13 @@ public class WpsController {
fileLength = String.valueOf(optional1.get().length); fileLength = String.valueOf(optional1.get().length);
fileName = entityList.get(0).getFilename(); fileName = entityList.get(0).getFilename();
buf = optional1.get(); buf = optional1.get();
uploadB = false;
} }
} }
if(uploadB){
buf = this.wpsService.uploadTempFile(fileId[0]);
//Optional<UploadObject> op=attachmentClient.upload(fileId[0],fileName,buf);
}
try{ try{
// 设置响应的头信息,告诉浏览器文件的大小和下载方式 // 设置响应的头信息,告诉浏览器文件的大小和下载方式

View File

@ -29,4 +29,6 @@ public interface WpsService{
String downloadDecrypt(String key); String downloadDecrypt(String key);
Map<String,String> saveKSFile(KingSoftFileSaveVo vo); Map<String,String> saveKSFile(KingSoftFileSaveVo vo);
public byte[] uploadTempFile(String fileExtension);
} }

View File

@ -24,6 +24,7 @@ import com.chinaunicom.mall.ebtp.extend.crypconfigure.util.SslUtil;
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.shortmessage.utils.RSA;
import com.chinaunicom.mall.ebtp.extend.uniBss.UniBssUtil; import com.chinaunicom.mall.ebtp.extend.uniBss.UniBssUtil;
import com.chinaunicom.mall.ebtp.extend.wps.controller.WpsController;
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.entity.KingSoftWpsPreviewVo; import com.chinaunicom.mall.ebtp.extend.wps.entity.KingSoftWpsPreviewVo;
import com.chinaunicom.mall.ebtp.extend.wps.entity.KingSoftWpsRet; import com.chinaunicom.mall.ebtp.extend.wps.entity.KingSoftWpsRet;
@ -549,7 +550,7 @@ public class WpsServiceImpl implements WpsService {
String url = ""; String url = "";
String dataJson = ""; String dataJson = "";
String callBackUrl = ""; String callBackUrl = "";
byte[] b = getFileByFileId(in.getFileId(),in.getFileName()); byte[] b = getFileByFileId(in.getFileId(),in.getFileName(),in.getFileExtension());
String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
try { try {
callBackUrl = kswdownloadUrl+"?key="+URLEncoder.encode(getDownloadEncrypt(in.getFileId(),in.getFileExtension(),in.getUserToken()), "utf-8"); callBackUrl = kswdownloadUrl+"?key="+URLEncoder.encode(getDownloadEncrypt(in.getFileId(),in.getFileExtension(),in.getUserToken()), "utf-8");
@ -686,12 +687,12 @@ public class WpsServiceImpl implements WpsService {
@Override @Override
public byte[] getKSWpsFile(String key){ public byte[] getKSWpsFile(String key){
String fileId = downloadDecrypt(key); String fileIdName = downloadDecrypt(key);
String[] fileId = fileIdName.split("\\.");
return getFileByFileId(fileId,fileId); return getFileByFileId(fileId[0],fileIdName,fileId[1]);
} }
private byte[] getFileByFileId(String id,String fileName){ private byte[] getFileByFileId(String id,String fileName,String fileExtension){
String text = " "; String text = " ";
byte buf[] = text.getBytes(); byte buf[] = text.getBytes();
List<String> businessIdList = new ArrayList<>(); List<String> businessIdList = new ArrayList<>();
@ -712,10 +713,30 @@ public class WpsServiceImpl implements WpsService {
} }
} }
if(uploadB){ if(uploadB){
buf = uploadTempFile(fileExtension);
Optional<UploadObject> op=attachmentClient.upload(id,fileName,buf); Optional<UploadObject> op=attachmentClient.upload(id,fileName,buf);
} }
return buf; return buf;
} }
@Override
public byte[] uploadTempFile(String fileExtension){
String text = " ";
byte buf[] = text.getBytes();
File tempFile = null;
try {
tempFile = File.createTempFile("tempDoc", "."+fileExtension);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(tempFile));
buf = IOUtils.toByteArray(bis);
}catch (Exception e){
log.error("读取异常",e);
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("模板文件读取异常",true);
}finally {
if(tempFile!=null) {
tempFile.delete();
}
}
return buf;
}
@Override @Override
public Map<String,String> saveKSFile(KingSoftFileSaveVo vo){ public Map<String,String> saveKSFile(KingSoftFileSaveVo vo){