34 changed files with 1639 additions and 1 deletions
@ -1,3 +1,6 @@
|
||||
# open-JSD-7339 |
||||
|
||||
JSD-7339 开源任务材料 |
||||
JSD-7339 开源任务代码\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.fr.plugin.7339.wps</id> |
||||
<name><![CDATA[WPS接入]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.0</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2020-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[]]></description> |
||||
<change-notes><![CDATA[ |
||||
]]></change-notes> |
||||
<extra-decision> |
||||
<!-- 长连接 --> |
||||
<HttpHandlerProvider class="com.fr.plugin.WPSHandlerProvider"/> |
||||
<!-- 短连接 --> |
||||
<URLAliasProvider class="com.fr.plugin.WPSURLAliasBridge"/> |
||||
</extra-decision> |
||||
<function-recorder class="com.fr.plugin.WPSHandlerProvider"/> |
||||
</plugin> |
@ -0,0 +1,103 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import javax.crypto.Mac; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.net.URLEncoder; |
||||
import java.security.InvalidKeyException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.*; |
||||
|
||||
import static org.apache.tomcat.util.codec.binary.Base64.encodeBase64String; |
||||
|
||||
public class Signature { |
||||
|
||||
public static boolean checkSig(HttpServletRequest request, String sign) throws UnsupportedEncodingException { |
||||
Map<String, String> paramMap = new HashMap<>(); |
||||
WPSConfig wpsConfig = WPSConfig.getInstance(); |
||||
Enumeration<String> parameterNames = request.getParameterNames(); |
||||
while (parameterNames.hasMoreElements()) { |
||||
String name = parameterNames.nextElement(); |
||||
if (name.startsWith("_w_") && !name.equals("_w_signature")) { |
||||
paramMap.put(name, request.getParameter(name)); |
||||
} |
||||
} |
||||
String signature = getSignature(paramMap, wpsConfig.getAppKey(),false); |
||||
return sign.equals(signature); |
||||
} |
||||
|
||||
public static String getSign(String name) throws UnsupportedEncodingException { |
||||
Map<String, String> paramMap = new HashMap<>(); |
||||
WPSConfig wpsConfig = WPSConfig.getInstance(); |
||||
paramMap.put("_w_appid", wpsConfig.getAppid()); |
||||
paramMap.put("_w_userid", name); |
||||
paramMap.put("_w_tokentype", "1"); |
||||
return getSignature(paramMap, wpsConfig.getAppKey(),true); |
||||
} |
||||
|
||||
private static String getUrlParam(Map<String, String> params) throws UnsupportedEncodingException { |
||||
StringBuilder builder = new StringBuilder(); |
||||
for (Map.Entry<String, String> entry : params.entrySet()) { |
||||
if (builder.length() > 0) { |
||||
builder.append('&'); |
||||
} |
||||
builder.append(URLEncoder.encode(entry.getKey(), "utf-8")).append('=').append(URLEncoder.encode(entry.getValue(), "utf-8")); |
||||
} |
||||
return builder.toString(); |
||||
} |
||||
|
||||
private static String getSignature(Map<String, String> params, String appSecret, boolean needEncode) { |
||||
List<String> keys = new ArrayList(); |
||||
for (Map.Entry<String, String> entry : params.entrySet()) { |
||||
keys.add(entry.getKey()); |
||||
} |
||||
|
||||
// 将所有参数按 key 的升序排序
|
||||
Collections.sort(keys, new Comparator<String>() { |
||||
public int compare(String o1, String o2) { |
||||
return o1.compareTo(o2); |
||||
} |
||||
}); |
||||
|
||||
// 构造签名的源字符串
|
||||
StringBuilder contents = new StringBuilder(""); |
||||
for (String key : keys) { |
||||
if (key == "_w_signature") { |
||||
continue; |
||||
} |
||||
contents.append(key + "=").append(params.get(key)); |
||||
System.out.println("key:" + key + ",value:" + params.get(key)); |
||||
} |
||||
contents.append("_w_secretkey=").append(appSecret); |
||||
|
||||
// 进行 hmac sha1 签名
|
||||
byte[] bytes = hmacSha1(appSecret.getBytes(), contents.toString().getBytes()); |
||||
// 字符串经过 Base64 编码
|
||||
String sign = encodeBase64String(bytes); |
||||
if (needEncode) { |
||||
try { |
||||
sign = URLEncoder.encode(sign, "UTF-8"); |
||||
} catch (UnsupportedEncodingException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return sign; |
||||
} |
||||
return sign; |
||||
} |
||||
|
||||
public static byte[] hmacSha1(byte[] key, byte[] data) { |
||||
try { |
||||
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1"); |
||||
Mac mac = Mac.getInstance(signingKey.getAlgorithm()); |
||||
mac.init(signingKey); |
||||
return mac.doFinal(data); |
||||
} catch (NoSuchAlgorithmException e) { |
||||
e.printStackTrace(); |
||||
} catch (InvalidKeyException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,82 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
|
||||
@Visualization(category = "WPS配置") |
||||
public class WPSConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile WPSConfig config = null; |
||||
|
||||
public static WPSConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(WPSConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "appKey", name = "appkey", description = "", status = Status.SHOW) |
||||
private Conf<String> appKey = Holders.simple("313a380c67bb491ca11fb47bffd3ba28"); |
||||
@Identifier(value = "appid", name = "Appid", description = "", status = Status.SHOW) |
||||
private Conf<String> appid = Holders.simple("98d8ac1a058c4fb4b32478c0d2319dff"); |
||||
|
||||
@Identifier(value = "appsecret", name = "数据连接名", description = "", status = Status.SHOW) |
||||
private Conf<String> appsecret = Holders.simple("JNSaaSFinAuditGuoJin"); |
||||
@Identifier(value = "domainName", name = "文件表名", description = "", status = Status.SHOW) |
||||
private Conf<String> domainName = Holders.simple("PD_File_Catalog"); |
||||
|
||||
@Identifier(value = "frHost", name = "当前fr的地址", description = "", status = Status.HIDE) |
||||
private Conf<String> frHost = Holders.simple("https://zzliap.ngrok2.xiaomiqiu.cn/webroot/decision"); |
||||
|
||||
public String getFrHost() { |
||||
return frHost.get(); |
||||
} |
||||
|
||||
public void setFrHost( String frHost) { |
||||
this.frHost .set(frHost); |
||||
} |
||||
|
||||
public String getAppid() { |
||||
return appid.get(); |
||||
} |
||||
|
||||
public void setAppid(String appid) { |
||||
this.appid.set(appid); |
||||
} |
||||
|
||||
public String getAppKey() { |
||||
return appKey.get(); |
||||
} |
||||
|
||||
public void setAppKey(String appKey) { |
||||
this.appKey.set(appKey); |
||||
} |
||||
|
||||
public String getAppsecret() { |
||||
return appsecret.get(); |
||||
} |
||||
|
||||
public void setAppsecret(String appsecret) { |
||||
this.appsecret.set(appsecret); |
||||
} |
||||
|
||||
public String getDomainName() { |
||||
return domainName.get(); |
||||
} |
||||
|
||||
public void setDomainName(String domainName) { |
||||
this.domainName.set(domainName); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
WPSConfig clone = (WPSConfig) super.clone(); |
||||
clone.appKey = (Conf<String>) this.appKey.clone(); |
||||
clone.appsecret = (Conf<String>) this.appKey.clone(); |
||||
clone.domainName = (Conf<String>) this.appKey.clone(); |
||||
clone.appid = (Conf<String>) this.appid.clone(); |
||||
clone.frHost = (Conf<String>) this.frHost.clone(); |
||||
return clone; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
import com.fr.plugin.api.*; |
||||
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
|
||||
@FunctionRecorder |
||||
/** |
||||
* url处理器需要在这里注册 |
||||
*/ |
||||
public class WPSHandlerProvider extends AbstractHttpHandlerProvider { |
||||
|
||||
public WPSHandlerProvider() { |
||||
WPSConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
@ExecuteFunctionRecord |
||||
public HttpHandler[] registerHandlers() { |
||||
return new HttpHandler[]{ |
||||
new DownloadApi(), |
||||
new FileHistoryApi(), |
||||
new FileInfoApi(), |
||||
new EditorApi(), |
||||
new FileRenameApi(), |
||||
new FileSaveApi(), |
||||
new FileVersionApi(), |
||||
new NotifyApi(), |
||||
new OnlineApi(), |
||||
new UserInfoApi(), |
||||
}; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||
import com.fr.decision.webservice.url.alias.URLAlias; |
||||
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||
|
||||
/** |
||||
* 将长连接转换为短连接 |
||||
* 参考文档: |
||||
* https://wiki.fanruan.com/display/PD/com.fr.decision.fun.URLAliasProvider
|
||||
*/ |
||||
public class WPSURLAliasBridge extends AbstractURLAliasProvider |
||||
{ |
||||
|
||||
@Override |
||||
public URLAlias[] registerAlias() { |
||||
//像这样配置之后再访问/api就可以通过http(s)://ip:port/webroot/decision/url/api。 进行访问
|
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/file/info", "/v1/3rd/file/info", true), |
||||
URLAliasFactory.createPluginAlias("/editorWps", "/editorWps", true), |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/user/info", "/v1/3rd/user/info", true), |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/file/save", "/v1/3rd/file/save", true), |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/file/online", "/v1/3rd/file/online", true), |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/file/version/:version", "/v1/3rd/file/version/:version", true), |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/file/rename", "/v1/3rd/file/rename", true), |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/file/history", "/v1/3rd/file/history", true), |
||||
URLAliasFactory.createPluginAlias("/v1/3rd/onnotify", "/v1/3rd/onnotify", true), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,71 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.plugin.WPSConfig; |
||||
import com.fr.plugin.models.GetFileModel; |
||||
import com.fr.plugin.utils.DbUtils; |
||||
import com.fr.plugin.utils.ErrorUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.ServletOutputStream; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedOutputStream; |
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.io.OutputStream; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
|
||||
public class DownloadApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/file/info/fileDownload"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
String fileId = WebUtils.getHTTPRequestParameter(request, "fileId"); |
||||
WPSConfig instance = WPSConfig.getInstance(); |
||||
DbUtils db = new DbUtils(instance.getAppsecret()); |
||||
List<Map<String, String>> list = db.exQuery("select * from " + instance.getDomainName() + " where File_Id =?", fileId); |
||||
if (list.isEmpty()) { |
||||
WebUtils.printAsJSON(response, ErrorUtils.createError(101,"文件不存在","请联系管理员")); |
||||
return; |
||||
} |
||||
Map<String, String> map = list.get(0); |
||||
String fileUrl = map.get("File_Url"); |
||||
String fileName = map.get("File_name"); |
||||
if (StringUtils.isEmpty(fileUrl)) { |
||||
WebUtils.printAsJSON(response, ErrorUtils.createError(101,"文件保存路径不存在","请联系管理员")); |
||||
return; |
||||
} |
||||
String filePath = fileUrl + fileName; |
||||
File file = new File(filePath); |
||||
if (!file.exists()) { |
||||
WebUtils.printAsJSON(response, ErrorUtils.createError(101,"文件已经被删除","请联系管理员")); |
||||
return; |
||||
} |
||||
response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes())); |
||||
response.addHeader("Content-Length", "" + file.length()); |
||||
OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); |
||||
response.setContentType("application/octet-stream"); |
||||
IOUtils.copyBinaryTo(new FileInputStream(file),toClient); |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.plugin.Signature; |
||||
import com.fr.plugin.WPSConfig; |
||||
import com.fr.plugin.utils.HttpUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
|
||||
public class EditorApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/editorWps"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
String fileId = WebUtils.getHTTPRequestParameter(request, "fileId"); |
||||
String userName = WebUtils.getHTTPRequestParameter(request, "userName"); |
||||
String fileType = WebUtils.getHTTPRequestParameter(request, "fileType"); |
||||
String sign = Signature.getSign(userName); |
||||
Map<String, String> param = new HashMap<>(); |
||||
param.put("fileId", fileId); |
||||
param.put("userName", userName); |
||||
param.put("xSign", sign); |
||||
param.put("appId", WPSConfig.getInstance().getAppid()); |
||||
param.put("fileType", fileType); |
||||
param.put("jsToken", HttpUtils.genToken()); |
||||
WebUtils.writeOutTemplate("/com/fr/plugin/wps.html", httpServletResponse, param); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.plugin.utils.ErrorUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
|
||||
public class FileHistoryApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/file/history"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101,"暂时不支持","请联系管理员")); |
||||
} |
||||
} |
@ -0,0 +1,98 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.plugin.Signature; |
||||
import com.fr.plugin.WPSConfig; |
||||
import com.fr.plugin.models.*; |
||||
import com.fr.plugin.utils.DbUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
import com.fr.plugin.utils.*; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.File; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
|
||||
public class FileInfoApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/file/info"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
WPSConfig instance = WPSConfig.getInstance(); |
||||
String token = request.getHeader("x-wps-weboffice-token"); |
||||
String fileId = request.getHeader("x-weboffice-file-id"); |
||||
String wSignature = WebUtils.getHTTPRequestParameter(request, "_w_signature"); |
||||
String userid = WebUtils.getHTTPRequestParameter(request, "_w_userid"); |
||||
if (!Signature.checkSig(request,wSignature)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(40005,"签名错误","请联系管理员")); |
||||
return; |
||||
} |
||||
if (!HttpUtils.checkToken(token)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(40002, "token过期", "请联系管理员")); |
||||
return; |
||||
} |
||||
if (StringUtils.isNotBlank(fileId)) { |
||||
DbUtils db = new DbUtils(instance.getAppsecret()); |
||||
GetFileModel getFileModel = new GetFileModel(); |
||||
List<Map<String, String>> list = db.exQuery("select * from " + instance.getDomainName() + " where File_Id =?", fileId); |
||||
if (list.isEmpty()) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(40004,"文件不存在","请联系管理员")); |
||||
return; |
||||
} |
||||
Map<String, String> map = list.get(0); |
||||
String fileUrl = map.get("File_Url"); |
||||
String fileName = map.get("File_name"); |
||||
String creater = map.get("Fill_Name"); |
||||
if (StringUtils.isEmpty(fileUrl)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(40004,"文件保存路径不存在","请联系管理员")); |
||||
return; |
||||
} |
||||
String filePath = fileUrl + fileName; |
||||
File file = new File(filePath); |
||||
if (!file.exists()) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(40004,"文件已经被删除","请联系管理员")); |
||||
return; |
||||
} |
||||
FileModel model = new FileModel(); |
||||
model.setId(fileId); |
||||
model.setSize(file.length()); |
||||
model.setDownload_url(request,fileId); |
||||
model.setName(map.get("File_name")); |
||||
UserService userService = UserService.getInstance(); |
||||
User createUser = userService.getUserByUserName(creater); |
||||
if (createUser == null) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(50001,"用户不存在","请联系管理员")); |
||||
return; |
||||
} |
||||
UserModel userModel = new UserModel(); |
||||
userModel.setName(createUser.getRealName()); |
||||
userModel.setId(creater); |
||||
getFileModel.setFile(model); |
||||
getFileModel.setUser(userModel); |
||||
WebUtils.printAsString(httpServletResponse, HttpUtils.obj2JsonStr(getFileModel)); |
||||
}else{ |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(40004,"文件id不存在","请联系管理员")); |
||||
return; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.plugin.utils.ErrorUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
|
||||
public class FileRenameApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/file/rename"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "暂不支持重命名", "请联系管理员")); |
||||
return; |
||||
} |
||||
} |
@ -0,0 +1,121 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.base.core.IgnoreBytesInputStream; |
||||
import com.fr.base.core.ParseResult; |
||||
import com.fr.base.core.PostParseUtils; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.Signature; |
||||
import com.fr.plugin.WPSConfig; |
||||
import com.fr.plugin.models.UploadFileModel; |
||||
import com.fr.plugin.models.UploadFileWarpModel; |
||||
import com.fr.plugin.utils.DbUtils; |
||||
import com.fr.plugin.utils.ErrorUtils; |
||||
import com.fr.plugin.utils.HttpUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.InputStream; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
|
||||
public class FileSaveApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/file/save"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest req, HttpServletResponse httpServletResponse) throws Exception { |
||||
WPSConfig instance = WPSConfig.getInstance(); |
||||
InputStream inputStream = req.getInputStream(); |
||||
FineLoggerFactory.getLogger().info("访问文件保存接口"); |
||||
try { |
||||
String token = req.getHeader("x-wps-weboffice-token"); |
||||
String fileId = req.getHeader("x-weboffice-file-id"); |
||||
String wSignature = WebUtils.getHTTPRequestParameter(req, "_w_signature"); |
||||
if (!Signature.checkSig(req, wSignature)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "签名错误", "请联系管理员")); |
||||
return; |
||||
} |
||||
if (!HttpUtils.checkToken(token)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "token过期", "请联系管理员")); |
||||
return; |
||||
} |
||||
if (StringUtils.isNotBlank(fileId)) { |
||||
DbUtils db = new DbUtils(instance.getAppsecret()); |
||||
List<Map<String, String>> list = db.exQuery("select * from " + instance.getDomainName() + " where File_Id =?", fileId); |
||||
if (list.isEmpty()) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "保存的文件不存在", "请联系管理员")); |
||||
return; |
||||
} |
||||
Map<String, String> map = list.get(0); |
||||
String fileUrl = map.get("File_Url"); |
||||
String fileName = map.get("File_name"); |
||||
if (StringUtils.isEmpty(fileUrl)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "保存的文件保存路径不存在", "请联系管理员")); |
||||
return; |
||||
} |
||||
String filePath = fileUrl + fileName; |
||||
File file = new File(filePath); |
||||
if (!file.exists()) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "保存的文件已经被删除", "请联系管理员")); |
||||
return; |
||||
} |
||||
ParseResult parseResult = PostParseUtils.parse(inputStream, req.getCharacterEncoding()); |
||||
InputStream fileDecorator = new IgnoreBytesInputStream(inputStream, concat(this.concat(NEW_LINE_BYTES, parseResult.getBoundary().getBytes()), BOUNDARY_END)); |
||||
IOUtils.copyBinaryTo(fileDecorator, new FileOutputStream(file)); |
||||
UploadFileWarpModel uploadFileWarpModel = new UploadFileWarpModel(); |
||||
UploadFileModel uploadFileModel = new UploadFileModel(); |
||||
uploadFileModel.setId(fileId); |
||||
uploadFileModel.setDownload_url(fileId); |
||||
uploadFileModel.setName(fileName); |
||||
uploadFileModel.setSize(file.length()); |
||||
uploadFileWarpModel.setFile(uploadFileModel); |
||||
WebUtils.printAsString(httpServletResponse, HttpUtils.obj2JsonStr(uploadFileWarpModel)); |
||||
FineLoggerFactory.getLogger().info("文件保存成功 文件名:{}", fileName); |
||||
return; |
||||
} else { |
||||
FineLoggerFactory.getLogger().info("文件保存失败 "); |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "要保存的文件不存在或找不到", "请联系管理员")); |
||||
return; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error("文件保存异常 ",e); |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "文件保存异常", "请联系管理员")); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
private byte[] concat(byte[] a, byte[] b) { |
||||
byte[] c = new byte[a.length + b.length]; |
||||
System.arraycopy(a, 0, c, 0, a.length); |
||||
System.arraycopy(b, 0, c, a.length, b.length); |
||||
return c; |
||||
} |
||||
|
||||
private static final int MAX_IMAGE_SIZE = 20971520;//20MB
|
||||
public static final String BASE64_DATA = "base64Data"; |
||||
private static final byte[] NEW_LINE_BYTES = new byte[]{13, 10}; |
||||
private static final byte[] BOUNDARY_END = new byte[]{45, 45}; |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.plugin.utils.ErrorUtils; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
|
||||
public class FileVersionApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/file/version/:version"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "暂未支持", "请联系管理员")); |
||||
return; |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
|
||||
public class NotifyApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/onnotify"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
|
||||
public class OnlineApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/file/online"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,82 @@
|
||||
package com.fr.plugin.api; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.plugin.Signature; |
||||
import com.fr.plugin.models.GetUserModel; |
||||
import com.fr.plugin.models.UserModel; |
||||
import com.fr.plugin.utils.ErrorUtils; |
||||
import com.fr.plugin.utils.HttpUtils; |
||||
import com.fr.report.core.utils.WebUnit; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.jodd.util.StringUtil; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
import org.json.JSONArray; |
||||
import org.json.JSONObject; |
||||
|
||||
import javax.servlet.ServletInputStream; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.ArrayList; |
||||
|
||||
|
||||
public class UserInfoApi extends BaseHttpHandler { |
||||
|
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/v1/3rd/user/info"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception { |
||||
String token = request.getHeader("x-wps-weboffice-token"); |
||||
String wSignature = WebUtils.getHTTPRequestParameter(request, "_w_signature"); |
||||
if (!Signature.checkSig(request,wSignature)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101,"签名错误","请联系管理员")); |
||||
return; |
||||
} |
||||
if (!HttpUtils.checkToken(token)) { |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101, "token过期", "请联系管理员")); |
||||
return; |
||||
} |
||||
ServletInputStream inputStream = request.getInputStream(); |
||||
String body = HttpUtils.inputStream2String(inputStream); |
||||
if (StringUtils.isNotBlank(body)) { |
||||
JSONObject jsonObject = new JSONObject(body); |
||||
JSONArray ids = jsonObject.getJSONArray("ids"); |
||||
int length = ids.length(); |
||||
UserService userService = UserService.getInstance(); |
||||
ArrayList<UserModel> userModels = new ArrayList<UserModel>(); |
||||
for (int i = 0; i < length; i++) { |
||||
String userName = ids.getString(i); |
||||
if (StringUtils.isNotBlank(userName)) { |
||||
User user = userService.getUserByUserName(userName); |
||||
UserModel userModel = new UserModel(); |
||||
userModel.setId(userName); |
||||
userModel.setName(user.getRealName()); |
||||
userModels.add(userModel); |
||||
} |
||||
} |
||||
GetUserModel getUserModel = new GetUserModel(); |
||||
getUserModel.setUsers(userModels); |
||||
WebUtils.printAsString(httpServletResponse, HttpUtils.obj2JsonStr(getUserModel)); |
||||
return; |
||||
}else{ |
||||
WebUtils.printAsJSON(httpServletResponse, ErrorUtils.createError(101,"请求参数中没有信息","请联系管理员")); |
||||
return; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,111 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* id: "132aa30a87064", //文件id,字符串长度小于32
|
||||
* name: "example.doc", //文件名(必须带文件后缀)
|
||||
* version: 1, //当前版本号,位数小于11
|
||||
* size: 200, //文件大小,单位为B(文件真实大小,否则会出现异常)
|
||||
* creator: "id0", //创建者id,字符串长度小于32
|
||||
* create_time: 1136185445. //创建时间,时间戳,单位为秒
|
||||
* modifier: "id1000", //修改者id,字符串长度小于32
|
||||
* modify_time: 1551409818, //修改时间,时间戳,单位为秒
|
||||
* download_url: "http://www.xxx.cn/v1/file?fid=f132aa30a87064", //文档下载地址
|
||||
* preview_pages: 3 //限制预览页数
|
||||
*/ |
||||
public class FileModel implements Serializable { |
||||
private String id; |
||||
private String name; |
||||
private int version; |
||||
private long size; |
||||
private String modifier; |
||||
private String modify_time; |
||||
private String download_url; |
||||
private int preview_pages = 0; |
||||
private UserAclModel user_acl; |
||||
private WatermarkModel watermark; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public int getVersion() { |
||||
return version; |
||||
} |
||||
|
||||
public void setVersion(int version) { |
||||
this.version = version; |
||||
} |
||||
|
||||
public long getSize() { |
||||
return size; |
||||
} |
||||
|
||||
public void setSize(long size) { |
||||
this.size = size; |
||||
} |
||||
|
||||
public String getModifier() { |
||||
return modifier; |
||||
} |
||||
|
||||
public void setModifier(String modifier) { |
||||
this.modifier = modifier; |
||||
} |
||||
|
||||
public String getModify_time() { |
||||
return modify_time; |
||||
} |
||||
|
||||
public void setModify_time(String modify_time) { |
||||
this.modify_time = modify_time; |
||||
} |
||||
|
||||
public String getDownload_url() { |
||||
return download_url; |
||||
} |
||||
|
||||
public void setDownload_url(HttpServletRequest request, String id) { |
||||
StringBuffer requestURL = request.getRequestURL(); |
||||
this.download_url = requestURL.append("/fileDownload?fileId=").append(id).toString(); |
||||
} |
||||
|
||||
public int getPreview_pages() { |
||||
return preview_pages; |
||||
} |
||||
|
||||
public void setPreview_pages(int preview_pages) { |
||||
this.preview_pages = preview_pages; |
||||
} |
||||
|
||||
public UserAclModel getUser_acl() { |
||||
return user_acl; |
||||
} |
||||
|
||||
public void setUser_acl(UserAclModel user_acl) { |
||||
this.user_acl = user_acl; |
||||
} |
||||
|
||||
public WatermarkModel getWatermark() { |
||||
return watermark; |
||||
} |
||||
|
||||
public void setWatermark(WatermarkModel watermark) { |
||||
this.watermark = watermark; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
public class GetFileModel implements Serializable { |
||||
private FileModel file; |
||||
private UserModel user; |
||||
|
||||
public FileModel getFile() { |
||||
return file; |
||||
} |
||||
|
||||
public void setFile(FileModel file) { |
||||
this.file = file; |
||||
} |
||||
|
||||
public UserModel getUser() { |
||||
return user; |
||||
} |
||||
|
||||
public void setUser(UserModel user) { |
||||
this.user = user; |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
public class GetUserModel implements Serializable { |
||||
private List<UserModel> users; |
||||
|
||||
public List<UserModel> getUsers() { |
||||
return users; |
||||
} |
||||
|
||||
public void setUsers(List<UserModel> users) { |
||||
this.users = users; |
||||
} |
||||
} |
@ -0,0 +1,70 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
{ |
||||
file: { |
||||
id: "f132aa30a87064", // 文件 id,字符串长度小于 40
|
||||
name: "example.doc", // 文件名
|
||||
version: 2, // 当前版本号,位数小于 11
|
||||
size: 200, //文件大小,单位是 B
|
||||
download_url: "http://www.xxx.cn/v1/file?fid=f132aa30a87064" // 文件下载地址
|
||||
} |
||||
} |
||||
*/ |
||||
public class UploadFileModel implements Serializable { |
||||
private String id; |
||||
private String name; |
||||
private int version=0; |
||||
private long size; |
||||
private String download_url; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public int getVersion() { |
||||
return version; |
||||
} |
||||
|
||||
public void setVersion(int version) { |
||||
this.version = version; |
||||
} |
||||
|
||||
public long getSize() { |
||||
return size; |
||||
} |
||||
|
||||
public void setSize(long size) { |
||||
this.size = size; |
||||
} |
||||
|
||||
public String getDownload_url() { |
||||
return download_url; |
||||
} |
||||
|
||||
public void setDownload_url(String download_url) { |
||||
this.download_url = download_url; |
||||
} |
||||
|
||||
public void setDownload_url(HttpServletRequest request, String id) { |
||||
StringBuffer requestURL = request.getRequestURL(); |
||||
this.download_url = requestURL.append("/url/fileDownload?fileId").append(id).toString(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* { |
||||
* file: { |
||||
* id: "f132aa30a87064", // 文件 id,字符串长度小于 40
|
||||
* name: "example.doc", // 文件名
|
||||
* version: 2, // 当前版本号,位数小于 11
|
||||
* size: 200, //文件大小,单位是 B
|
||||
* download_url: "http://www.xxx.cn/v1/file?fid=f132aa30a87064" // 文件下载地址
|
||||
* } |
||||
* } |
||||
*/ |
||||
public class UploadFileWarpModel implements Serializable { |
||||
private UploadFileModel file; |
||||
|
||||
public UploadFileModel getFile() { |
||||
return file; |
||||
} |
||||
|
||||
public void setFile(UploadFileModel file) { |
||||
this.file = file; |
||||
} |
||||
} |
@ -0,0 +1,56 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
/** |
||||
* rename: 1, //重命名权限,1为打开该权限,0为关闭该权限,默认为0
|
||||
* history: 1, //历史版本权限,1为打开该权限,0为关闭该权限,默认为1
|
||||
* copy: 1, //复制
|
||||
* export: 1, //导出PDF
|
||||
* print: 1 //打印
|
||||
*/ |
||||
public class UserAclModel { |
||||
private int rename; |
||||
private int history; |
||||
private int copy; |
||||
private int export; |
||||
private int print; |
||||
|
||||
public int getRename() { |
||||
return rename; |
||||
} |
||||
|
||||
public void setRename(int rename) { |
||||
this.rename = rename; |
||||
} |
||||
|
||||
public int getHistory() { |
||||
return history; |
||||
} |
||||
|
||||
public void setHistory(int history) { |
||||
this.history = history; |
||||
} |
||||
|
||||
public int getCopy() { |
||||
return copy; |
||||
} |
||||
|
||||
public void setCopy(int copy) { |
||||
this.copy = copy; |
||||
} |
||||
|
||||
public int getExport() { |
||||
return export; |
||||
} |
||||
|
||||
public void setExport(int export) { |
||||
this.export = export; |
||||
} |
||||
|
||||
public int getPrint() { |
||||
return print; |
||||
} |
||||
|
||||
public void setPrint(int print) { |
||||
this.print = print; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
public class UserModel implements Serializable { |
||||
private String id; |
||||
private String name; |
||||
private String permission="write"; |
||||
private String avatar_url; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getPermission() { |
||||
return permission; |
||||
} |
||||
|
||||
public void setPermission(String permission) { |
||||
this.permission = permission; |
||||
} |
||||
|
||||
public String getAvatar_url() { |
||||
return avatar_url; |
||||
} |
||||
|
||||
public void setAvatar_url(String avatar_url) { |
||||
this.avatar_url = avatar_url; |
||||
} |
||||
} |
@ -0,0 +1,67 @@
|
||||
package com.fr.plugin.models; |
||||
|
||||
/** |
||||
* type: 1, //水印类型, 0为无水印; 1为文字水印
|
||||
* value: "禁止传阅", //文字水印的文字,当type为1时此字段必选
|
||||
* fillstyle: "rgba( 192, 192, 192, 0.6 )", //水印的透明度,非必选,有默认值
|
||||
* font: "bold 20px Serif", //水印的字体,非必选,有默认值
|
||||
* rotate: -0.7853982, //水印的旋转度,非必选,有默认值
|
||||
* horizontal: 50, //水印水平间距,非必选,有默认值
|
||||
* vertical: 100 //水印垂直间距,非必选,有默认值
|
||||
*/ |
||||
public class WatermarkModel { |
||||
private int type = 0; |
||||
private String value; |
||||
private String font; |
||||
private Double rotate; |
||||
private int horizontal = 0; |
||||
private int vertical = 0; |
||||
|
||||
public int getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(int type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
public void setValue(String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
public String getFont() { |
||||
return font; |
||||
} |
||||
|
||||
public void setFont(String font) { |
||||
this.font = font; |
||||
} |
||||
|
||||
public Double getRotate() { |
||||
return rotate; |
||||
} |
||||
|
||||
public void setRotate(Double rotate) { |
||||
this.rotate = rotate; |
||||
} |
||||
|
||||
public int getHorizontal() { |
||||
return horizontal; |
||||
} |
||||
|
||||
public void setHorizontal(int horizontal) { |
||||
this.horizontal = horizontal; |
||||
} |
||||
|
||||
public int getVertical() { |
||||
return vertical; |
||||
} |
||||
|
||||
public void setVertical(int vertical) { |
||||
this.vertical = vertical; |
||||
} |
||||
} |
@ -0,0 +1,151 @@
|
||||
package com.fr.plugin.utils; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.file.ConnectionConfig; |
||||
import com.fr.file.DatasourceManager; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.log.FineLoggerProvider; |
||||
|
||||
import java.sql.*; |
||||
import java.util.*; |
||||
|
||||
public class DbUtils { |
||||
String db_name = ""; |
||||
|
||||
FineLoggerProvider logger = FineLoggerFactory.getLogger(); |
||||
|
||||
|
||||
public DbUtils(String db_name) { |
||||
this.db_name = db_name; |
||||
} |
||||
|
||||
public com.fr.data.impl.Connection getDbConnect() { |
||||
return ConnectionConfig.getInstance().getConnection(db_name); |
||||
} |
||||
|
||||
public List<Map<String, Object>> select(String sql, Object... params) { |
||||
logger.info("query data by sql:" + sql + Arrays.toString(params)); |
||||
try { |
||||
com.fr.data.impl.Connection dbConnect = getDbConnect(); |
||||
|
||||
Connection con = dbConnect.createConnection(); |
||||
PreparedStatement preparedStatement = con.prepareStatement(sql); |
||||
setParams(preparedStatement, params); |
||||
ResultSet rs = preparedStatement.executeQuery(sql); |
||||
// 获得记录的详细信息,然后获得总列数
|
||||
ResultSetMetaData resMetaData = rs.getMetaData(); |
||||
int colNum = resMetaData.getColumnCount(); |
||||
// 用对象保存数据
|
||||
String name = ""; |
||||
String value = ""; |
||||
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); |
||||
while (rs.next()) { |
||||
Map<String, Object> cells = new HashMap<String, Object>(); |
||||
for (int i = 0; i < colNum; i++) { |
||||
name = resMetaData.getColumnLabel(i); |
||||
if (cells.get(name) != null) { |
||||
name = resMetaData.getColumnLabel(i); |
||||
} |
||||
if (rs.getObject(i) != null && resMetaData.getColumnTypeName(i).equals("DATETIME") || resMetaData.getColumnTypeName(i).equals("TIMESTAMP")) { |
||||
value = rs.getObject(i).toString(); |
||||
cells.put(name, value.substring(0, value.length() - 2)); |
||||
} else { |
||||
cells.put(name, rs.getString(i)); |
||||
} |
||||
} |
||||
list.add(cells); |
||||
} |
||||
// 释放数据库资源
|
||||
rs.close(); |
||||
preparedStatement.close(); |
||||
con.close(); |
||||
return list; |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public Map<String, Object> findOneRow(String sql, Object... params) { |
||||
List<Map<String, Object>> select = select(sql, params); |
||||
if (select != null) { |
||||
if (!select.isEmpty()) { |
||||
return select.get(0); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public boolean checkExist(String sql, Object... params) throws Exception { |
||||
PreparedStatement pstmt = getDbConnect().createConnection().prepareStatement(sql); |
||||
setParams(pstmt, params); |
||||
ResultSet resultSet = pstmt.executeQuery(); |
||||
if (resultSet.next()) { |
||||
return resultSet.getInt(1) > 0; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
private void setParams(PreparedStatement pstmt, Object... params) throws SQLException { |
||||
if (params.length > 0) { |
||||
int length = params.length; |
||||
for (int i = 1; i <= length; i++) { |
||||
pstmt.setObject(i, params[i - 1]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public int exSqlUpdate(String sql, Object... params) throws Exception { |
||||
logger.info("update data by sql:" + sql + " params " + Arrays.toString(params)); |
||||
com.fr.data.impl.Connection dbConnect = getDbConnect(); |
||||
Connection connection = dbConnect.createConnection(); |
||||
PreparedStatement pstmt = connection.prepareStatement(sql); |
||||
setParams(pstmt, params); |
||||
int i = pstmt.executeUpdate(); |
||||
pstmt.close(); |
||||
connection.close(); |
||||
return i; |
||||
} |
||||
|
||||
/** |
||||
* 取查询结果集字段 |
||||
* @param sql |
||||
* @param params |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public List<Map<String,String>> exQuery(String sql, Object... params) throws Exception { |
||||
logger.info("query data by sql:" + sql + " params " + Arrays.toString(params)); |
||||
com.fr.data.impl.Connection dbConnect = getDbConnect(); |
||||
Connection connection = dbConnect.createConnection(); |
||||
PreparedStatement pstmt = connection.prepareStatement(sql); |
||||
setParams(pstmt, params); |
||||
ResultSet resultSet = pstmt.executeQuery(); |
||||
ResultSetMetaData resMetaData = resultSet.getMetaData(); |
||||
int columnCount = resMetaData.getColumnCount(); |
||||
List<Map<String,String>> arrs=new ArrayList<Map<String,String>>(); |
||||
while (resultSet.next()) { |
||||
String name; |
||||
String value; |
||||
Map<String, String> one = new HashMap<String, String>(); |
||||
for (int i = 1; i <= columnCount; i++) { |
||||
name = resMetaData.getColumnLabel(i); |
||||
if (one.get(name) != null) { |
||||
name = resMetaData.getColumnLabel(i); |
||||
} |
||||
if (resultSet.getObject(i) != null && resMetaData.getColumnTypeName(i).equals("DATETIME") || resMetaData.getColumnTypeName(i).equals("TIMESTAMP")) { |
||||
value = resultSet.getObject(i).toString(); |
||||
one.put(name, value.substring(0, value.length() - 2)); |
||||
} else { |
||||
one.put(name, resultSet.getString(i)); |
||||
} |
||||
} |
||||
arrs.add(one); |
||||
} |
||||
|
||||
pstmt.close(); |
||||
connection.close(); |
||||
logger.info("查询结果:"+arrs); |
||||
return arrs; |
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.fr.plugin.utils; |
||||
|
||||
|
||||
import com.fr.json.JSONObject; |
||||
|
||||
public class ErrorUtils { |
||||
public static JSONObject createError(int code, String message, String details) { |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("code", code); |
||||
jsonObject.put("message", message); |
||||
jsonObject.put("details", details); |
||||
jsonObject.put("hint", ""); |
||||
return jsonObject; |
||||
} |
||||
} |
@ -0,0 +1,140 @@
|
||||
package com.fr.plugin.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.fasterxml.jackson.core.JsonProcessingException; |
||||
import com.fr.third.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
import com.fr.third.org.apache.commons.io.IOUtils; |
||||
|
||||
import javax.net.ssl.*; |
||||
import java.io.*; |
||||
import java.net.URL; |
||||
import java.nio.charset.Charset; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.time.LocalDate; |
||||
|
||||
public class HttpUtils { |
||||
public static String inputStream2String(InputStream inputStream) { |
||||
StringBuilder sb = new StringBuilder(); |
||||
BufferedReader reader = null; |
||||
|
||||
try { |
||||
reader = new BufferedReader(new InputStreamReader(inputStream, Charset.defaultCharset())); |
||||
String line; |
||||
while ((line = reader.readLine()) != null) { |
||||
sb.append(line); |
||||
} |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} finally { |
||||
if (reader != null) { |
||||
try { |
||||
reader.close(); |
||||
} catch (IOException e) { |
||||
} |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
static class MyX509TrustManager implements X509TrustManager { |
||||
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
||||
} |
||||
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
||||
} |
||||
|
||||
public X509Certificate[] getAcceptedIssuers() { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public static String https(String requestUrl, String requestMethod, String outputStr) { |
||||
String result = null; |
||||
StringBuffer buffer = new StringBuffer(); |
||||
HttpsURLConnection httpUrlConn = null; |
||||
try { |
||||
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
|
||||
TrustManager[] tm = {new MyX509TrustManager()}; |
||||
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); |
||||
sslContext.init(null, tm, new java.security.SecureRandom()); |
||||
// 从上述SSLContext对象中得到SSLSocketFactory对象
|
||||
SSLSocketFactory ssf = sslContext.getSocketFactory(); |
||||
|
||||
URL url = new URL(requestUrl); |
||||
httpUrlConn = (HttpsURLConnection) url.openConnection(); |
||||
httpUrlConn.setSSLSocketFactory(ssf); |
||||
|
||||
httpUrlConn.setDoOutput(false); |
||||
httpUrlConn.setDoInput(true); |
||||
httpUrlConn.setUseCaches(false); |
||||
// 设置请求方式(GET/POST)
|
||||
httpUrlConn.setRequestMethod(requestMethod); |
||||
httpUrlConn.connect(); |
||||
|
||||
// 将返回的输入流转换成字符串
|
||||
InputStream inputStream = httpUrlConn.getInputStream(); |
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8"); |
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader); |
||||
|
||||
String str = null; |
||||
while ((str = bufferedReader.readLine()) != null) { |
||||
buffer.append(str); |
||||
} |
||||
bufferedReader.close(); |
||||
inputStreamReader.close(); |
||||
// 释放资源
|
||||
inputStream.close(); |
||||
// inputStream = null;
|
||||
httpUrlConn.disconnect(); |
||||
result = buffer.toString(); |
||||
FineLoggerFactory.getLogger().error("请求响应时间:{}", result); |
||||
// jsonObject = JSONObject.fromObject(buffer.toString());
|
||||
} catch (Exception e) { |
||||
if (httpUrlConn != null) { |
||||
InputStream errorStream = httpUrlConn.getErrorStream(); |
||||
if (errorStream != null) { |
||||
try { |
||||
String s = IOUtils.toString(errorStream, StandardCharsets.UTF_8); |
||||
FineLoggerFactory.getLogger().error("resp logger :{}", s); |
||||
} catch (IOException ioException) { |
||||
ioException.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
printException2Frlog(e); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public static void printException2Frlog(Exception e) { |
||||
StringWriter writer = new StringWriter(); |
||||
e.printStackTrace(new PrintWriter(writer)); |
||||
String s = writer.toString(); |
||||
FineLoggerFactory.getLogger().error("错误:{}", s); |
||||
} |
||||
|
||||
public static String obj2JsonStr(Object obj) { |
||||
ObjectMapper mapper = new ObjectMapper(); |
||||
String json = ""; |
||||
try { |
||||
json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj); |
||||
} catch (JsonProcessingException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return json; |
||||
} |
||||
|
||||
public static String genToken() { |
||||
LocalDate date = LocalDate.now(); |
||||
String key = "fr123"; |
||||
return DigestUtils.md5Hex(date.toString() + key).toLowerCase(); |
||||
} |
||||
|
||||
public static boolean checkToken(String tokens){ |
||||
return genToken().equals(tokens); |
||||
} |
||||
} |
@ -0,0 +1 @@
|
||||
Plugin-Test_Function_Abs=Test ABS |
@ -0,0 +1 @@
|
||||
Plugin-Test_Function_Abs=测试ABS函数 |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<title>editor</title> |
||||
<meta charset="UTF-8"> |
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> |
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> |
||||
<script src="https://cdn.bootcss.com/babel-core/5.8.35/browser.min.js"></script> |
||||
<script src="https://cdn.bootcss.com/babel-core/5.8.35/browser-polyfill.min.js"></script> |
||||
<script src="${fineServletURL}/file?path=/com/fr/plugin/js/web-office-sdk-v1.1.11.umd.js&type=plain&parser=plain"></script> |
||||
</head> |
||||
<body onload="login()"></body> |
||||
<script type="text/babel"> |
||||
var jsToken = "${jsToken}" |
||||
window.onload = function () { |
||||
// 获取 token 函数 |
||||
var fileId = "${fileId}" |
||||
var userName = "${userName}" |
||||
var xSign = "${xSign}" |
||||
var url = "https://wwo.wps.cn/office/${fileType}/${fileId}?_w_tokentype=1&_w_appid=${appId}&_w_userid=${userName}&_w_signature=${xSign}" |
||||
const refreshToken = () => { |
||||
// 可以返回 Promise 或者 return { token, timeout } |
||||
return Promise.resolve({ |
||||
token: jsToken, // 必需:你需要设置的 toekn |
||||
timeout: 10 * 60 * 1000, // 必需:token 超时时间,以 10 分钟示例 |
||||
}); |
||||
}; |
||||
const jssdk = WebOfficeSDK.config({ |
||||
refreshToken:refreshToken, |
||||
url: url |
||||
}); |
||||
// 设置 token |
||||
jssdk.setToken({ |
||||
token: jsToken, // 根据自身的业务需求,通过异步请求或者模板输出的方式,取得 token |
||||
timeout: 10 * 60 * 1000, // token 超时时间,可配合 refreshToken 配置函数使用,在超时前调用 refreshToken 重新刷新 token |
||||
}); |
||||
// 如果需要对 iframe 进行特殊的处理,可以通过以下方式拿到 iframe 的 dom 对象 |
||||
console.log(jssdk.iframe); |
||||
|
||||
// 打开文档结果 |
||||
jssdk.on('fileOpen', (data) => { |
||||
console.log(data.success); |
||||
}); |
||||
|
||||
|
||||
// 配置超时获取 token 函数 |
||||
|
||||
|
||||
}; |
||||
</script> |
||||
</body> |
||||
</html> |
Binary file not shown.
Loading…
Reference in new issue