You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

81 lines
2.4 KiB

/*
* Copyright (C), 2015-2019
* FileName: FuncUtils
* Author: xxx
* Date: 2019/8/22 15:05
* Description: FuncUtils
* History:
* <author> <time> <version> <desc>
*/
package com.fr.plugin.tabledataservice.utils;
import com.fr.base.Icon;
import com.fr.base.IconManager;
import com.fr.data.NetworkHelper;
import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.io.utils.MD5Calculator;
import com.fr.json.JSONObject;
import com.fr.locale.InterProviderFactory;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static com.fr.plugin.tabledataservice.Constants.ICON_PATH;
/**
* 〈Function Description〉<br>
* 〈FuncUtils〉
*
* @author xxx
* @since 1.0.0
*/
public class FuncUtils {
/**
* MD5验证:key、报表路径、时间戳计算
*
* @param appKey
* @param reportPath
* @param timestamp
* @param sign
* @return
*/
public static Boolean validateMD5(String appKey, String reportPath, String timestamp, String sign) {
StringBuffer str = new StringBuffer();
str.append(appKey);
str.append(reportPath);
str.append(timestamp);
String token = MD5Calculator.calculateMD5(str.toString().getBytes());
return ComparatorUtils.equals(token, sign);
}
public static void printErrorJSON(HttpServletResponse res, int code) throws Exception {
JSONObject errorJSON = JSONObject.create();
errorJSON.put("err_code", code)
.put("err_msg", InterProviderFactory.getProvider().getLocText("Plugin-tabledataservice_Error_" + code));
WebUtils.printAsJSON(res, errorJSON);
}
public static JSONObject getParams(HttpServletRequest req) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(NetworkHelper.getRequestInputStream(req), "utf-8"));
StringBuilder sb = new StringBuilder();
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
}
br.close();
return new JSONObject(sb.toString());
}
public static String loadIcon() {
Icon icon = new Icon("json", IOUtils.readImage(ICON_PATH));
IconManager.getIconManager().addIcon(icon, true);
return icon.getName();
}
}