Merge remote-tracking branch 'base-version/test' into dev
# Conflicts: # zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/util/security/CryptoSignatureUtils.java # zt-module-system/zt-module-system-api/src/main/java/com/zt/plat/module/system/api/sms/dto/send/SmsSendSingleToUserReqDTO.java # zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl.java # zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/controller/admin/sms/SmsCallbackController.java # zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/framework/sms/core/enums/SmsChannelEnum.java
This commit is contained in:
@@ -163,6 +163,33 @@
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.14</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.5.14</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(description = "分页结果")
|
||||
@Data
|
||||
@Data //TODO 分页结果参考这个
|
||||
public final class PageResult<T> implements Serializable {
|
||||
|
||||
@Schema(description = "数据", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
||||
@@ -0,0 +1,382 @@
|
||||
package com.zt.plat.framework.common.util.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.entity.mime.HttpMultipartMode;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* HttpClient工具类
|
||||
*
|
||||
* @author luzemin
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpClientUtils {
|
||||
/**
|
||||
* 请求配置对象
|
||||
*/
|
||||
private static final RequestConfig REQUEST_CONFIG;
|
||||
|
||||
static {
|
||||
/* 设置请求和传输超时时间 */
|
||||
REQUEST_CONFIG = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求传输json参数
|
||||
*
|
||||
* @param url url地址
|
||||
* @param jsonParam 参数
|
||||
* @return JSONObject 请求结果对象
|
||||
*/
|
||||
public static JSONObject httpPost(String url, JSONObject jsonParam) {
|
||||
/* 请求返回结果 */
|
||||
JSONObject jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(REQUEST_CONFIG);
|
||||
|
||||
try {
|
||||
/* 构建请求体 */
|
||||
if (StringUtils.isNotBlank(jsonParam.toJSONString())) {
|
||||
StringEntity entity = new StringEntity(jsonParam.toJSONString(), StandardCharsets.UTF_8);
|
||||
entity.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
entity.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
String result = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
jsonResult = JSONObject.parseObject(result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求传输String参数 例如:name=Jack&sex=1&type=2
|
||||
* Content-type:application/x-www-form-urlencoded
|
||||
*
|
||||
* @param url url地址
|
||||
* @param strParam 参数
|
||||
* @return JSONObject 请求结果对象
|
||||
*/
|
||||
public static JSONObject httpPost(String url, String strParam) {
|
||||
/* 请求返回结果 */
|
||||
JSONObject jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(REQUEST_CONFIG);
|
||||
|
||||
try {
|
||||
/* 构建请求体 */
|
||||
if (StringUtils.isNotBlank(strParam)) {
|
||||
StringEntity entity = new StringEntity(strParam, StandardCharsets.UTF_8);
|
||||
entity.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
entity.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
String result = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
jsonResult = JSONObject.parseObject(result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求传输String参数 例如:name=Jack&sex=1&type=2
|
||||
* Content-type:application/x-www-form-urlencoded
|
||||
*
|
||||
* @param url url地址
|
||||
* @param strParam 参数
|
||||
* @param token 身份认证令牌
|
||||
* @return JSONObject 请求结果对象
|
||||
*/
|
||||
public static JSONObject httpPostByToken(String url, String strParam, String token) {
|
||||
/* 请求返回结果 */
|
||||
JSONObject jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(REQUEST_CONFIG);
|
||||
|
||||
try {
|
||||
/* 构建请求体 */
|
||||
if (StringUtils.isNotBlank(strParam)) {
|
||||
StringEntity entity = new StringEntity(strParam, StandardCharsets.UTF_8);
|
||||
entity.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
entity.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
httpPost.setHeader("token", token);
|
||||
}
|
||||
|
||||
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
String result = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
jsonResult = JSONObject.parseObject(result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求传输String参数 例如:name=Jack&sex=1&type=2
|
||||
* Content-type:application/x-www-form-urlencoded
|
||||
*
|
||||
* @param url url地址
|
||||
* @param strParam 参数
|
||||
* @return String 请求结果对象
|
||||
*/
|
||||
public static String httpPostStr(String url, String strParam) {
|
||||
/* 请求返回结果 */
|
||||
String jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(REQUEST_CONFIG);
|
||||
|
||||
try {
|
||||
/* 构建请求体 */
|
||||
if (StringUtils.isNotBlank(strParam)) {
|
||||
StringEntity entity = new StringEntity(strParam, StandardCharsets.UTF_8);
|
||||
entity.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
entity.setContentType(ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
jsonResult = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* post请求传输String参数 例如:name=Jack&sex=1&type=2
|
||||
* Content-type:application/x-www-form-urlencoded
|
||||
*
|
||||
* @param url url地址
|
||||
* @param strParam 参数
|
||||
* @param token 身份认证字符串
|
||||
* @return String 请求结果对象
|
||||
*/
|
||||
public static String httpPostStrByToken(String url, String strParam, String token) {
|
||||
/* 请求返回结果 */
|
||||
String jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(REQUEST_CONFIG);
|
||||
|
||||
try {
|
||||
/* 构建请求体 */
|
||||
if (StringUtils.isNotBlank(strParam)) {
|
||||
StringEntity entity = new StringEntity(strParam, StandardCharsets.UTF_8);
|
||||
entity.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
entity.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
httpPost.setHeader("token", token);
|
||||
}
|
||||
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
jsonResult = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指定的url地址上传文件
|
||||
*
|
||||
* @param mediaName 服务器定义的读取文件流的name
|
||||
* @param url 文件上传url
|
||||
* @param file 文件对象
|
||||
* @return JSONObject 文件上传结果
|
||||
*/
|
||||
public static JSONObject httpFileUpload(String mediaName, String url, MultipartFile file) {
|
||||
/* 请求返回结果 */
|
||||
JSONObject jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(REQUEST_CONFIG);
|
||||
|
||||
/* 构建请求头 */
|
||||
String boundaryStr = UUID.randomUUID().toString();
|
||||
httpPost.setHeader(HttpHeaders.ACCEPT_CHARSET, StandardCharsets.UTF_8.name());
|
||||
httpPost.setHeader(HttpHeaders.CONNECTION, "Keep-Alive");
|
||||
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.MULTIPART_FORM_DATA.getMimeType() + ";boundary=" + boundaryStr);
|
||||
|
||||
try {
|
||||
/* 构建文件对象 */
|
||||
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
|
||||
multipartEntityBuilder.setBoundary(boundaryStr)
|
||||
.setContentType(ContentType.APPLICATION_OCTET_STREAM)
|
||||
.setCharset(StandardCharsets.UTF_8)
|
||||
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
|
||||
multipartEntityBuilder.addBinaryBody(mediaName, file.getInputStream(), ContentType.APPLICATION_OCTET_STREAM, file.getOriginalFilename());
|
||||
HttpEntity entity = multipartEntityBuilder.build();
|
||||
httpPost.setEntity(entity);
|
||||
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
String result = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
jsonResult = JSONObject.parseObject(result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送get请求
|
||||
*
|
||||
* @param url 路径
|
||||
* @return JSONObject 请求结果对象
|
||||
*/
|
||||
public static JSONObject httpGet(String url) {
|
||||
/* 请求返回结果 */
|
||||
JSONObject jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
httpGet.setConfig(REQUEST_CONFIG);
|
||||
|
||||
try {
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
String result = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
jsonResult = JSONObject.parseObject(result);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送get请求
|
||||
*
|
||||
* @param url 路径
|
||||
* @return JSONObject 请求结果对象
|
||||
*/
|
||||
public static String httpGetStr(String url) {
|
||||
/* 请求返回结果 */
|
||||
String jsonResult = null;
|
||||
|
||||
/* 构建连接对象 */
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
httpGet.setConfig(REQUEST_CONFIG);
|
||||
|
||||
try {
|
||||
/* 提交请求,构建响应对象 */
|
||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
||||
|
||||
/* 处理请求结果 */
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
jsonResult = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.zt.plat.framework.common.util.security;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.symmetric.SM4;
|
||||
import com.zt.plat.framework.common.util.json.JsonUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
@@ -11,6 +12,7 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -27,6 +29,15 @@ public final class CryptoSignatureUtils {
|
||||
private static final String AES_TRANSFORMATION = "AES/ECB/PKCS5Padding";
|
||||
public static final String SIGNATURE_FIELD = "signature";
|
||||
|
||||
private static final String CHARSET = "UTF-8";
|
||||
|
||||
//@Value("${sa.encrypt.sm4.key}")
|
||||
private static String SM4_KEY = "1234567890123456";
|
||||
|
||||
static {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
private CryptoSignatureUtils() {
|
||||
}
|
||||
|
||||
@@ -220,4 +231,91 @@ public final class CryptoSignatureUtils {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------- 国密方式2 -------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*/
|
||||
public static String enCode(String data) {
|
||||
try {
|
||||
// 第一步: SM4 加密
|
||||
SM4 sm4 = new SM4(hexToBytes(stringToHex(SM4_KEY)));
|
||||
String encryptHex = sm4.encryptHex(data);
|
||||
|
||||
// 第二步: Base64 编码
|
||||
return new String(Base64.getEncoder().encode(encryptHex.getBytes(CHARSET)), CHARSET);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("国密加密失败{}",e.getMessage(),e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*/
|
||||
public static String deCode(String data) {
|
||||
try {
|
||||
|
||||
// 第一步: Base64 解码
|
||||
byte[] base64Decode = Base64.getDecoder().decode(data);
|
||||
|
||||
// 第二步: SM4 解密
|
||||
SM4 sm4 = new SM4(hexToBytes(stringToHex(SM4_KEY)));
|
||||
return sm4.decryptStr(new String(base64Decode));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("国密解密失败{}",e.getMessage(),e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String stringToHex(String input) {
|
||||
char[] chars = input.toCharArray();
|
||||
StringBuilder hex = new StringBuilder();
|
||||
for (char c : chars) {
|
||||
hex.append(Integer.toHexString((int) c));
|
||||
}
|
||||
return hex.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 16 进制串转字节数组
|
||||
*
|
||||
* @param hex 16进制字符串
|
||||
* @return byte数组
|
||||
*/
|
||||
public static byte[] hexToBytes(String hex) {
|
||||
int length = hex.length();
|
||||
byte[] result;
|
||||
if (length % 2 == 1) {
|
||||
length++;
|
||||
result = new byte[(length / 2)];
|
||||
hex = "0" + hex;
|
||||
} else {
|
||||
result = new byte[(length / 2)];
|
||||
}
|
||||
int j = 0;
|
||||
for (int i = 0; i < length; i += 2) {
|
||||
result[j] = hexToByte(hex.substring(i, i + 2));
|
||||
j++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 16 进制字符转字节
|
||||
*
|
||||
* @param hex 16进制字符 0x00到0xFF
|
||||
* @return byte
|
||||
*/
|
||||
private static byte hexToByte(String hex) {
|
||||
return (byte) Integer.parseInt(hex, 16);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.zt.plat.framework.common.util.security;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Key;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* 3DES加密解密工具类
|
||||
* 注意:如果websphere下报错:Could not find class 'com.sun.crypto.provider.SunJCE'
|
||||
* 解决方法如下: 下载sunjce_provider.jar放到jdk目录\jre\lib\ext里即可解决
|
||||
*
|
||||
* @author apple
|
||||
*/
|
||||
|
||||
public class DESUtil {
|
||||
|
||||
/**
|
||||
* 默认的密钥
|
||||
*/
|
||||
private static final String strDefaultKey = "cymco-20160329000000000000000ABCGHDYFYSSPPOEWWWDDDSSXX-cymco";
|
||||
|
||||
private Cipher encryptCipher = null;
|
||||
|
||||
private Cipher decryptCipher = null;
|
||||
|
||||
/**
|
||||
* 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813, 和public static byte[]
|
||||
* hexStr2ByteArr(String strIn) 互为可逆的转换过程
|
||||
* @param arrB 需要转换的byte数组
|
||||
* @return 转换后的字符串
|
||||
* @throws Exception 本方法不处理任何异常,所有异常全部抛出
|
||||
*/
|
||||
public static String byteArr2HexStr(byte[] arrB) throws Exception {
|
||||
int iLen = arrB.length;
|
||||
// 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
|
||||
StringBuffer sb = new StringBuffer(iLen * 2);
|
||||
for (int i = 0; i < iLen; i++) {
|
||||
int intTmp = arrB[i];
|
||||
// 把负数转换为正数
|
||||
while (intTmp < 0) {
|
||||
intTmp = intTmp + 256;
|
||||
}
|
||||
// 小于0F的数需要在前面补0
|
||||
if (intTmp < 16) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(Integer.toString(intTmp, 16));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将表示16进制值的字符串转换为byte数组, 和public static String byteArr2HexStr(byte[] arrB)
|
||||
* 互为可逆的转换过程
|
||||
* @param strIn 需要转换的字符串
|
||||
* @return 转换后的byte数组
|
||||
* @throws Exception 本方法不处理任何异常,所有异常全部抛出
|
||||
*/
|
||||
public static byte[] hexStr2ByteArr(String strIn) throws Exception {
|
||||
byte[] arrB = strIn.getBytes(StandardCharsets.UTF_8);
|
||||
int iLen = arrB.length;
|
||||
|
||||
// 两个字符表示一个字节,所以字节数组长度是字符串长度除以2
|
||||
byte[] arrOut = new byte[iLen / 2];
|
||||
for (int i = 0; i < iLen; i = i + 2) {
|
||||
String strTmp = new String(arrB, i, 2);
|
||||
arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
|
||||
}
|
||||
return arrOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认构造方法,使用默认密钥
|
||||
* @throws Exception
|
||||
*/
|
||||
public DESUtil() throws Exception {
|
||||
this(strDefaultKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定密钥构造方法
|
||||
* @param strKey 指定的密钥
|
||||
* @throws Exception
|
||||
*/
|
||||
public DESUtil(String strKey) throws Exception {
|
||||
//Security.addProvider(new com.sun.crypto.provider.SunJCE());
|
||||
Key key = getKey(strKey.getBytes());
|
||||
|
||||
encryptCipher = Cipher.getInstance("DES");
|
||||
encryptCipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
|
||||
decryptCipher = Cipher.getInstance("DES");
|
||||
decryptCipher.init(Cipher.DECRYPT_MODE, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密字节数组
|
||||
* @param arrB 需加密的字节数组
|
||||
* @return 加密后的字节数组
|
||||
* @throws Exception
|
||||
*/
|
||||
public byte[] encrypt(byte[] arrB) throws Exception {
|
||||
return encryptCipher.doFinal(arrB);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密字符串
|
||||
* @param strIn 需加密的字符串
|
||||
* @return 加密后的字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public String encrypt(String strIn) throws Exception {
|
||||
return byteArr2HexStr(encrypt(strIn.getBytes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密字节数组
|
||||
* @param arrB 需解密的字节数组
|
||||
* @return 解密后的字节数组
|
||||
* @throws Exception
|
||||
*/
|
||||
public byte[] decrypt(byte[] arrB) throws Exception {
|
||||
return decryptCipher.doFinal(arrB);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密字符串
|
||||
* @param strIn 需解密的字符串
|
||||
* @return 解密后的字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public String decrypt(String strIn) throws Exception {
|
||||
return new String(decrypt(hexStr2ByteArr(strIn)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从指定字符串生成密钥,密钥所需的字节数组长度为8位 不足8位时后面补0,超出8位只取前8位
|
||||
* @param arrBTmp 构成该字符串的字节数组
|
||||
* @return 生成的密钥
|
||||
* @throws Exception
|
||||
*/
|
||||
private Key getKey(byte[] arrBTmp) throws Exception {
|
||||
// 创建一个空的8位字节数组(默认值为0)
|
||||
byte[] arrB = new byte[8];
|
||||
|
||||
// 将原始字节数组转换为8位
|
||||
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
|
||||
arrB[i] = arrBTmp[i];
|
||||
}
|
||||
|
||||
// 生成密钥
|
||||
Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public static String SHA1(String decript) throws NoSuchAlgorithmException {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||
digest.update(decript.getBytes());
|
||||
byte messageDigest[] = digest.digest();
|
||||
// Create Hex String
|
||||
StringBuffer hexString = new StringBuffer();
|
||||
// 字节数组转换为 十六进制 数
|
||||
for (int i = 0; i < messageDigest.length; i++) {
|
||||
String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
|
||||
if (shaHex.length() < 2) {
|
||||
hexString.append(0);
|
||||
}
|
||||
hexString.append(shaHex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void main(String [] args){
|
||||
DESUtil des;
|
||||
try {
|
||||
des = new DESUtil();
|
||||
String en= des.encrypt("fls123,12121");
|
||||
System.out.println(en);
|
||||
String de = des.decrypt(en);
|
||||
System.out.println(de);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package com.zt.plat.framework.common.util.validation;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 正则校验工具
|
||||
*
|
||||
* @author luzemin
|
||||
**/
|
||||
public class MatcherSolveUtils {
|
||||
|
||||
/**
|
||||
* 正则校验正数、负数、和小数
|
||||
*/
|
||||
private static final Pattern IS_NUM = Pattern.compile("^(\\-|\\+)?\\d+(\\.\\d+)?$");
|
||||
/**
|
||||
* 正则校验大于0的数字
|
||||
*/
|
||||
private static final Pattern IS_GT_0_NUM = Pattern.compile("(^[0-9]+\\.\\d+$)|(^[0-9]+$)");
|
||||
/**
|
||||
* 正则校验大于等于0的数字
|
||||
*/
|
||||
private static final Pattern IS_GE_EQ_0_NUM = Pattern.compile("(^[0-9]+\\.\\d+$)|(^[1-9]+\\d*$)");
|
||||
/**
|
||||
* 正则校验字母或者数字组成的字符串
|
||||
*/
|
||||
private static final Pattern EN_NUM = Pattern.compile("^[A-Za-z0-9]+$");
|
||||
/**
|
||||
* 中文、英文、数字但不包括下划线等符号
|
||||
*/
|
||||
private static final Pattern EN_CN_NUM = Pattern.compile("^[\\u4E00-\\u9FA5A-Za-z0-9]+$");
|
||||
/**
|
||||
* Email地址
|
||||
*/
|
||||
private static final Pattern EMAIL = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
|
||||
/**
|
||||
* 域名
|
||||
*/
|
||||
private static final Pattern WWW = Pattern.compile("[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\\.?");
|
||||
/**
|
||||
* InternetURL
|
||||
*/
|
||||
private static final Pattern URL = Pattern.compile("(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private static final Pattern MOBILE_NUM = Pattern.compile("^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$");
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
private static final Pattern TRUCK_NO = Pattern.compile("^([京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][1-9DF][1-9ABCDEFGHJKLMNPQRSTUVWXYZ]\\d{3}[1-9DF]|[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5})$");
|
||||
|
||||
/**
|
||||
* 电话号码正则表达式(支持手机号码,3-4位区号,7-8位直播号码,1-4位分机号)
|
||||
*/
|
||||
private static final Pattern PHONE_NUM = Pattern.compile("((\\d{11})|^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$)");
|
||||
/**
|
||||
* 身份证
|
||||
*/
|
||||
private static final Pattern ID_CARD = Pattern.compile("(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)");
|
||||
/**
|
||||
* 帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线)
|
||||
*/
|
||||
private static final Pattern ACCOUNT = Pattern.compile("^[a-zA-Z][a-zA-Z0-9_]{4,15}$");
|
||||
/**
|
||||
* 密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线)
|
||||
*/
|
||||
private static final Pattern PASSWORD = Pattern.compile("^[a-zA-Z]\\w{5,17}$");
|
||||
/**
|
||||
* 强密码(必须包含大小写字母和数字的组合,可以使用特殊字符,长度在8-18之间)
|
||||
*/
|
||||
private static final Pattern PASSWORD_STRONG = Pattern.compile("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,18}$");
|
||||
|
||||
/**
|
||||
* 正则校验正数、负数、和小数
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkIsNum(String str) {
|
||||
return IS_NUM.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 正则校验大于0的数字
|
||||
*
|
||||
* @param str 待校验字符串t
|
||||
*/
|
||||
public static boolean checkIsGt0Num(String str) {
|
||||
return IS_GT_0_NUM.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 正则校验大于等于0的数字
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkIsGtEq0Num(String str) {
|
||||
return IS_GE_EQ_0_NUM.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 正则校验字母或者数字组成的字符串
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkEnNum(String str) {
|
||||
return EN_NUM.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 中文、英文、数字但不包括下划线等符号
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkEnCnNum(String str) {
|
||||
return EN_CN_NUM.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Email地址
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkEmail(String str) {
|
||||
return EMAIL.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 域名
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkWww(String str) {
|
||||
return WWW.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* InternetURL
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkInternetURL(String str) {
|
||||
return URL.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkMobileNum(String str) {
|
||||
return MOBILE_NUM.matcher(str).matches();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 车牌号
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
* @return 校验通过-true,反之-false
|
||||
*/
|
||||
public static boolean checkTruckNo(String str) {
|
||||
return TRUCK_NO.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 电话号码正则表达式(支持手机号码,3-4位区号,7-8位直播号码,1-4位分机号)
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkPhoneNum(String str) {
|
||||
return PHONE_NUM.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份证
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkIdCard(String str) {
|
||||
return ID_CARD.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线)
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkAccount(String str) {
|
||||
return ACCOUNT.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线)
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkPassword(String str) {
|
||||
return PASSWORD.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 强密码(必须包含大小写字母和数字的组合,可以使用特殊字符,长度在8-18之间)
|
||||
*
|
||||
* @param str 待校验字符串
|
||||
*/
|
||||
public static boolean checkPasswordStrong(String str) {
|
||||
return PASSWORD_STRONG.matcher(str).matches();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import static com.zt.plat.framework.web.core.util.WebFrameworkUtils.HEADER_TENAN
|
||||
*
|
||||
* Producer 发送消息时,将 {@link TenantContextHolder} 租户编号,添加到消息的 Header 中
|
||||
*
|
||||
* @author ZT
|
||||
* @author ZT TODO
|
||||
*/
|
||||
public class TenantRocketMQSendMessageHook implements SendMessageHook {
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> {
|
||||
PageSumSupport.tryAttachSummary(this, queryWrapper, pageResult);
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
//TODO 分页结果参考这个 ===============================
|
||||
// MyBatis Plus 查询
|
||||
IPage<T> mpPage = MyBatisUtils.buildPage(pageParam, sortingFields);
|
||||
selectPage(mpPage, queryWrapper);
|
||||
|
||||
Reference in New Issue
Block a user