金山WPS在线编辑

This commit is contained in:
zhangqinbin
2023-10-24 15:39:27 +08:00
parent 1e96a5e7fa
commit aa5d4a6b0c
8 changed files with 375 additions and 27 deletions

View File

@ -296,12 +296,12 @@ 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 = "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/9vnXnO8X5d7xYAbM1gp5qwaQzy3fYr31UcxHiFTcZMgvN6z32FNB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qcnLULDE6P31NAkEAtSLt+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);
System.out.println("公钥加密——私钥解密---------------"); System.out.println("公钥加密——私钥解密---------------");

View File

@ -14,10 +14,15 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.PrintWriter;
@Slf4j @Slf4j
@RestController @RestController
@ -91,9 +96,8 @@ public class WpsController {
*/ */
@ApiOperation("(金山)获得编辑或查看链接") @ApiOperation("(金山)获得编辑或查看链接")
@PostMapping("/kingSoft/getWpsUrl") @PostMapping("/kingSoft/getWpsUrl")
public BaseResponse<WpsResultVo> getKSWpsUrl(WpsClientInVo in) { public BaseResponse<String> getKSWpsUrl(@RequestBody WpsClientInVo in) {
WpsResultVo str = null;//this.wpsService.getWpsUrl(in); String str = this.wpsService.getKSWpsUrl(in);
log.info("----调用天擎WPS接口---getWpsUrl-------:"+str);
return BaseResponse.success(str); return BaseResponse.success(str);
} }
/** /**
@ -104,9 +108,9 @@ public class WpsController {
* @return * @return
*/ */
@ApiOperation("(金山)沃文档回调-查询文档") @ApiOperation("(金山)沃文档回调-查询文档")
@GetMapping("/kingSoft/file/{id}") @GetMapping("/kingSoft/file")
public BaseResponse<String> getKSFile(@PathVariable String id) { public BaseResponse<byte[]> getKSFile(@RequestHeader("key") String key) {
return BaseResponse.success(this.wpsService.getKSWpsFile(id)); return BaseResponse.success(this.wpsService.getKSWpsFile(key));
} }
/** /**
* 沃文档回调-保存文档 * 沃文档回调-保存文档

View File

@ -0,0 +1,14 @@
package com.chinaunicom.mall.ebtp.extend.wps.entity;
import lombok.Data;
@Data
public class KingSoftWpsRet {
/**
* code
*/
private String code;
private String message;
private String data;
}

View File

@ -0,0 +1,60 @@
package com.chinaunicom.mall.ebtp.extend.wps.entity;
import lombok.Data;
@Data
public class KingSoftWpsVo {
/**
* 触点id 1
*/
private Integer srcId;
/**
* 当前编辑用户工号
*/
private String staffCode;
/**
* 文件唯一标识
*/
private String fileKey;
/**
* 文件名
*/
private String fillName;
/**
* 文件后缀名,如docx、pdf
*/
private String fillExtension;
/**
* 文件版本号 1
*/
private Integer version;
/**
* 文件下载URL
*/
private String downloadUrl;
/**
* 文件大小
*/
private Integer size;
/**
* 文件创建者工号
*/
private String creator;
/**
* 文件修改者工号
*/
private String modifier;
/**
* 文件创建时间;yyyy-MM-dd HH:mm:ss
*/
private String createTime;
/**
* 前端 host
*/
private String host;
/**
* 文件最近一次修改时间;yyyy-MM-dd HH:mm:ss
*/
private String lastModifiedTime;
}

View File

@ -1,15 +1,9 @@
package com.chinaunicom.mall.ebtp.extend.wps.service; package com.chinaunicom.mall.ebtp.extend.wps.service;
import com.chinaunicom.mall.ebtp.common.base.service.IBaseService;
import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLogVo;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
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.vo.WpsClientInVo; import com.chinaunicom.mall.ebtp.extend.wps.vo.WpsClientInVo;
import com.chinaunicom.mall.ebtp.extend.wps.vo.WpsResultVo; import com.chinaunicom.mall.ebtp.extend.wps.vo.WpsResultVo;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
@ -26,7 +20,9 @@ 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);
String getKSWpsFile(String id); String getKSWpsUrl(WpsClientInVo in);
byte[] getKSWpsFile(String id);
Map<String,String> saveKSFile(KingSoftFileSaveVo vo); Map<String,String> saveKSFile(KingSoftFileSaveVo vo);
} }

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,143 @@
package com.chinaunicom.mall.ebtp.extend.wps.util;
import lombok.extern.slf4j.Slf4j;
import javax.net.ssl.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Slf4j
public class HttpsUtils {
public static String httpGet(String path) {
String str = "";
try {
URL url = new URL(path);
//打开和url之间的连接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
PrintWriter out = null;
/**设置URLConnection的参数和普通的请求属性****start***/
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Accept-Encoding", "");
/**设置URLConnection的参数和普通的请求属性****end***/
conn.setDoOutput(true);
conn.setDoInput(true);
//conn.setRequestMethod("POST");//GET和POST必须全大写
/**GET方法请求*****start*/
/**
* 如果只是发送GET方式请求使用connet方法建立和远程资源之间的实际连接即可
* 如果发送POST方式的请求需要获取URLConnection实例对应的输出流来发送请求参数。
* */
conn.connect();
/**GET方法请求*****end*/
/***POST方法请求****start*/
// out = new PrintWriter(conn.getOutputStream());//获取URLConnection对象对应的输出流
//
// out.print(data);//发送请求参数即数据
//
// out.flush();//缓冲数据
/***POST方法请求****end*/
//获取URLConnection对象对应的输入流
InputStream is = conn.getInputStream();
//构造一个字符流缓存
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
while (line != null) {
str = new String(line.getBytes(), "UTF-8");//解决中文乱码问题
System.out.println(str);
line = br.readLine();
}
//关闭流
is.close();
//断开连接最好写上disconnect是在底层tcp socket链接空闲时才切断。如果正在被其他线程使用就不切断。
//固定多线程的话如果不disconnect链接会增多直到收发不出信息。写上disconnect后正常一些。
conn.disconnect();
//System.out.println("完整结束");
} catch (Exception e) {
log.error("错误信息",e);
//e.printStackTrace();
}
return str;
}
public static String httpPost(String path,String data) {
String str = "";
try {
log.info("path:"+path);
log.info("data:"+data);
URL url = new URL(path);
//打开和url之间的连接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
PrintWriter out = null;
/**设置URLConnection的参数和普通的请求属性****start***/
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Accept-Encoding", "");
/**设置URLConnection的参数和普通的请求属性****end***/
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");//GET和POST必须全大写
/**GET方法请求*****start*/
/**
* 如果只是发送GET方式请求使用connet方法建立和远程资源之间的实际连接即可
* 如果发送POST方式的请求需要获取URLConnection实例对应的输出流来发送请求参数。
* */
conn.connect();
/**GET方法请求*****end*/
/***POST方法请求****start*/
out = new PrintWriter(conn.getOutputStream());//获取URLConnection对象对应的输出流
out.print(data);//发送请求参数即数据
out.flush();//缓冲数据
/***POST方法请求****end*/
//获取URLConnection对象对应的输入流
InputStream is = conn.getInputStream();
//构造一个字符流缓存
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
while (line != null) {
str = new String(line.getBytes(), "UTF-8");//解决中文乱码问题
System.out.println(str);
line = br.readLine();
}
//关闭流
is.close();
//断开连接最好写上disconnect是在底层tcp socket链接空闲时才切断。如果正在被其他线程使用就不切断。
//固定多线程的话如果不disconnect链接会增多直到收发不出信息。写上disconnect后正常一些。
conn.disconnect();
//System.out.println("完整结束");
} catch (Exception e) {
log.error("错误信息",e);
//e.printStackTrace();
}
return str;
}
}

View File

@ -0,0 +1,28 @@
package com.chinaunicom.mall.ebtp.extend.wps.util;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MdConstants {
public static String getSha256(String str) {
try {
// 初始化MessageDigest并指定MD5算法
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(str.getBytes());
// 将字节转换为十六进制字符串
return new BigInteger(1, md.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
String originalString = "Hello, World!";
System.out.println("Original String: " + originalString);
System.out.println("SHA-256 Hash: " + MdConstants.getSha256(originalString));
}
}