调解系统初始化版本
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 缓存的key 常量
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class CacheConstants
|
||||
{
|
||||
/**
|
||||
* 登录用户 redis key
|
||||
*/
|
||||
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||
|
||||
/**
|
||||
* 验证码 redis key
|
||||
*/
|
||||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||
|
||||
/**
|
||||
* 参数管理 cache key
|
||||
*/
|
||||
public static final String SYS_CONFIG_KEY = "sys_config:";
|
||||
|
||||
/**
|
||||
* 字典管理 cache key
|
||||
*/
|
||||
public static final String SYS_DICT_KEY = "sys_dict:";
|
||||
|
||||
/**
|
||||
* 防重提交 redis key
|
||||
*/
|
||||
public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
|
||||
|
||||
/**
|
||||
* 限流 redis key
|
||||
*/
|
||||
public static final String RATE_LIMIT_KEY = "rate_limit:";
|
||||
|
||||
/**
|
||||
* 登录账户密码错误次数 redis key
|
||||
*/
|
||||
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||
public static final String WE_CHAT_SMS_VERIFY_CODE_KEY="we_chat_sms_verify_code:";
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.ruoyi.common.constant;
|
||||
/**
|
||||
* 立案申请案件状态
|
||||
*
|
||||
*/
|
||||
public class CaseApplicationConstants {
|
||||
/** 立案申请 */
|
||||
public static final int CASE_APPLICATION = 0;
|
||||
/** 待立案审查 */
|
||||
public static final int CASE_CHECK = 1;
|
||||
/** 待缴费 */
|
||||
public static final int PENDING_PAYMENT = 2;
|
||||
/** 待缴费确认 */
|
||||
public static final int PENDING_PAYMENT_CONFIRM = 3;
|
||||
/** 待案件质证 */
|
||||
public static final int CASE_CROSSEXAMI = 4;
|
||||
|
||||
/** 待组庭 */
|
||||
public static final int PENDING_TRIAL = 26;
|
||||
/** 待组庭审核 */
|
||||
public static final int CONFIRMDED_PENDING_TRIAL_SUBMMIT = 5;
|
||||
/** 待组庭确定 */
|
||||
public static final int CONFIRMDED_PENDING_TRIAL = 6;
|
||||
|
||||
/** 待审核仲裁方式 */
|
||||
public static final int CHECK_ARBITRATION_METHOD = 7;
|
||||
/** 待开庭审理 */
|
||||
public static final int PENDING_OPENCOURT_HEAR = 8;
|
||||
/** 待书面审理 */
|
||||
public static final int PENDING_WRIITEN_HEAR = 9;
|
||||
/** 待生成仲裁文书 */
|
||||
public static final int GENERATED_ARBITRATION = 10;
|
||||
/**待秘书核验仲裁文书*/
|
||||
public static final int VERPRIF_ARBITRATION = 11;
|
||||
/**待部门长审核仲裁文书*/
|
||||
public static final int CHECK_ARBITRATION = 12;
|
||||
/**待仲裁文书签名*/
|
||||
public static final int SIGN_ARBITRATION = 13;
|
||||
/** 待仲裁文书用印 */
|
||||
public static final int ARBITRATED_SEAL = 14;
|
||||
/** 待仲裁文书送达 */
|
||||
public static final int ARBITRATION_DELIVERY = 15;
|
||||
/** 待案件归档*/
|
||||
public static final int CASE_FILING = 16;
|
||||
/** 已归档*/
|
||||
public static final int CASE_ARCHIVED = 17;
|
||||
|
||||
/** 待修改开庭时间*/
|
||||
public static final int MODIFY_HEARDATE = 31;
|
||||
/**待仲裁员审核仲裁文书*/
|
||||
public static final int HEAD_CHECK_ARBITRATION = 18;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
|
||||
/**
|
||||
* 通用常量信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class Constants
|
||||
{
|
||||
/**
|
||||
* UTF-8 字符集
|
||||
*/
|
||||
public static final String UTF8 = "UTF-8";
|
||||
|
||||
/**
|
||||
* GBK 字符集
|
||||
*/
|
||||
public static final String GBK = "GBK";
|
||||
|
||||
/**
|
||||
* www主域
|
||||
*/
|
||||
public static final String WWW = "www.";
|
||||
|
||||
/**
|
||||
* http请求
|
||||
*/
|
||||
public static final String HTTP = "http://";
|
||||
/**
|
||||
* br标签
|
||||
*/
|
||||
public static final String BR = "</br>";
|
||||
/**
|
||||
* pdf拼接符
|
||||
*/
|
||||
public static final String PDFSTR = "∰";
|
||||
|
||||
/**
|
||||
* https请求
|
||||
*/
|
||||
public static final String HTTPS = "https://";
|
||||
|
||||
/**
|
||||
* 通用成功标识
|
||||
*/
|
||||
public static final String SUCCESS = "0";
|
||||
|
||||
/**
|
||||
* 通用失败标识
|
||||
*/
|
||||
public static final String FAIL = "1";
|
||||
|
||||
/**
|
||||
* 登录成功
|
||||
*/
|
||||
public static final String LOGIN_SUCCESS = "Success";
|
||||
|
||||
/**
|
||||
* 注销
|
||||
*/
|
||||
public static final String LOGOUT = "Logout";
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public static final String REGISTER = "Register";
|
||||
|
||||
/**
|
||||
* 登录失败
|
||||
*/
|
||||
public static final String LOGIN_FAIL = "Error";
|
||||
|
||||
/**
|
||||
* 验证码有效期(分钟)
|
||||
*/
|
||||
public static final Integer CAPTCHA_EXPIRATION = 2;
|
||||
|
||||
/**
|
||||
* 令牌
|
||||
*/
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
public static final String TOKEN_PREFIX = "Bearer ";
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
public static final String LOGIN_USER_KEY = "login_user_key";
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
public static final String JWT_USERID = "userid";
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
public static final String JWT_USERNAME = Claims.SUBJECT;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
public static final String JWT_AVATAR = "avatar";
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
public static final String JWT_CREATED = "created";
|
||||
|
||||
/**
|
||||
* 用户权限
|
||||
*/
|
||||
public static final String JWT_AUTHORITIES = "authorities";
|
||||
|
||||
/**
|
||||
* 资源映射路径 前缀
|
||||
*/
|
||||
public static final String RESOURCE_PREFIX = "/profile";
|
||||
|
||||
/**
|
||||
* RMI 远程方法调用
|
||||
*/
|
||||
public static final String LOOKUP_RMI = "rmi:";
|
||||
|
||||
/**
|
||||
* LDAP 远程方法调用
|
||||
*/
|
||||
public static final String LOOKUP_LDAP = "ldap:";
|
||||
|
||||
/**
|
||||
* LDAPS 远程方法调用
|
||||
*/
|
||||
public static final String LOOKUP_LDAPS = "ldaps:";
|
||||
public static final String DEFAULT_PASSWORD = "123456";
|
||||
public static final String SPLIT_COMMA =",";
|
||||
|
||||
/**
|
||||
* 自动识别json对象白名单配置(仅允许解析的包名,范围越小越安全)
|
||||
*/
|
||||
public static final String[] JSON_WHITELIST_STR = { "org.springframework", "com.ruoyi" };
|
||||
|
||||
/**
|
||||
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
|
||||
*/
|
||||
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
|
||||
|
||||
/**
|
||||
* 定时任务违规的字符
|
||||
*/
|
||||
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
|
||||
"org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config" };
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package com.ruoyi.common.constant;
|
||||
import com.ruoyi.common.exception.EsignDemoException;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.Collator;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @description 请求数据通用处理类
|
||||
* @author 澄泓
|
||||
* @date 2020年10月22日 下午14:25:31
|
||||
* @since JDK1.7
|
||||
*/
|
||||
public class EsignEncryption {
|
||||
|
||||
/**
|
||||
* 不允许外部创建实例
|
||||
*/
|
||||
private EsignEncryption(){}
|
||||
|
||||
/**
|
||||
* 拼接待签名字符串
|
||||
* @param httpMethod
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static String appendSignDataString(String httpMethod, String contentMd5,String accept,String contentType,String headers,String date, String url) throws EsignDemoException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(httpMethod).append("\n").append(accept).append("\n").append(contentMd5).append("\n")
|
||||
.append(contentType).append("\n");
|
||||
|
||||
if ("".equals(date) || date == null) {
|
||||
sb.append("\n");
|
||||
} else {
|
||||
sb.append(date).append("\n");
|
||||
}
|
||||
if ("".equals(headers) || headers == null) {
|
||||
sb.append(url);
|
||||
} else {
|
||||
sb.append(headers).append("\n").append(url);
|
||||
}
|
||||
return new String(sb);
|
||||
}
|
||||
|
||||
/***
|
||||
* Content-MD5的计算方法
|
||||
* @param str 待计算的消息
|
||||
* @return MD5计算后摘要值的Base64编码(ContentMD5)
|
||||
* @throws EsignDemoException 加密过程中的异常信息
|
||||
*/
|
||||
public static String doContentMD5(String str) throws EsignDemoException {
|
||||
byte[] md5Bytes = null;
|
||||
MessageDigest md5 = null;
|
||||
String contentMD5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
// 计算md5函数
|
||||
md5.update(str.getBytes("UTF-8"));
|
||||
// 获取文件MD5的二进制数组(128位)
|
||||
md5Bytes = md5.digest();
|
||||
// 把MD5摘要后的二进制数组md5Bytes使用Base64进行编码(而不是对32位的16进制字符串进行编码)
|
||||
contentMD5 = Base64.encodeBase64String(md5Bytes);
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
EsignDemoException ex = new EsignDemoException("不支持此算法",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return contentMD5;
|
||||
}
|
||||
|
||||
/***
|
||||
* 计算请求签名值-HmacSHA256摘要
|
||||
* @param message 待签名字符串
|
||||
* @param secret 密钥APP KEY
|
||||
* @return reqSignature HmacSHA256计算后摘要值的Base64编码
|
||||
* @throws EsignDemoException 加密过程中的异常信息
|
||||
*/
|
||||
public static String doSignatureBase64(String message, String secret) throws EsignDemoException {
|
||||
String algorithm = "HmacSHA256";
|
||||
Mac hmacSha256;
|
||||
String digestBase64 = null;
|
||||
try {
|
||||
hmacSha256 = Mac.getInstance(algorithm);
|
||||
byte[] keyBytes = secret.getBytes("UTF-8");
|
||||
byte[] messageBytes = message.getBytes("UTF-8");
|
||||
hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, algorithm));
|
||||
// 使用HmacSHA256对二进制数据消息Bytes计算摘要
|
||||
byte[] digestBytes = hmacSha256.doFinal(messageBytes);
|
||||
// 把摘要后的结果digestBytes使用Base64进行编码
|
||||
digestBase64 = Base64.encodeBase64String(digestBytes);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
EsignDemoException ex = new EsignDemoException("不支持此算法",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (InvalidKeyException e) {
|
||||
EsignDemoException ex = new EsignDemoException("无效的密钥规范",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return digestBase64;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间戳
|
||||
* @return
|
||||
*/
|
||||
public static String timeStamp() {
|
||||
long timeStamp = System.currentTimeMillis();
|
||||
return String.valueOf(timeStamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* byte字节数组转换成字符串
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
public static String byteArrayToHexString(byte[] b) {
|
||||
StringBuilder hs = new StringBuilder();
|
||||
String stmp;
|
||||
for (int n = 0; b != null && n < b.length; n++) {
|
||||
stmp = Integer.toHexString(b[n] & 0XFF);
|
||||
if (stmp.length() == 1)
|
||||
hs.append('0');
|
||||
hs.append(stmp);
|
||||
}
|
||||
return hs.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* hash散列加密算法
|
||||
* @return
|
||||
*/
|
||||
public static String Hmac_SHA256(String message,String key) throws EsignDemoException {
|
||||
byte[] rawHmac=null;
|
||||
try {
|
||||
SecretKeySpec sk = new SecretKeySpec(key.getBytes(), "HmacSHA256");
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(sk);
|
||||
rawHmac = mac.doFinal(message.getBytes());
|
||||
}catch (InvalidKeyException e){
|
||||
EsignDemoException ex = new EsignDemoException("无效的密钥规范",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
EsignDemoException ex = new EsignDemoException("不支持此算法",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}catch (Exception e){
|
||||
EsignDemoException ex = new EsignDemoException("hash散列加密算法报错",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}finally {
|
||||
return byteArrayToHexString(rawHmac);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* MD5加密32位
|
||||
*/
|
||||
public static String MD5Digest(String text) throws EsignDemoException {
|
||||
byte[] digest=null;
|
||||
try {
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
md5.update(text.getBytes());
|
||||
digest = md5.digest();
|
||||
}catch (NoSuchAlgorithmException e){
|
||||
EsignDemoException ex = new EsignDemoException("不支持此算法",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}finally {
|
||||
return byteArrayToHexString(digest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void formDataSort(List<BasicNameValuePair> param) {
|
||||
Collections.sort(param, new Comparator<BasicNameValuePair>() {
|
||||
@Override
|
||||
public int compare(BasicNameValuePair o1, BasicNameValuePair o2) {
|
||||
Comparator<Object> com = Collator.getInstance(Locale.CHINA);
|
||||
return com.compare(o1.getName(), o2.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/***
|
||||
* 字符串是否为空(含空格校验)
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isBlank(String str) {
|
||||
if (null == str || 0 == str.length()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int strLen = str.length();
|
||||
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if (!Character.isWhitespace(str.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 对请求URL中的Query参数按照字段名的 ASCII 码从小到大排序(字典排序)
|
||||
*
|
||||
* @param apiUrl
|
||||
* @return 排序后的API接口地址
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String sortApiUrl(String apiUrl) throws EsignDemoException {
|
||||
|
||||
if (!apiUrl.contains("?")) {
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
int queryIndex = apiUrl.indexOf("?");
|
||||
String apiUrlPath =apiUrl.substring(0,queryIndex+1);
|
||||
String apiUrlQuery = apiUrl.substring(queryIndex+1);
|
||||
//apiUrlQuery为空时返回
|
||||
if(isBlank(apiUrlQuery)){
|
||||
return apiUrl.substring(0,apiUrl.length()-1);
|
||||
}
|
||||
// 请求URL中Query参数转成Map
|
||||
Map<Object, Object> queryParamsMap = new HashMap<Object, Object>();
|
||||
String[] params = apiUrlQuery.split("&");
|
||||
for (String str : params) {
|
||||
int index = str.indexOf("=");
|
||||
String key = str.substring(0, index);
|
||||
String value = str.substring(index + 1);
|
||||
if (queryParamsMap.containsKey(key)) {
|
||||
String msg = MessageFormat.format("请求URL中的Query参数的{0}重复", key);
|
||||
throw new EsignDemoException(msg);
|
||||
}
|
||||
queryParamsMap.put(key, value);
|
||||
}
|
||||
|
||||
ArrayList<String> queryMapKeys = new ArrayList<String>();
|
||||
for (Map.Entry<Object, Object> entry : queryParamsMap.entrySet()) {
|
||||
queryMapKeys.add((String) entry.getKey());
|
||||
}
|
||||
// 按照字段名的 ASCII 码从小到大排序(字典排序)
|
||||
Collections.sort(queryMapKeys, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return (o1.compareToIgnoreCase(o2) == 0 ? -o1.compareTo(o2) : o1.compareToIgnoreCase(o2));
|
||||
}
|
||||
});
|
||||
|
||||
StringBuffer queryString = new StringBuffer();
|
||||
// 构造Query参数键值对值对的格式
|
||||
for (int i = 0; i < queryMapKeys.size(); i++) {
|
||||
String key = queryMapKeys.get(i);
|
||||
String value = (String) queryParamsMap.get(key);
|
||||
queryString.append(key);
|
||||
queryString.append("=");
|
||||
queryString.append(value);
|
||||
queryString.append("&");
|
||||
}
|
||||
if (queryString.length() > 0) {
|
||||
queryString = queryString.deleteCharAt(queryString.length() - 1);
|
||||
}
|
||||
|
||||
// Query参数排序后的接口请求地址
|
||||
StringBuffer sortApiUrl = new StringBuffer();
|
||||
sortApiUrl.append(apiUrlPath);
|
||||
sortApiUrl.append(queryString.toString());
|
||||
return sortApiUrl.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*获取query
|
||||
* @param apiUrl
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static ArrayList<BasicNameValuePair> getQuery(String apiUrl) throws EsignDemoException {
|
||||
ArrayList<BasicNameValuePair> BasicNameValuePairList = new ArrayList<>();
|
||||
|
||||
if (!apiUrl.contains("?")) {
|
||||
return BasicNameValuePairList;
|
||||
}
|
||||
|
||||
int queryIndex = apiUrl.indexOf("\\?");
|
||||
String apiUrlQuery = apiUrl.substring(queryIndex,apiUrl.length());
|
||||
|
||||
// 请求URL中Query参数转成Map
|
||||
Map<Object, Object> queryParamsMap = new HashMap<Object, Object>();
|
||||
String[] params = apiUrlQuery.split("&");
|
||||
for (String str : params) {
|
||||
int index = str.indexOf("=");
|
||||
String key = str.substring(0, index);
|
||||
String value = str.substring(index + 1);
|
||||
if (queryParamsMap.containsKey(key)) {
|
||||
String msg = MessageFormat.format("请求URL中的Query参数的{0}重复", key);
|
||||
throw new EsignDemoException(msg);
|
||||
}
|
||||
BasicNameValuePairList.add(new BasicNameValuePair(key,value));
|
||||
queryParamsMap.put(key, value);
|
||||
}
|
||||
return BasicNameValuePairList;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean callBackCheck(String timestamp,String requestQuery,String body,String key,String signature){
|
||||
String algorithm="HmacSHA256";
|
||||
String encoding="UTF-8";
|
||||
Mac mac = null;
|
||||
try {
|
||||
String data = timestamp + requestQuery + body;
|
||||
mac = Mac.getInstance(algorithm);
|
||||
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(encoding), algorithm);
|
||||
mac.init(secretKey);
|
||||
mac.update(data.getBytes(encoding));
|
||||
} catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("获取Signature签名信息异常:" + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return byte2hex(mac.doFinal()).equalsIgnoreCase(signature);
|
||||
}
|
||||
|
||||
/***
|
||||
* 将byte[]转成16进制字符串
|
||||
*
|
||||
* @param data
|
||||
*
|
||||
* @return 16进制字符串
|
||||
*/
|
||||
public static String byte2hex(byte[] data) {
|
||||
StringBuilder hash = new StringBuilder();
|
||||
String stmp;
|
||||
for (int n = 0; data != null && n < data.length; n++) {
|
||||
stmp = Integer.toHexString(data[n] & 0XFF);
|
||||
if (stmp.length() == 1)
|
||||
hash.append('0');
|
||||
hash.append(stmp);
|
||||
}
|
||||
return hash.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ruoyi.common.constant;
|
||||
/**
|
||||
* @description 头部信息常量
|
||||
* @author 澄泓
|
||||
* @date 2020/10/22 15:05
|
||||
* @version JDK1.7
|
||||
*/
|
||||
public enum EsignHeaderConstant {
|
||||
ACCEPT("*/*"),
|
||||
DATE(""),
|
||||
HEADERS( ""),
|
||||
CONTENTTYPE_FORMDATA("application/x-www-form-urlencoded"),
|
||||
CONTENTTYPE_JSON("application/json; charset=UTF-8"),
|
||||
CONTENTTYPE_PDF("application/pdf"),
|
||||
CONTENTTYPE_STREAM("application/octet-stream"),
|
||||
AUTHMODE("Signature");
|
||||
|
||||
private String value;
|
||||
private EsignHeaderConstant(String value) {
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
public String VALUE(){
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
/*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package com.ruoyi.common.constant;
|
||||
import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
|
||||
import com.ruoyi.common.enums.EsignRequestType;
|
||||
import com.ruoyi.common.exception.EsignDemoException;
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.HttpRequestRetryHandler;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.config.Registry;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.conn.ConnectTimeoutException;
|
||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description Http请求 辅助类
|
||||
* @author 澄泓
|
||||
* @since JDK1.7
|
||||
*/
|
||||
public class EsignHttpCfgHelper {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(EsignHttpCfgHelper.class);
|
||||
/**
|
||||
* 超时时间,默认15000毫秒
|
||||
*/
|
||||
private static int MAX_TIMEOUT = 15000;
|
||||
/**
|
||||
* 请求池最大连接数,默认100个
|
||||
*/
|
||||
private static int MAX_TOTAL=100;
|
||||
/**
|
||||
* 单域名最大的连接数,默认50个
|
||||
*/
|
||||
private static int ROUTE_MAX_TOTAL=50;
|
||||
/**
|
||||
* 请求失败重试次数,默认3次
|
||||
*/
|
||||
private static int MAX_RETRY = 3;
|
||||
/**
|
||||
* 是否需要域名校验,默认不需要校验
|
||||
*/
|
||||
private static boolean SSL_VERIFY=false;
|
||||
|
||||
/**
|
||||
* 正向代理IP
|
||||
*/
|
||||
private static String PROXY_IP;
|
||||
/**
|
||||
* 正向代理端口,默认8888
|
||||
*/
|
||||
private static int PROXY_PORT=8888;
|
||||
/**
|
||||
* 代理协议,默认http
|
||||
*/
|
||||
private static String PROXY_AGREEMENT="http";
|
||||
|
||||
/**
|
||||
* 是否开启代理,默认false
|
||||
*/
|
||||
private static boolean OPEN_PROXY=false;
|
||||
|
||||
/**
|
||||
* 代理服务器用户名
|
||||
*/
|
||||
private static String PROXY_USERNAME="";
|
||||
|
||||
/**
|
||||
* 代理服务器密码
|
||||
*/
|
||||
private static String PROXY_PASSWORD="";
|
||||
|
||||
|
||||
private static PoolingHttpClientConnectionManager connMgr; //连接池
|
||||
private static HttpRequestRetryHandler retryHandler; //重试机制
|
||||
|
||||
private static CloseableHttpClient httpClient=null;
|
||||
|
||||
public static int getMaxTimeout() {
|
||||
return MAX_TIMEOUT;
|
||||
}
|
||||
|
||||
public static void setMaxTimeout(int maxTimeout) {
|
||||
MAX_TIMEOUT = maxTimeout;
|
||||
}
|
||||
|
||||
public static int getMaxTotal() {
|
||||
return MAX_TOTAL;
|
||||
}
|
||||
|
||||
public static void setMaxTotal(int maxTotal) {
|
||||
MAX_TOTAL = maxTotal;
|
||||
}
|
||||
|
||||
public static int getRouteMaxTotal() {
|
||||
return ROUTE_MAX_TOTAL;
|
||||
}
|
||||
|
||||
public static void setRouteMaxTotal(int routeMaxTotal) {
|
||||
ROUTE_MAX_TOTAL = routeMaxTotal;
|
||||
}
|
||||
|
||||
public static int getMaxRetry() {
|
||||
return MAX_RETRY;
|
||||
}
|
||||
|
||||
public static void setMaxRetry(int maxRetry) {
|
||||
MAX_RETRY = maxRetry;
|
||||
}
|
||||
|
||||
public static boolean isSslVerify() {
|
||||
return SSL_VERIFY;
|
||||
}
|
||||
|
||||
public static void setSslVerify(boolean sslVerify) {
|
||||
SSL_VERIFY = sslVerify;
|
||||
}
|
||||
|
||||
public static String getProxyIp() {
|
||||
return PROXY_IP;
|
||||
}
|
||||
|
||||
public static void setProxyIp(String proxyIp) {
|
||||
PROXY_IP = proxyIp;
|
||||
}
|
||||
|
||||
public static int getProxyPort() {
|
||||
return PROXY_PORT;
|
||||
}
|
||||
|
||||
public static void setProxyPort(int proxyPort) {
|
||||
PROXY_PORT = proxyPort;
|
||||
}
|
||||
|
||||
public static String getProxyAgreement() {
|
||||
return PROXY_AGREEMENT;
|
||||
}
|
||||
|
||||
public static void setProxyAgreement(String proxyAgreement) {
|
||||
PROXY_AGREEMENT = proxyAgreement;
|
||||
}
|
||||
|
||||
public static boolean getOpenProxy() {
|
||||
return OPEN_PROXY;
|
||||
}
|
||||
|
||||
public static void setOpenProxy(boolean openProxy) {
|
||||
OPEN_PROXY = openProxy;
|
||||
}
|
||||
|
||||
public static String getProxyUsername() {
|
||||
return PROXY_USERNAME;
|
||||
}
|
||||
|
||||
public static void setProxyUserame(String proxyUsername) {
|
||||
PROXY_USERNAME = proxyUsername;
|
||||
}
|
||||
|
||||
public static String getProxyPassword() {
|
||||
return PROXY_PASSWORD;
|
||||
}
|
||||
|
||||
public static void setProxyPassword(String proxyPassword) {
|
||||
PROXY_PASSWORD = proxyPassword;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 不允许外部创建实例
|
||||
*/
|
||||
private EsignHttpCfgHelper() {
|
||||
}
|
||||
|
||||
//------------------------------公有方法start--------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* @description 发起HTTP / HTTPS 请求
|
||||
*
|
||||
* @param reqType
|
||||
* {@link EsignRequestType} 请求类型 GET、 POST 、 DELETE 、 PUT
|
||||
* @param httpUrl
|
||||
* {@link String} 请求目标地址
|
||||
* @param headers
|
||||
* {@link Map} 请求头
|
||||
* @param param
|
||||
* {@link Object} 参数
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
* @author 澄泓
|
||||
*/
|
||||
public static EsignHttpResponse sendHttp(EsignRequestType reqType, String httpUrl, Map<String, String> headers, Object param, boolean debug)
|
||||
throws EsignDemoException {
|
||||
HttpRequestBase reqBase=null;
|
||||
if(httpUrl.startsWith("http")){
|
||||
reqBase=reqType.getHttpType(httpUrl);
|
||||
}else{
|
||||
throw new EsignDemoException("请求url地址格式错误");
|
||||
}
|
||||
if(debug){
|
||||
LOGGER.info("请求头:{}",headers+"\n");
|
||||
LOGGER.info("请求参数\n{}", param+"\n");
|
||||
LOGGER.info("请求地址\n:{}\n请求方式\n:{}",reqBase.getURI(),reqType+"\n");
|
||||
}
|
||||
//请求方法不是GET或者DELETE时传入body体,否则不传入。
|
||||
String[] methods = {"DELETE", "GET"};
|
||||
if(param instanceof String&&Arrays.binarySearch(methods, reqType.name())<0){//POST或者PUT请求
|
||||
((HttpEntityEnclosingRequest) reqBase).setEntity(
|
||||
new StringEntity(String.valueOf(param), ContentType.create("application/json", "UTF-8")));
|
||||
}
|
||||
//参数时字节流数组
|
||||
else if(param instanceof byte[]) {
|
||||
reqBase=reqType.getHttpType(httpUrl);
|
||||
byte[] paramBytes = (byte[])param;
|
||||
((HttpEntityEnclosingRequest) reqBase).setEntity(new ByteArrayEntity(paramBytes));
|
||||
}
|
||||
//参数是form表单时
|
||||
else if(param instanceof List){
|
||||
((HttpEntityEnclosingRequest) reqBase).setEntity(new UrlEncodedFormEntity((Iterable<? extends NameValuePair>) param));
|
||||
}
|
||||
httpClient = getHttpClient();
|
||||
config(reqBase);
|
||||
|
||||
//设置请求头
|
||||
if(headers != null &&headers.size()>0) {
|
||||
for(Map.Entry<String, String> entry :headers.entrySet()) {
|
||||
reqBase.setHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
//响应对象
|
||||
CloseableHttpResponse res = null;
|
||||
//响应内容
|
||||
String resCtx = null;
|
||||
int status;
|
||||
EsignHttpResponse esignHttpResponse = new EsignHttpResponse();
|
||||
try {
|
||||
//执行请求
|
||||
res = httpClient.execute(reqBase);
|
||||
status=res.getStatusLine().getStatusCode();
|
||||
|
||||
//获取请求响应对象和响应entity
|
||||
HttpEntity httpEntity = res.getEntity();
|
||||
if(httpEntity != null) {
|
||||
resCtx = EntityUtils.toString(httpEntity,"utf-8");
|
||||
}
|
||||
if(debug) {
|
||||
LOGGER.info("响应\n{}", resCtx + "\n");
|
||||
LOGGER.info("----------------------------end------------------------");
|
||||
}
|
||||
} catch (NoHttpResponseException e) {
|
||||
throw new EsignDemoException("服务器丢失了",e);
|
||||
} catch (SSLHandshakeException e){
|
||||
String msg = MessageFormat.format("SSL握手异常", e);
|
||||
EsignDemoException ex = new EsignDemoException(msg, e);
|
||||
throw ex;
|
||||
} catch (UnknownHostException e){
|
||||
EsignDemoException ex = new EsignDemoException("服务器找不到", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch(ConnectTimeoutException e){
|
||||
EsignDemoException ex = new EsignDemoException("连接超时", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch(SSLException e){
|
||||
EsignDemoException ex = new EsignDemoException("SSL异常",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (ClientProtocolException e) {
|
||||
EsignDemoException ex = new EsignDemoException("请求头异常",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("网络请求失败",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} finally {
|
||||
if(res != null) {
|
||||
try {
|
||||
res.close();
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("--->>关闭请求响应失败",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
esignHttpResponse.setStatus(status);
|
||||
esignHttpResponse.setBody(resCtx);
|
||||
return esignHttpResponse;
|
||||
}
|
||||
//------------------------------公有方法end----------------------------------------------
|
||||
|
||||
//------------------------------私有方法start--------------------------------------------
|
||||
|
||||
/**
|
||||
* @description 请求头和超时时间配置
|
||||
*
|
||||
* @param httpReqBase
|
||||
* @author 澄泓
|
||||
*/
|
||||
private static void config(HttpRequestBase httpReqBase) {
|
||||
// 配置请求的超时设置
|
||||
RequestConfig.Builder builder = RequestConfig.custom()
|
||||
.setConnectionRequestTimeout(MAX_TIMEOUT)
|
||||
.setConnectTimeout(MAX_TIMEOUT)
|
||||
.setSocketTimeout(MAX_TIMEOUT);
|
||||
if(OPEN_PROXY){
|
||||
HttpHost proxy=new HttpHost(PROXY_IP,PROXY_PORT,PROXY_AGREEMENT);
|
||||
builder.setProxy(proxy);
|
||||
}
|
||||
RequestConfig requestConfig = builder.build();
|
||||
httpReqBase.setConfig(requestConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 连接池配置
|
||||
*
|
||||
* @return
|
||||
* @author 澄泓
|
||||
*/
|
||||
private static void cfgPoolMgr() throws EsignDemoException {
|
||||
ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
|
||||
LayeredConnectionSocketFactory sslsf = SSLConnectionSocketFactory.getSocketFactory();
|
||||
if(!SSL_VERIFY){
|
||||
sslsf=sslConnectionSocketFactory();
|
||||
}
|
||||
|
||||
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("http", plainsf)
|
||||
.register("https", sslsf)
|
||||
.build();
|
||||
|
||||
//连接池管理器
|
||||
connMgr = new PoolingHttpClientConnectionManager(registry);
|
||||
//请求池最大连接数
|
||||
connMgr.setMaxTotal(MAX_TOTAL);
|
||||
//但域名最大的连接数
|
||||
connMgr.setDefaultMaxPerRoute(ROUTE_MAX_TOTAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @description 设置重试机制
|
||||
*
|
||||
* @author 澄泓
|
||||
*/
|
||||
private static void cfgRetryHandler() {
|
||||
retryHandler = new HttpRequestRetryHandler() {
|
||||
|
||||
@Override
|
||||
public boolean retryRequest(IOException e, int excCount, HttpContext ctx) {
|
||||
//超过最大重试次数,就放弃
|
||||
if(excCount > MAX_RETRY) {
|
||||
return false;
|
||||
}
|
||||
//服务器丢掉了链接,就重试
|
||||
if(e instanceof NoHttpResponseException) {
|
||||
return true;
|
||||
}
|
||||
//不重试SSL握手异常
|
||||
if(e instanceof SSLHandshakeException) {
|
||||
return false;
|
||||
}
|
||||
//中断
|
||||
if(e instanceof InterruptedIOException) {
|
||||
return false;
|
||||
}
|
||||
//目标服务器不可达
|
||||
if(e instanceof UnknownHostException) {
|
||||
return false;
|
||||
}
|
||||
//连接超时
|
||||
//SSL异常
|
||||
if(e instanceof SSLException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HttpClientContext clientCtx = HttpClientContext.adapt(ctx);
|
||||
HttpRequest req = clientCtx.getRequest();
|
||||
//如果是幂等请求,就再次尝试
|
||||
if(!(req instanceof HttpEntityEnclosingRequest)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略域名校验
|
||||
*/
|
||||
private static SSLConnectionSocketFactory sslConnectionSocketFactory() throws EsignDemoException {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLS"); // 创建一个上下文(此处指定的协议类型似乎不是重点)
|
||||
X509TrustManager tm = new X509TrustManager() { // 创建一个跳过SSL证书的策略
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
|
||||
}
|
||||
};
|
||||
ctx.init(null, new TrustManager[] { tm }, null); // 使用上面的策略初始化上下文
|
||||
return new SSLConnectionSocketFactory(ctx, new String[] { "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" }, null, NoopHostnameVerifier.INSTANCE);
|
||||
}catch (Exception e){
|
||||
EsignDemoException ex = new EsignDemoException("忽略域名校验失败",e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取单例HttpClient
|
||||
*
|
||||
* @return
|
||||
* @author 澄泓
|
||||
*/
|
||||
private static synchronized CloseableHttpClient getHttpClient() throws EsignDemoException {
|
||||
if(httpClient==null) {
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(new AuthScope(PROXY_IP,PROXY_PORT),new UsernamePasswordCredentials(PROXY_USERNAME, PROXY_PASSWORD));
|
||||
cfgPoolMgr();
|
||||
cfgRetryHandler();
|
||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||
httpClient = httpClientBuilder.setDefaultCredentialsProvider(credsProvider).setConnectionManager(connMgr).setRetryHandler(retryHandler).build();
|
||||
}
|
||||
return httpClient;
|
||||
|
||||
}
|
||||
//------------------------------私有方法end----------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
import com.ruoyi.common.exception.EsignDemoException;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 澄泓
|
||||
* @version JDK1.7
|
||||
* @description 文件转换类
|
||||
* @date 2020/10/26 10:47
|
||||
*/
|
||||
public class FileTransformation {
|
||||
|
||||
/**
|
||||
* 传入本地文件路径转二进制byte
|
||||
*
|
||||
* @param srcFilePath 本地文件路径
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static byte[] fileToBytes(String srcFilePath) throws EsignDemoException {
|
||||
return getBytes(srcFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片转base64
|
||||
*
|
||||
* @param filePath 本地文件路径
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static String fileToBase64(String filePath) throws EsignDemoException {
|
||||
byte[] bytes;
|
||||
String base64 = null;
|
||||
bytes = fileToBytes(filePath);
|
||||
base64 = Base64.encodeBase64String(bytes);
|
||||
base64 = base64.replaceAll("\r\n", "");
|
||||
return base64;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws EsignDemoException {
|
||||
System.out.println(getFileContentMD5("D:\\文档\\PLT2022-02124CT.pdf"));
|
||||
}
|
||||
|
||||
/***
|
||||
* 计算文件内容的Content-MD5
|
||||
* @param filePath 文件路径
|
||||
* @return
|
||||
*/
|
||||
public static String getFileContentMD5(String filePath) throws EsignDemoException {
|
||||
// 获取文件MD5的二进制数组(128位)
|
||||
byte[] bytes = getFileMD5Bytes128(filePath);
|
||||
// 对文件MD5的二进制数组进行base64编码
|
||||
return new String(Base64.encodeBase64String(bytes));
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param httpUrl 网络文件地址url
|
||||
* @return
|
||||
*/
|
||||
public static boolean downLoadFileByUrl(String httpUrl, String dir) throws EsignDemoException {
|
||||
boolean downLoadFileFlag = false;
|
||||
InputStream fis = null;
|
||||
FileOutputStream fileOutputStream = null;
|
||||
try {
|
||||
URL url = new URL(httpUrl);
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.connect();
|
||||
fis = httpConn.getInputStream();
|
||||
fileOutputStream = new FileOutputStream(new File(dir));
|
||||
byte[] md5Bytes = null;
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length = -1;
|
||||
while ((length = fis.read(buffer, 0, 1024)) != -1) {
|
||||
fileOutputStream.write(buffer, 0, length);
|
||||
}
|
||||
downLoadFileFlag = true;
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("获取文件流异常", e);
|
||||
ex.initCause(e);
|
||||
return downLoadFileFlag;
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fileOutputStream != null) {
|
||||
fileOutputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("关闭文件流异常", e);
|
||||
ex.initCause(e);
|
||||
return downLoadFileFlag;
|
||||
}
|
||||
}
|
||||
return downLoadFileFlag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 网络文件转二进制MD5数组并获取文件大小
|
||||
*
|
||||
* @param fileUrl 网络文件地址url
|
||||
* @return
|
||||
*/
|
||||
public static Map fileUrlToBytes(String fileUrl) throws EsignDemoException {
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
try {
|
||||
URL url = new URL(fileUrl);
|
||||
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||
httpConn.connect();
|
||||
InputStream fis = httpConn.getInputStream();
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
outStream.close();
|
||||
map.put("fileSize", fis.available());
|
||||
byte[] md5Bytes = null;
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
byte[] buffer = new byte[1024];
|
||||
int length = -1;
|
||||
while ((length = fis.read(buffer, 0, 1024)) != -1) {
|
||||
md5.update(buffer, 0, length);
|
||||
outStream.write(buffer, 0, length);
|
||||
}
|
||||
md5Bytes = md5.digest();
|
||||
byte[] fileData = outStream.toByteArray();
|
||||
map.put("fileData", fileData);
|
||||
outStream.close();
|
||||
fis.close();
|
||||
map.put("md5Bytes", md5Bytes);
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("获取文件流异常", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
EsignDemoException ex = new EsignDemoException("文件计算异常", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取文件MD5的二进制数组(128位)
|
||||
* @param filePath
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
*/
|
||||
public static byte[] getFileMD5Bytes128(String filePath) throws EsignDemoException {
|
||||
FileInputStream fis = null;
|
||||
byte[] md5Bytes = null;
|
||||
try {
|
||||
File file = new File(filePath);
|
||||
fis = new FileInputStream(file);
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
byte[] buffer = new byte[1024];
|
||||
int length = -1;
|
||||
while ((length = fis.read(buffer, 0, 1024)) != -1) {
|
||||
md5.update(buffer, 0, length);
|
||||
}
|
||||
md5Bytes = md5.digest();
|
||||
fis.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
EsignDemoException ex = new EsignDemoException("文件找不到", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
EsignDemoException ex = new EsignDemoException("不支持此算法", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("输入流或输出流异常", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("关闭文件输入流失败", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
return md5Bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
* @description 根据文件路径,获取文件base64
|
||||
* @author 宫清
|
||||
* @date 2019年7月21日 下午4:22:08
|
||||
*/
|
||||
public static String getBase64Str(String path) throws EsignDemoException {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(new File(path));
|
||||
byte[] bytes = new byte[is.available()];
|
||||
is.read(bytes);
|
||||
return Base64.encodeBase64String(bytes);
|
||||
} catch (Exception e) {
|
||||
EsignDemoException ex = new EsignDemoException("获取文件输入流失败", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("关闭文件输入流失败", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path 文件路径
|
||||
* @return
|
||||
* @description 获取文件名称
|
||||
* @author 宫清
|
||||
* @date 2019年7月21日 下午8:21:16
|
||||
*/
|
||||
public static String getFileName(String path) {
|
||||
return new File(path).getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePath {@link String} 文件地址
|
||||
* @return
|
||||
* @throws EsignDemoException
|
||||
* @description 获取文件字节流
|
||||
* @date 2019年7月10日 上午9:17:00
|
||||
* @author 宫清
|
||||
*/
|
||||
public static byte[] getBytes(String filePath) throws EsignDemoException {
|
||||
File file = new File(filePath);
|
||||
FileInputStream fis = null;
|
||||
byte[] buffer = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
buffer = new byte[(int) file.length()];
|
||||
fis.read(buffer);
|
||||
} catch (Exception e) {
|
||||
EsignDemoException ex = new EsignDemoException("获取文件字节流失败", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
EsignDemoException ex = new EsignDemoException("关闭文件字节流失败", e);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 代码生成通用常量
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class GenConstants
|
||||
{
|
||||
/** 单表(增删改查) */
|
||||
public static final String TPL_CRUD = "crud";
|
||||
|
||||
/** 树表(增删改查) */
|
||||
public static final String TPL_TREE = "tree";
|
||||
|
||||
/** 主子表(增删改查) */
|
||||
public static final String TPL_SUB = "sub";
|
||||
|
||||
/** 树编码字段 */
|
||||
public static final String TREE_CODE = "treeCode";
|
||||
|
||||
/** 树父编码字段 */
|
||||
public static final String TREE_PARENT_CODE = "treeParentCode";
|
||||
|
||||
/** 树名称字段 */
|
||||
public static final String TREE_NAME = "treeName";
|
||||
|
||||
/** 上级菜单ID字段 */
|
||||
public static final String PARENT_MENU_ID = "parentMenuId";
|
||||
|
||||
/** 上级菜单名称字段 */
|
||||
public static final String PARENT_MENU_NAME = "parentMenuName";
|
||||
|
||||
/** 数据库字符串类型 */
|
||||
public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" };
|
||||
|
||||
/** 数据库文本类型 */
|
||||
public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" };
|
||||
|
||||
/** 数据库时间类型 */
|
||||
public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" };
|
||||
|
||||
/** 数据库数字类型 */
|
||||
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
"bit", "bigint", "float", "double", "decimal" };
|
||||
|
||||
/** 页面不需要编辑字段 */
|
||||
public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" };
|
||||
|
||||
/** 页面不需要显示的列表字段 */
|
||||
public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by",
|
||||
"update_time" };
|
||||
|
||||
/** 页面不需要查询字段 */
|
||||
public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by",
|
||||
"update_time", "remark" };
|
||||
|
||||
/** Entity基类字段 */
|
||||
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
|
||||
|
||||
/** Tree基类字段 */
|
||||
public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" };
|
||||
|
||||
/** 文本框 */
|
||||
public static final String HTML_INPUT = "input";
|
||||
|
||||
/** 文本域 */
|
||||
public static final String HTML_TEXTAREA = "textarea";
|
||||
|
||||
/** 下拉框 */
|
||||
public static final String HTML_SELECT = "select";
|
||||
|
||||
/** 单选框 */
|
||||
public static final String HTML_RADIO = "radio";
|
||||
|
||||
/** 复选框 */
|
||||
public static final String HTML_CHECKBOX = "checkbox";
|
||||
|
||||
/** 日期控件 */
|
||||
public static final String HTML_DATETIME = "datetime";
|
||||
|
||||
/** 图片上传控件 */
|
||||
public static final String HTML_IMAGE_UPLOAD = "imageUpload";
|
||||
|
||||
/** 文件上传控件 */
|
||||
public static final String HTML_FILE_UPLOAD = "fileUpload";
|
||||
|
||||
/** 富文本控件 */
|
||||
public static final String HTML_EDITOR = "editor";
|
||||
|
||||
/** 字符串类型 */
|
||||
public static final String TYPE_STRING = "String";
|
||||
|
||||
/** 整型 */
|
||||
public static final String TYPE_INTEGER = "Integer";
|
||||
|
||||
/** 长整型 */
|
||||
public static final String TYPE_LONG = "Long";
|
||||
|
||||
/** 浮点型 */
|
||||
public static final String TYPE_DOUBLE = "Double";
|
||||
|
||||
/** 高精度计算类型 */
|
||||
public static final String TYPE_BIGDECIMAL = "BigDecimal";
|
||||
|
||||
/** 时间类型 */
|
||||
public static final String TYPE_DATE = "Date";
|
||||
|
||||
/** 模糊查询 */
|
||||
public static final String QUERY_LIKE = "LIKE";
|
||||
|
||||
/** 相等查询 */
|
||||
public static final String QUERY_EQ = "EQ";
|
||||
|
||||
/** 需要 */
|
||||
public static final String REQUIRE = "1";
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 返回状态码
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class HttpStatus
|
||||
{
|
||||
/**
|
||||
* 操作成功
|
||||
*/
|
||||
public static final int SUCCESS = 200;
|
||||
|
||||
/**
|
||||
* 对象创建成功
|
||||
*/
|
||||
public static final int CREATED = 201;
|
||||
|
||||
/**
|
||||
* 请求已经被接受
|
||||
*/
|
||||
public static final int ACCEPTED = 202;
|
||||
|
||||
/**
|
||||
* 操作已经执行成功,但是没有返回数据
|
||||
*/
|
||||
public static final int NO_CONTENT = 204;
|
||||
|
||||
/**
|
||||
* 资源已被移除
|
||||
*/
|
||||
public static final int MOVED_PERM = 301;
|
||||
|
||||
/**
|
||||
* 重定向
|
||||
*/
|
||||
public static final int SEE_OTHER = 303;
|
||||
|
||||
/**
|
||||
* 资源没有被修改
|
||||
*/
|
||||
public static final int NOT_MODIFIED = 304;
|
||||
|
||||
/**
|
||||
* 参数列表错误(缺少,格式不匹配)
|
||||
*/
|
||||
public static final int BAD_REQUEST = 400;
|
||||
|
||||
/**
|
||||
* 未授权
|
||||
*/
|
||||
public static final int UNAUTHORIZED = 401;
|
||||
|
||||
/**
|
||||
* 访问受限,授权过期
|
||||
*/
|
||||
public static final int FORBIDDEN = 403;
|
||||
|
||||
/**
|
||||
* 资源,服务未找到
|
||||
*/
|
||||
public static final int NOT_FOUND = 404;
|
||||
|
||||
/**
|
||||
* 不允许的http方法
|
||||
*/
|
||||
public static final int BAD_METHOD = 405;
|
||||
|
||||
/**
|
||||
* 资源冲突,或者资源被锁
|
||||
*/
|
||||
public static final int CONFLICT = 409;
|
||||
|
||||
/**
|
||||
* 不支持的数据,媒体类型
|
||||
*/
|
||||
public static final int UNSUPPORTED_TYPE = 415;
|
||||
|
||||
/**
|
||||
* 系统内部错误
|
||||
*/
|
||||
public static final int ERROR = 500;
|
||||
|
||||
/**
|
||||
* 接口未实现
|
||||
*/
|
||||
public static final int NOT_IMPLEMENTED = 501;
|
||||
|
||||
/**
|
||||
* 系统警告消息
|
||||
*/
|
||||
public static final int WARN = 601;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 任务调度通用常量
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ScheduleConstants
|
||||
{
|
||||
public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME";
|
||||
|
||||
/** 执行目标key */
|
||||
public static final String TASK_PROPERTIES = "TASK_PROPERTIES";
|
||||
|
||||
/** 默认 */
|
||||
public static final String MISFIRE_DEFAULT = "0";
|
||||
|
||||
/** 立即触发执行 */
|
||||
public static final String MISFIRE_IGNORE_MISFIRES = "1";
|
||||
|
||||
/** 触发一次执行 */
|
||||
public static final String MISFIRE_FIRE_AND_PROCEED = "2";
|
||||
|
||||
/** 不触发立即执行 */
|
||||
public static final String MISFIRE_DO_NOTHING = "3";
|
||||
|
||||
public enum Status
|
||||
{
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL("0"),
|
||||
/**
|
||||
* 暂停
|
||||
*/
|
||||
PAUSE("1");
|
||||
|
||||
private String value;
|
||||
|
||||
private Status(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 用户常量信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserConstants
|
||||
{
|
||||
/**
|
||||
* 平台内系统用户的唯一标志
|
||||
*/
|
||||
public static final String SYS_USER = "SYS_USER";
|
||||
|
||||
/** 正常状态 */
|
||||
public static final String NORMAL = "0";
|
||||
|
||||
/** 异常状态 */
|
||||
public static final String EXCEPTION = "1";
|
||||
|
||||
/** 用户封禁状态 */
|
||||
public static final String USER_DISABLE = "1";
|
||||
|
||||
/** 角色封禁状态 */
|
||||
public static final String ROLE_DISABLE = "1";
|
||||
|
||||
/** 部门正常状态 */
|
||||
public static final String DEPT_NORMAL = "0";
|
||||
|
||||
/** 部门停用状态 */
|
||||
public static final String DEPT_DISABLE = "1";
|
||||
|
||||
/** 字典正常状态 */
|
||||
public static final String DICT_NORMAL = "0";
|
||||
|
||||
/** 是否为系统默认(是) */
|
||||
public static final String YES = "Y";
|
||||
|
||||
/** 是否菜单外链(是) */
|
||||
public static final String YES_FRAME = "0";
|
||||
|
||||
/** 是否菜单外链(否) */
|
||||
public static final String NO_FRAME = "1";
|
||||
|
||||
/** 菜单类型(目录) */
|
||||
public static final String TYPE_DIR = "M";
|
||||
|
||||
/** 菜单类型(菜单) */
|
||||
public static final String TYPE_MENU = "C";
|
||||
|
||||
/** 菜单类型(按钮) */
|
||||
public static final String TYPE_BUTTON = "F";
|
||||
|
||||
/** Layout组件标识 */
|
||||
public final static String LAYOUT = "Layout";
|
||||
|
||||
/** ParentView组件标识 */
|
||||
public final static String PARENT_VIEW = "ParentView";
|
||||
|
||||
/** InnerLink组件标识 */
|
||||
public final static String INNER_LINK = "InnerLink";
|
||||
|
||||
/** 校验是否唯一的返回标识 */
|
||||
public final static boolean UNIQUE = true;
|
||||
public final static boolean NOT_UNIQUE = false;
|
||||
|
||||
/**
|
||||
* 用户名长度限制
|
||||
*/
|
||||
public static final int USERNAME_MIN_LENGTH = 2;
|
||||
public static final int USERNAME_MAX_LENGTH = 20;
|
||||
|
||||
/**
|
||||
* 密码长度限制
|
||||
*/
|
||||
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||
}
|
||||
Reference in New Issue
Block a user