mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-11-18 21:17:43 +08:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e890fd94c3 | |||
|
|
5545bcfc9f | ||
|
|
a2a247bbff | ||
|
|
fd2d7a51bb | ||
|
|
763bc7b47a | ||
|
|
605d697c4f | ||
| c931ee8b5b | |||
| 26c9b91cf0 | |||
| f15f02e0d2 | |||
| ee012fe845 | |||
| 25a534d307 | |||
| 0c12801047 | |||
| b284ec4a84 |
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
.mvn
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
20
README.md
20
README.md
@@ -3,25 +3,35 @@
|
||||
### 说明
|
||||
>1. 支持环境:java8
|
||||
>2. 该工具包基于springboot提取,按理说适用于所有java工程
|
||||
>3. 其中依赖jjwt、validation-api,但不传递依赖
|
||||
>3. 其中依赖jjwt、validation-api,排除请使用
|
||||
```
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>xxx</artifactId>
|
||||
<groupId>xxxx</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
```
|
||||
>4. 1.1.9升级JWT为单例类
|
||||
|
||||
|
||||
### 使用
|
||||
>yexuejc.base.version=1.1.2
|
||||
>yexuejc.base.version=1.1.9
|
||||
|
||||
pom.xml
|
||||
```
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yexuejc</groupId>
|
||||
<groupId>com.yexuejc.base</groupId>
|
||||
<artifactId>yexuejc-base</artifactId>
|
||||
<version>${yexuejc.base.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
<id>yexuejc-nexus-public</id>
|
||||
<name>yexuejc-nexus-public</name>
|
||||
<url>https://nexus.yexuejc.club/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
|
||||
61
UPDATE.md
61
UPDATE.md
@@ -1,30 +1,83 @@
|
||||
yexuejc-base 更新记录
|
||||
------------------
|
||||
|
||||
#### version :1.1.9
|
||||
**time:2018-9-23 11:57:36** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. 优化工具类包名:不向下兼容,升级请修改
|
||||
>2. 升级JWT工具类:更改为单例模式,可配置参数
|
||||
#
|
||||
|
||||
#### version :1.1.8
|
||||
**time:2018-9-3 19:29:56** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. 增肌图片处理工具类
|
||||
>2. 增肌3des工具类
|
||||
>3. 增肌RSA工具类
|
||||
>4. 优化其他工具类
|
||||
#
|
||||
#### version :1.1.7
|
||||
**time:2018-8-17 11:22:50** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. 优化ApiVO
|
||||
#
|
||||
|
||||
#### version :1.1.6
|
||||
**time:2018-7-7 11:32:56** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. maven仓库更新
|
||||
#
|
||||
|
||||
#### version :1.1.5
|
||||
**time:2018-6-19 22:16:34** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. 优化ApiVO
|
||||
|
||||
#
|
||||
#### version :1.1.4
|
||||
**time:2018-6-14 22:27:59** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. 统一编码:UTF-8
|
||||
|
||||
#
|
||||
#### version :1.1.3
|
||||
**time:2018年6月2日12:16:58** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. 修改正则RegexUtils.java
|
||||
>2. 修改正则StrUtil.java->扩展genUUID()
|
||||
|
||||
#
|
||||
#### version :1.1.2
|
||||
**time:** 2018-5-16 15:03:28<br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1.修改依赖
|
||||
>1. 修改依赖
|
||||
|
||||
#
|
||||
#### version :1.1.1
|
||||
**time:** 2018-5-12 22:25:05<br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1.添加RSA
|
||||
>1. 添加RSA
|
||||
#
|
||||
|
||||
##### version :1.1.0
|
||||
**time:** 2018-5-12 22:25:05<br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1.添加支持加密功能
|
||||
>1. 添加支持加密功能
|
||||
#
|
||||
|
||||
#### version :1.0.0
|
||||
**time:** 2018-1-31 12:16:10<br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1.基于java8开发的web应用工具包
|
||||
>1. 基于java8开发的web应用工具包
|
||||
#
|
||||
19
WIKI.md
19
WIKI.md
@@ -1,9 +1,28 @@
|
||||
yexuejc-base 文档
|
||||
------------------
|
||||
|
||||
> com.yexuejc.base.constant
|
||||
##### 1. RespsConsts 网络请求统一返回 常量
|
||||
> com.yexuejc.base.http
|
||||
##### 2. Resps 网络请求统一返回类
|
||||
> com.yexuejc.base.pojo
|
||||
##### 3. ApiVO 接口交互API
|
||||
##### 4. BaseVO 基类VO
|
||||
##### 5. PagerVO 分页VO
|
||||
##### 6. ParamsPO 加密参数封装
|
||||
> com.yexuejc.base.util
|
||||
##### 7. AlgorithmUtils 算法工具类:进制转换
|
||||
##### 8. DateTimeUtil 日期时间工具:基于`java.time.*`家族
|
||||
##### 9. DateUtil 日期时间工具:基于`java.util.Date`家族
|
||||
##### 10. ExcelImportUtils excel工具
|
||||
##### 11. FileUtil 文件操作工具
|
||||
##### 12. IdcardValidator 身份证工具
|
||||
##### 13. JsonUtil json操作工具:基于`com.fasterxml.jackson`家族
|
||||
##### 14. JwtUtil jwt库工具
|
||||
##### 15. MapRemoveNullUtil map处理空值
|
||||
##### 16. MoneyUtils 金额转换:元->分 分->元
|
||||
##### 17. RegexUtils 常用正则
|
||||
##### 18. StrUtil 字符串工具
|
||||
##### 19. SysUtils 常用java系统操作封装
|
||||
|
||||
待完善......
|
||||
34
pom.xml
34
pom.xml
@@ -6,15 +6,12 @@
|
||||
|
||||
<groupId>com.yexuejc.base</groupId>
|
||||
<artifactId>yexuejc-base</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.9</version>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
|
||||
<properties>
|
||||
<repos.yexuejc.ivt.url>http://47.100.13.178:7081/nexus/content/groups/public</repos.yexuejc.ivt.url>
|
||||
<repos.yexuejc.prod.url>http://47.100.13.178:7081/nexus/content/groups/public</repos.yexuejc.prod.url>
|
||||
<repos.yexuejc.dist.url>http://47.100.13.178:7081/nexus/content/repositories</repos.yexuejc.dist.url>
|
||||
|
||||
<repos.yexuejc.url>https://nexus.yexuejc.club/repository/</repos.yexuejc.url>
|
||||
<repos.aliyun.url>http://maven.aliyun.com/nexus/content/groups/public</repos.aliyun.url>
|
||||
<repos.jitpack.url>https://jitpack.io</repos.jitpack.url>
|
||||
<jjwt.version>0.7.0</jjwt.version>
|
||||
@@ -23,6 +20,7 @@
|
||||
<validation-api.version>1.1.0.Final</validation-api.version>
|
||||
<commons-codec.version>1.10</commons-codec.version>
|
||||
<commons-io.version>2.6</commons-io.version>
|
||||
<bcprov-jdk15on.version>1.60</bcprov-jdk15on.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -51,6 +49,12 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<!--支持大量的密码术算法,并提供JCE 1.2.1的实现-->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>${bcprov-jdk15on.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -61,8 +65,9 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- 打包源码 -->
|
||||
@@ -99,14 +104,9 @@
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>yexuejc-prod-nexus-public</id>
|
||||
<name>yexuejc-prod-nexus-public</name>
|
||||
<url>${repos.yexuejc.prod.url}</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>yexuejc-ivt-nexus-public</id>
|
||||
<name>yexuejc-ivt-nexus-public</name>
|
||||
<url>${repos.yexuejc.ivt.url}</url>
|
||||
<id>yexuejc-nexus-public</id>
|
||||
<name>yexuejc-nexus-public</name>
|
||||
<url>${repos.yexuejc.url}maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aliyun-nexus-public</id>
|
||||
@@ -123,12 +123,12 @@
|
||||
<repository>
|
||||
<id>releases</id>
|
||||
<name>nexus-release</name>
|
||||
<url>${repos.yexuejc.dist.url}/releases</url>
|
||||
<url>${repos.yexuejc.url}maven-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>snapshots</id>
|
||||
<name>nexus-snapshots</name>
|
||||
<url>${repos.yexuejc.dist.url}/snapshots</url>
|
||||
<url>${repos.yexuejc.url}maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
@@ -107,7 +107,6 @@ public class RSA {
|
||||
* @param privateKey
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static String privateDecrypt(String data, RSAPrivateKey privateKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||
|
||||
200
src/main/java/com/yexuejc/base/encrypt/RSACoder.java
Normal file
200
src/main/java/com/yexuejc/base/encrypt/RSACoder.java
Normal file
@@ -0,0 +1,200 @@
|
||||
package com.yexuejc.base.encrypt;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.security.Key;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
|
||||
/**
|
||||
* RSA 加解密 工具模式
|
||||
*
|
||||
* @author maxf
|
||||
* @ClassName RSACoder
|
||||
* @Description
|
||||
* @date 2018/9/3 16:13
|
||||
*/
|
||||
public class RSACoder {
|
||||
|
||||
public static final String KEY_ALGORITHM = "RSA";
|
||||
|
||||
/**
|
||||
* 解密<br>
|
||||
* 用公钥解密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decryptByPublic(String data, String key)
|
||||
throws Exception {
|
||||
return getDataByPublicKey(data, key, Cipher.DECRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密<br>
|
||||
* 用私钥解密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decryptByPrivateKey(String data, String key)
|
||||
throws Exception {
|
||||
return getDataByPrivateKey(data, key, Cipher.DECRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密<br>
|
||||
* 用公钥加密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encryptByPublicKey(String data, String key)
|
||||
throws Exception {
|
||||
return getDataByPublicKey(data, key, Cipher.ENCRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密<br>
|
||||
* 用私钥加密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encryptByPrivateKey(String data, String key)
|
||||
throws Exception {
|
||||
return getDataByPrivateKey(data, key, Cipher.ENCRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密<br>
|
||||
* 用公钥解密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decryptByPublic(byte[] data, String key)
|
||||
throws Exception {
|
||||
return getDataByPublicKey(data, key, Cipher.DECRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密<br>
|
||||
* 用私钥解密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decryptByPrivateKey(byte[] data, String key)
|
||||
throws Exception {
|
||||
return getDataByPrivateKey(data, key, Cipher.DECRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密<br>
|
||||
* 用公钥加密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encryptByPublicKey(byte[] data, String key)
|
||||
throws Exception {
|
||||
return getDataByPublicKey(data, key, Cipher.ENCRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密<br>
|
||||
* 用私钥加密
|
||||
*
|
||||
* @param data
|
||||
* @param key
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encryptByPrivateKey(byte[] data, String key)
|
||||
throws Exception {
|
||||
return getDataByPrivateKey(data, key, Cipher.ENCRYPT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过公钥获得加解密数据
|
||||
*
|
||||
* @param data String
|
||||
* @param key String
|
||||
* @param mode int
|
||||
* @return
|
||||
*/
|
||||
public static byte[] getDataByPublicKey(String data, String key, int mode)
|
||||
throws Exception {
|
||||
return getDataByPublicKey(data.getBytes(), key, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过私钥获得加解密数据
|
||||
*
|
||||
* @param data String
|
||||
* @param key String
|
||||
* @param mode 加密或解密
|
||||
* @return
|
||||
*/
|
||||
public static byte[] getDataByPrivateKey(String data, String key, int mode)
|
||||
throws Exception {
|
||||
return getDataByPrivateKey(data.getBytes(), key, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过公钥获得加解密数据
|
||||
*
|
||||
* @param data String
|
||||
* @param key String
|
||||
* @param mode int
|
||||
* @return
|
||||
*/
|
||||
public static byte[] getDataByPublicKey(byte[] data, String key, int mode)
|
||||
throws Exception {
|
||||
// 取得私钥
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(Base64.decodeBase64(key.getBytes("UTF-8")));
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
Key privateKey = keyFactory.generatePublic(x509KeySpec);
|
||||
// 对数据进行加密或解密
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
cipher.init(mode, privateKey);
|
||||
return cipher.doFinal(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过私钥获得加解密数据
|
||||
*
|
||||
* @param data String
|
||||
* @param key String
|
||||
* @param mode 加密或解密
|
||||
* @return
|
||||
*/
|
||||
public static byte[] getDataByPrivateKey(byte[] data, String key, int mode)
|
||||
throws Exception {
|
||||
// 取得私钥
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(key.getBytes("UTF-8")));
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
|
||||
Key privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
// 对数据解密
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
cipher.init(mode, privateKey);
|
||||
return cipher.doFinal(data);
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,10 @@ public class Resps<T> implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Resps success(String[] msg) {
|
||||
return new Resps(RespsConsts.CODE_SUCCESS, msg);
|
||||
}
|
||||
|
||||
public static Resps success(String msg) {
|
||||
return new Resps(RespsConsts.CODE_SUCCESS, msg);
|
||||
}
|
||||
@@ -93,8 +97,8 @@ public class Resps<T> implements Serializable {
|
||||
return new Resps(RespsConsts.CODE_ERROR, msg);
|
||||
}
|
||||
|
||||
public static Resps fail(String msg) {
|
||||
return new Resps(RespsConsts.CODE_FAIL, msg);
|
||||
public static Resps error(String[] msg) {
|
||||
return new Resps(RespsConsts.CODE_ERROR, msg);
|
||||
}
|
||||
|
||||
public static Resps error(String code, String msg) {
|
||||
@@ -105,6 +109,14 @@ public class Resps<T> implements Serializable {
|
||||
return new Resps(code, msg);
|
||||
}
|
||||
|
||||
public static Resps fail(String msg) {
|
||||
return new Resps(RespsConsts.CODE_FAIL, msg);
|
||||
}
|
||||
|
||||
public static Resps fail(String[] msg) {
|
||||
return new Resps(RespsConsts.CODE_FAIL, msg);
|
||||
}
|
||||
|
||||
public static Resps fail(String code, String msg) {
|
||||
return new Resps(code, msg);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,58 @@ public class ApiVO implements Serializable {
|
||||
public ApiVO() {
|
||||
}
|
||||
|
||||
public ApiVO(STATUS status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用默认返回code
|
||||
*
|
||||
* @param status
|
||||
* @param msg
|
||||
*/
|
||||
public ApiVO(STATUS status, String msg) {
|
||||
this.status = status;
|
||||
this.msgs = StrUtil.isNotEmpty(msg) ? new String[]{msg} : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用默认返回code
|
||||
*
|
||||
* @param status
|
||||
* @param msg
|
||||
*/
|
||||
public ApiVO(STATUS status, String[] msg) {
|
||||
this.status = status;
|
||||
this.msgs = msg;
|
||||
}
|
||||
|
||||
public ApiVO(STATUS status, String code, String msg) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.msgs = StrUtil.isNotEmpty(msg) ? new String[]{msg} : null;
|
||||
}
|
||||
|
||||
public ApiVO(STATUS status, String code, String[] msg) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.msgs = msg;
|
||||
}
|
||||
|
||||
public ApiVO setStatus(STATUS status, String code, String msg) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.msgs = StrUtil.isNotEmpty(msg) ? new String[]{msg} : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiVO setStatus(STATUS status, String code, String[] msg) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.msgs = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public enum STATUS {
|
||||
/**
|
||||
* 成功
|
||||
@@ -62,36 +108,24 @@ public class ApiVO implements Serializable {
|
||||
*/
|
||||
private Object object2;
|
||||
|
||||
public <T extends Object> void setObject1(T obj) {
|
||||
public <T extends Object> ApiVO setObject1(T obj) {
|
||||
object1 = obj;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends Object> T getObject1(Class<T> clazz) {
|
||||
return (T) object1;
|
||||
}
|
||||
|
||||
public <T extends Object> void setObject2(T obj) {
|
||||
public <T extends Object> ApiVO setObject2(T obj) {
|
||||
object2 = obj;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends Object> T getObject2(Class<T> clazz) {
|
||||
return (T) object2;
|
||||
}
|
||||
|
||||
public ApiVO setStatus(STATUS status, String code, String msg) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.msgs = StrUtil.isNotEmpty(msg) ? new String[]{msg} : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiVO setStatus(STATUS status, String code, String[] msg) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.msgs = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isSucc() {
|
||||
if (STATUS.S.name().equals(status.name())) {
|
||||
return true;
|
||||
@@ -106,8 +140,9 @@ public class ApiVO implements Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
public ApiVO setMsg(String msg) {
|
||||
this.msgs = StrUtil.isNotEmpty(msg) ? new String[]{msg} : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isFail() {
|
||||
@@ -118,8 +153,9 @@ public class ApiVO implements Serializable {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
public ApiVO setCode(String code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,12 +167,14 @@ public class ApiVO implements Serializable {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(STATUS status) {
|
||||
public ApiVO setStatus(STATUS status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMsgs(String[] msgs) {
|
||||
public ApiVO setMsgs(String[] msgs) {
|
||||
this.msgs = msgs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getMsgs() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 基类VO
|
||||
*
|
||||
* @PackageName: com.yexuejc.util.base.pojo
|
||||
* @Description:
|
||||
* @author: maxf
|
||||
@@ -15,16 +16,16 @@ public class BaseVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1442656950873492155L;
|
||||
|
||||
public static interface Add {
|
||||
public interface Add {
|
||||
}
|
||||
|
||||
public static interface Del {
|
||||
public interface Del {
|
||||
}
|
||||
|
||||
public static interface Mdfy {
|
||||
public interface Mdfy {
|
||||
}
|
||||
|
||||
public static interface Srch {
|
||||
public interface Srch {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,13 +9,13 @@ package com.yexuejc.base.util;
|
||||
* @author: maxf
|
||||
* @date: 2017年11月23日 下午3:17:58
|
||||
*/
|
||||
public class AlgorithmUtils {
|
||||
public class AlgorithmUtil {
|
||||
private static final int LENGTH_1 = 1;
|
||||
private static final int LENGTH_2 = 2;
|
||||
private static final int LENGTH_3 = 3;
|
||||
private static final int LENGTH_36 = 36;
|
||||
|
||||
private AlgorithmUtils() {
|
||||
private AlgorithmUtil() {
|
||||
}
|
||||
|
||||
private static final String X36 = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
@@ -107,4 +107,47 @@ public class AlgorithmUtils {
|
||||
static class NextCodeException extends Exception {
|
||||
private static final long serialVersionUID = 8956943499144648985L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 16进制转为2进制
|
||||
*
|
||||
* @param hexString 16进制字符串
|
||||
*/
|
||||
public static String x16ConvertTo2(String hexString) {
|
||||
if (hexString == null || hexString.length() % 2 != 0) {
|
||||
return null;
|
||||
}
|
||||
String bString = "", tmp;
|
||||
for (int i = 0; i < hexString.length(); i++) {
|
||||
tmp = "0000" + Integer.toBinaryString(Integer.parseInt(hexString.substring(i, i + 1), 16));
|
||||
bString += tmp.substring(tmp.length() - 4);
|
||||
}
|
||||
return bString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 16进制转为2进制byte[]
|
||||
*
|
||||
* @param hexString 16进制字符串
|
||||
* @return
|
||||
*/
|
||||
public static byte[] hexStringToBytes(String hexString) {
|
||||
if (hexString == null || hexString.equals("")) {
|
||||
return null;
|
||||
}
|
||||
hexString = hexString.toUpperCase();
|
||||
int length = hexString.length() / 2;
|
||||
char[] hexChars = hexString.toCharArray();
|
||||
byte[] d = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
int pos = i * 2;
|
||||
d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
private static byte charToByte(char c) {
|
||||
return (byte) "0123456789ABCDEF".indexOf(c);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,9 @@ import java.util.Date;
|
||||
* @date: 2018/3/27 10:44
|
||||
*/
|
||||
public class DateTimeUtil {
|
||||
private DateTimeUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本年第一天
|
||||
*
|
||||
@@ -106,7 +109,8 @@ public class DateTimeUtil {
|
||||
* @return
|
||||
*/
|
||||
public static LocalDate getWeek4First(LocalDate date) {
|
||||
TemporalAdjuster FIRST_OF_WEEK = TemporalAdjusters.ofDateAdjuster(localDate -> localDate.minusDays(localDate.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue()));
|
||||
TemporalAdjuster FIRST_OF_WEEK =
|
||||
TemporalAdjusters.ofDateAdjuster(localDate -> localDate.minusDays(localDate.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue()));
|
||||
return date.with(FIRST_OF_WEEK);
|
||||
}
|
||||
|
||||
@@ -126,7 +130,8 @@ public class DateTimeUtil {
|
||||
* @return
|
||||
*/
|
||||
public static LocalDate getWeek4Last(LocalDate date) {
|
||||
TemporalAdjuster LAST_OF_WEEK = TemporalAdjusters.ofDateAdjuster(localDate -> localDate.plusDays(DayOfWeek.SUNDAY.getValue() - localDate.getDayOfWeek().getValue()));
|
||||
TemporalAdjuster LAST_OF_WEEK =
|
||||
TemporalAdjusters.ofDateAdjuster(localDate -> localDate.plusDays(DayOfWeek.SUNDAY.getValue() - localDate.getDayOfWeek().getValue()));
|
||||
return date.with(LAST_OF_WEEK);
|
||||
}
|
||||
|
||||
@@ -136,7 +141,7 @@ public class DateTimeUtil {
|
||||
* @param zonedDateTime
|
||||
* @return
|
||||
*/
|
||||
public static Date zonedDateTime2Date(ZonedDateTime zonedDateTime) {
|
||||
public static Date parseDate(ZonedDateTime zonedDateTime) {
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
ZonedDateTime zdt = zonedDateTime.withZoneSameInstant(zoneId);
|
||||
Date date = Date.from(zdt.toInstant());
|
||||
@@ -149,12 +154,99 @@ public class DateTimeUtil {
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static ZonedDateTime date2ZonedDateTime(Date date) {
|
||||
public static ZonedDateTime parseZonedDateTime(Date date) {
|
||||
Instant instant = date.toInstant();
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
return instant.atZone(zoneId).withZoneSameInstant(zoneId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Date 转 LocalDateTime
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime parseLocalDateTime(Date date) {
|
||||
Instant instant = date.toInstant();
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
return instant.atZone(zoneId).toLocalDateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* LocalDateTime 转 Date
|
||||
*
|
||||
* @param localDateTime
|
||||
* @return
|
||||
*/
|
||||
public static Date parseLocalDateTime(LocalDateTime localDateTime) {
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
ZonedDateTime zdt = localDateTime.atZone(zoneId);
|
||||
return Date.from(zdt.toInstant());
|
||||
}
|
||||
|
||||
/**
|
||||
* LocalDate 转 Date
|
||||
*
|
||||
* @param localDate
|
||||
* @return
|
||||
*/
|
||||
public static Date parseData(LocalDate localDate) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
|
||||
return Date.from(instant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Date 转 LocalDate
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static LocalDate parseLocalDate(Date date) {
|
||||
Instant instant = date.toInstant();
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
|
||||
return localDateTime.toLocalDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Date 转 LocalTime
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static LocalTime parseLocalTime(Date date) {
|
||||
Instant instant = date.toInstant();
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
|
||||
return localDateTime.toLocalTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Date 转 LocalTime
|
||||
*
|
||||
* @param localTime
|
||||
* @return 当前日期的指定时间
|
||||
*/
|
||||
public static Date parseDate(LocalTime localTime) {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
return parseDate(localDate, localTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Date 转 LocalTime
|
||||
*
|
||||
* @param localDate
|
||||
* @param localTime
|
||||
* @return 指定日期的指定时间
|
||||
*/
|
||||
public static Date parseDate(LocalDate localDate, LocalTime localTime) {
|
||||
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
Instant instant = localDateTime.atZone(zone).toInstant();
|
||||
return Date.from(instant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间 <br/>
|
||||
* 格式 yyyy-MM-dd HH:mm:ss
|
||||
|
||||
@@ -7,6 +7,14 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* java.util.Date 时间工具类
|
||||
*
|
||||
* @author maxf
|
||||
* @ClassName DateUtil
|
||||
* @Description
|
||||
* @date 2018/9/3 15:27
|
||||
*/
|
||||
public class DateUtil {
|
||||
private DateUtil() {
|
||||
}
|
||||
@@ -71,7 +79,7 @@ public class DateUtil {
|
||||
/**
|
||||
* 日期字符串转date
|
||||
*
|
||||
* @param date
|
||||
* @param dateStr
|
||||
* @return Date
|
||||
* @throws ParseException
|
||||
*/
|
||||
@@ -81,7 +89,7 @@ public class DateUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期字符串转date
|
||||
* date转字符串
|
||||
*
|
||||
* @param date
|
||||
* @return Date
|
||||
@@ -95,6 +103,34 @@ public class DateUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期字符串转dateTime
|
||||
*
|
||||
* @param dateStr
|
||||
* @return
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static Date str2dateTime(String dateStr) throws ParseException {
|
||||
Date date = DATE_TIME_FORMAT.parse(dateStr);
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* dateTime转字符串
|
||||
*
|
||||
* @param date
|
||||
* @return Date
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static String dateTime2str(Date date) throws ParseException {
|
||||
if (date != null) {
|
||||
return DATE_TIME_FORMAT.format(date);
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取本周的日期
|
||||
*
|
||||
|
||||
@@ -2,13 +2,15 @@ package com.yexuejc.base.util;
|
||||
|
||||
/**
|
||||
* excel 格式验证工具
|
||||
*
|
||||
* @ClassName: ExcelImportUtils
|
||||
* @Description:
|
||||
* @author: maxf
|
||||
* @date: 2017/12/27 16:42
|
||||
*/
|
||||
public class ExcelImportUtils {
|
||||
|
||||
public class ExcelImportUtil {
|
||||
private ExcelImportUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是2003的excel,返回true是2003
|
||||
421
src/main/java/com/yexuejc/base/util/ImgUtil.java
Normal file
421
src/main/java/com/yexuejc/base/util/ImgUtil.java
Normal file
@@ -0,0 +1,421 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* 图片处理工具类
|
||||
*
|
||||
* @author maxf
|
||||
* @ClassName ImageUtil
|
||||
* @Description
|
||||
* @date 2018/9/3 15:25
|
||||
*/
|
||||
public class ImgUtil {
|
||||
private ImgUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一张网络图片转化成Base64字符串
|
||||
*
|
||||
* @param imgURL 网络图片url
|
||||
* @return String Base64字符串
|
||||
*/
|
||||
public static String getImageStrFromUrl(String imgURL) {
|
||||
ByteArrayOutputStream data = new ByteArrayOutputStream();
|
||||
try {
|
||||
byte[] by = new byte[1024];
|
||||
InputStream is = getImageInputStreamFromUrl(null, imgURL);
|
||||
// 将内容读取内存中
|
||||
int len = -1;
|
||||
while ((len = is.read(by)) != -1) {
|
||||
data.write(by, 0, len);
|
||||
}
|
||||
// 关闭流
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 对字节数组Base64编码
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(data.toByteArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取网络图片url为输入流
|
||||
* <p>本方法未关闭io流,请自行关闭io流</p>
|
||||
* <p>is.close();</p>
|
||||
*
|
||||
* @param imgURL 网络图片url
|
||||
* @return InputStream 输入流
|
||||
* @throws IOException
|
||||
*/
|
||||
public static InputStream getImageInputStreamFromUrl(Proxy proxy, String imgURL) throws IOException {
|
||||
// 创建URL
|
||||
URL url = new URL(imgURL);
|
||||
// 创建链接
|
||||
HttpURLConnection conn;
|
||||
if (null == proxy) {
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
} else {
|
||||
// 如果有代理则通过代理下载
|
||||
conn = (HttpURLConnection) url.openConnection(proxy);
|
||||
}
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5000);
|
||||
InputStream is = conn.getInputStream();
|
||||
return is;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取网络图片url为输入流
|
||||
* <p>本方法未关闭io流,请自行关闭io流</p>
|
||||
* <p>is.close();</p>
|
||||
*
|
||||
* @param imgURL
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static InputStream getImageInputStreamFromUrl(String imgURL) throws IOException {
|
||||
return getImageInputStreamFromUrl(null, imgURL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将图片文件流转换成字节数组
|
||||
* <p>
|
||||
* 好处就是字节数组可以多次利用,而流一旦读取过一次之后就不能再使用了
|
||||
*
|
||||
* @param proxy
|
||||
* @param targetUrl
|
||||
* @return
|
||||
* @throws MalformedURLException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] getByteArrayFromInputStream(Proxy proxy, String targetUrl)
|
||||
throws MalformedURLException, IOException {
|
||||
InputStream is = getImageInputStreamFromUrl(proxy, targetUrl);
|
||||
return getByteArray(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将图片文件流转换成字节数组
|
||||
* <p>
|
||||
* 好处就是字节数组可以多次利用,而流一旦读取过一次之后就不能再使用了
|
||||
*
|
||||
* @param targetUrl
|
||||
* @return
|
||||
* @throws MalformedURLException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] getByteArrayFromInputStream(String targetUrl)
|
||||
throws MalformedURLException, IOException {
|
||||
return getByteArrayFromInputStream(null, targetUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将图片文件流转换成字节数组
|
||||
*
|
||||
* @return
|
||||
* @throws MalformedURLException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] getByteArray(InputStream is)
|
||||
throws MalformedURLException, IOException {
|
||||
// 把文件写到字节数组保存起来
|
||||
ByteArrayOutputStream fos = getByteArrayFromInputStream(is);
|
||||
byte[] bytes = fos.toByteArray();
|
||||
fos.close();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* ByteArrayOutputStream转换成字节数组
|
||||
*
|
||||
* @param fos
|
||||
* @return
|
||||
* @throws MalformedURLException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] getByteArray(ByteArrayOutputStream fos)
|
||||
throws MalformedURLException, IOException {
|
||||
// 把文件写到字节数组保存起来
|
||||
byte[] bytes = fos.toByteArray();
|
||||
fos.close();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将图片文件流转换成ByteArrayOutputStream
|
||||
* <p>本方法未关闭io流,请自行关闭io流</p>
|
||||
* <p>is.close();</p>
|
||||
*
|
||||
* @param is
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static ByteArrayOutputStream getByteArrayFromInputStream(InputStream is) throws IOException {
|
||||
// 把文件写到字节数组保存起来
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
bis.close();
|
||||
return fos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果你已经将图片文件流InputStream读取出来放到一个字节数组
|
||||
* <p>
|
||||
* 那么根据这个字节数组也是可以转换成对应的图片流,并再次获取图片基本信息
|
||||
*
|
||||
* @param imgBytes
|
||||
* @return
|
||||
*/
|
||||
public static ImageInfo getImageInfoFromInputStream(byte[] imgBytes) {
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(imgBytes);
|
||||
ImageInfo image = getImageInfoFromInputStream(in);
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从图片文件流读取图片文件的基本信息
|
||||
*
|
||||
* @param inputStream
|
||||
* @return
|
||||
*/
|
||||
public static ImageInfo getImageInfoFromInputStream(InputStream inputStream) {
|
||||
ImageInputStream imgStream = null;
|
||||
try {
|
||||
// 创建Image流
|
||||
imgStream = ImageIO.createImageInputStream(inputStream);
|
||||
Iterator<ImageReader> iter = ImageIO.getImageReaders(imgStream);
|
||||
if (!iter.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
// 读取流中一帧就可以获取到高宽以及各式
|
||||
ImageReader reader = iter.next();
|
||||
reader.setInput(imgStream, true);
|
||||
int width = reader.getWidth(0);
|
||||
int height = reader.getHeight(0);
|
||||
String type = reader.getFormatName();
|
||||
ImageInfo bean = new ImageInfo();
|
||||
bean.setWidth(width);
|
||||
bean.setHeight(height);
|
||||
bean.setType(type);
|
||||
return bean;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
imgStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将byte数组以Base64方式编码为字符串
|
||||
*
|
||||
* @param bytes 待编码的byte数组
|
||||
* @return String 编码后的字符串
|
||||
*/
|
||||
public static String encode(byte[] bytes) {
|
||||
return new BASE64Encoder().encode(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将以Base64方式编码的字符串解码为byte数组
|
||||
*
|
||||
* @param encodeStr 待解码的字符串
|
||||
* @return byte[] 解码后的byte数组
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] decode(String encodeStr) throws IOException {
|
||||
byte[] bt = null;
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
bt = decoder.decodeBuffer(encodeStr);
|
||||
return bt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将两个byte数组连接起来后,返回连接后的Byte数组
|
||||
*
|
||||
* @param front 拼接后在前面的数组
|
||||
* @param after 拼接后在后面的数组
|
||||
* @return byte[] 拼接后的数组
|
||||
*/
|
||||
public static byte[] connectBytes(byte[] front, byte[] after) {
|
||||
byte[] result = new byte[front.length + after.length];
|
||||
System.arraycopy(front, 0, result, 0, after.length);
|
||||
System.arraycopy(after, 0, result, front.length, after.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将流保存至本机或者图片服务器
|
||||
*
|
||||
* @param in 图片流
|
||||
* @param saveUrl 目标地址
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void saveImgFromInputStream(InputStream in, String saveUrl) throws IOException {
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(saveUrl));
|
||||
byte[] buffer = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = in.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
bos.close();
|
||||
in.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将图片以Base64方式编码为字符串
|
||||
*
|
||||
* @param imgUrl 图片的绝对路径(例如:D:\\1.jpg)
|
||||
* @return String 编码后的字符串
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String encodeImage(String imgUrl) throws IOException {
|
||||
FileInputStream fis = new FileInputStream(imgUrl);
|
||||
byte[] rs = new byte[fis.available()];
|
||||
fis.read(rs);
|
||||
fis.close();
|
||||
return encode(rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片返回bate[]
|
||||
*
|
||||
* @param imgUrl 图片的绝对路径(例如:D:\\1.jpg)
|
||||
* @return byte[]
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] byteImage(String imgUrl) throws IOException {
|
||||
FileInputStream fis = new FileInputStream(imgUrl);
|
||||
byte[] rs = new byte[fis.available()];
|
||||
return rs;
|
||||
}
|
||||
|
||||
public static class ImageInfo {
|
||||
/**
|
||||
* 图片大小
|
||||
*/
|
||||
private long size = 0;
|
||||
/**
|
||||
* 图片宽度
|
||||
*/
|
||||
private int width = 0;
|
||||
/**
|
||||
* 图片高度
|
||||
*/
|
||||
private int height = 0;
|
||||
/**
|
||||
* 图片类型
|
||||
*/
|
||||
private String type = "jpg";
|
||||
/**
|
||||
* 符号要求的图片类型
|
||||
*/
|
||||
private String[] validTypes;
|
||||
|
||||
/**
|
||||
* 定义一个简单方法描述该图片是否符合要求
|
||||
*
|
||||
* @param validImg
|
||||
* @return
|
||||
*/
|
||||
public boolean isValidImg(ImageInfo validImg) {
|
||||
if (null == validImg) {
|
||||
return true;
|
||||
}
|
||||
return (this.getSize() <= validImg.getSize()) && (this.getWidth() <= validImg.getWidth())
|
||||
&& (this.getHeight() <= validImg.getHeight()) && isValidType(validImg);
|
||||
|
||||
}
|
||||
|
||||
private boolean isValidType(ImageInfo validImg) {
|
||||
if (null == validImg.getValidTypes()) {
|
||||
return true;
|
||||
}
|
||||
boolean isValid = false;
|
||||
for (String validType : validImg.getValidTypes()) {
|
||||
if (type.equalsIgnoreCase(validType)) {
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
private String validTypeToString() {
|
||||
if (null == validTypes) {
|
||||
return "";
|
||||
}
|
||||
StringBuffer sb = new StringBuffer("[");
|
||||
for (String type : validTypes) {
|
||||
sb.append(type).append(" ");
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String[] getValidTypes() {
|
||||
return validTypes;
|
||||
}
|
||||
|
||||
public void setValidTypes(String[] validTypes) {
|
||||
this.validTypes = validTypes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,14 @@ import com.fasterxml.jackson.databind.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* json工具类,基于jackson
|
||||
*
|
||||
* @author maxf
|
||||
* @ClassName JsonUtil
|
||||
* @Description
|
||||
* @date 2018/9/3 15:28
|
||||
*/
|
||||
public class JsonUtil {
|
||||
private JsonUtil() {
|
||||
}
|
||||
|
||||
@@ -6,21 +6,69 @@ import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* jwt工具类
|
||||
* <p>
|
||||
* 升级2.0
|
||||
* <br/>
|
||||
* 由静态类分装成单例类,可配置参数config()
|
||||
* </p>
|
||||
*
|
||||
* @author maxf
|
||||
* @version 2.0
|
||||
* @ClassName JwtUtil
|
||||
* @Description
|
||||
* @date 2018/9/3 15:28
|
||||
*/
|
||||
public class JwtUtil {
|
||||
/** 加密用KEY */
|
||||
private static String JWT_SIGNATURE_KEY = "h%OG8Y3WgA5AN7&6Ke7I#C1XvneW0N8a";
|
||||
/** token类型 */
|
||||
private static String JWT_HEADER_TYP = "JWT";
|
||||
/** token发行商 */
|
||||
private static String JWT_CLAIMS_ISS = "yexuejc.com";
|
||||
|
||||
private JwtUtil() {
|
||||
}
|
||||
|
||||
public static JwtUtil instace() {
|
||||
return Instace.jwtUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数配置:设置一次即可,多次设置会覆盖之前的
|
||||
*
|
||||
* @param key 加密key 默认:h%OG8Y3WgA5AN7&6Ke7I#C1XvneW0N8a
|
||||
* @param type 加密类型:默认JWT
|
||||
* @param iss token发行商: 默认yexuejc.com
|
||||
* @return
|
||||
*/
|
||||
public static JwtUtil config(String key, String type, String iss) {
|
||||
JwtUtil jwtUtil = instace();
|
||||
jwtUtil.JWT_SIGNATURE_KEY = key;
|
||||
jwtUtil.JWT_HEADER_TYP = type;
|
||||
jwtUtil.JWT_CLAIMS_ISS = iss;
|
||||
return jwtUtil;
|
||||
}
|
||||
|
||||
public static class Instace {
|
||||
private static JwtUtil jwtUtil = new JwtUtil();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密用KEY
|
||||
*/
|
||||
private String JWT_SIGNATURE_KEY = "h%OG8Y3WgA5AN7&6Ke7I#C1XvneW0N8a";
|
||||
/**
|
||||
* token类型
|
||||
*/
|
||||
private String JWT_HEADER_TYP = "JWT";
|
||||
/**
|
||||
* token发行商
|
||||
*/
|
||||
private String JWT_CLAIMS_ISS = "yexuejc.com";
|
||||
|
||||
/**
|
||||
* 加密内容生成token
|
||||
*
|
||||
*
|
||||
* @param subjectObj
|
||||
* @return
|
||||
*/
|
||||
public static String compact(Object subjectObj) {
|
||||
public String compact(Object subjectObj) {
|
||||
String subject = null;
|
||||
if (subjectObj instanceof String) {
|
||||
subject = (String) subjectObj;
|
||||
@@ -48,22 +96,22 @@ public class JwtUtil {
|
||||
|
||||
/**
|
||||
* 解密token为一个Map
|
||||
*
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Map<?, ?> parse(String token) {
|
||||
public Map<?, ?> parse(String token) {
|
||||
return parse(token, Map.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密token为一个指定对象
|
||||
*
|
||||
*
|
||||
* @param token
|
||||
* @param cls
|
||||
* @return
|
||||
*/
|
||||
public static <T> T parse(String token, Class<T> cls) {
|
||||
public <T> T parse(String token, Class<T> cls) {
|
||||
String subject = null;
|
||||
try {
|
||||
subject = Jwts.parser().setSigningKey(JWT_SIGNATURE_KEY).parseClaimsJws(token).getBody().getSubject();
|
||||
|
||||
@@ -5,6 +5,14 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* map相关工具
|
||||
*
|
||||
* @author maxf
|
||||
* @ClassName MapRemoveNullUtil
|
||||
* @Description
|
||||
* @date 2018/9/3 15:32
|
||||
*/
|
||||
public class MapRemoveNullUtil {
|
||||
private MapRemoveNullUtil() {
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* q钱相关工具类
|
||||
* 钱相关工具类
|
||||
*
|
||||
* @ClassName: MoneyUtils
|
||||
* @Description:
|
||||
* @author: maxf
|
||||
* @date: 2017年12月1日 下午5:33:57
|
||||
*/
|
||||
public class MoneyUtils {
|
||||
private MoneyUtils() {
|
||||
public class MoneyUtil {
|
||||
private MoneyUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
99
src/main/java/com/yexuejc/base/util/RegexUtil.java
Normal file
99
src/main/java/com/yexuejc/base/util/RegexUtil.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 正则验证
|
||||
*
|
||||
* @author yexue
|
||||
* @expl
|
||||
* @time 2017年11月9日 上午11:01:24
|
||||
*/
|
||||
public class RegexUtil {
|
||||
private RegexUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 正则规则:小写字母
|
||||
*/
|
||||
public static final String REGEX_LOWERCASE = "^$|^[a-z\\d_]+$";
|
||||
/**
|
||||
* 正则规则:中国人姓名
|
||||
* 例:张三、买买提·也罗伊
|
||||
*/
|
||||
public static final String CHINA_NAME = "^[\\u4e00-\\u9fa5]+(·[\\u4e00-\\u9fa5]+)*$";
|
||||
;
|
||||
/**
|
||||
* 短信验证码:4位数字
|
||||
*/
|
||||
public static final String REGEX_NUM4 = "^$|^\\d{4}$";
|
||||
/**
|
||||
* cvn2:3位数字
|
||||
*/
|
||||
public static final String REGEX_NUM3 = "^$|^\\d{3}$";
|
||||
/**
|
||||
* ID用 正则表达式(32位 16进制小写编码)
|
||||
*/
|
||||
public static final String REGEX_ID = "^$|^[a-f0-9]{32}$";
|
||||
/**
|
||||
* 手机用 正则表达式(首位为1,共11位数字)
|
||||
*/
|
||||
public static final String REGEX_MOBILE = "^$|^1\\d{10}$";
|
||||
/**
|
||||
* 验证是否是Json数据 正则表达式(首尾是{})
|
||||
*/
|
||||
public static final String REGEX_JSON = "^$|^\\{.*\\}$";
|
||||
/**
|
||||
* 验证预约日期时间 正则表达式(精确到半小时)
|
||||
*/
|
||||
public static final String REGEX_DATE_APPOINTMENT = "^$|^\\d{4}-[01]\\d-[0-3]\\d [0-2]\\d:(0|3)0$";
|
||||
/**
|
||||
* 日期 正则表达式
|
||||
*/
|
||||
public static final String REGEX_DATE = "^$|^\\d{4}-[01]\\d-[0-3]\\d$";
|
||||
|
||||
/**
|
||||
* 6位数字
|
||||
*/
|
||||
public static final String REGEX_NUM6 = "^$|^\\d{6}$";
|
||||
/**
|
||||
* 两位以内正整数
|
||||
*/
|
||||
public static final String REGEX_PINT2 = "^$|^[1-9]\\d{0,1}$";
|
||||
/**
|
||||
* 五位以内正整数
|
||||
*/
|
||||
public static final String REGEX_PINT5 = "^$|^[1-9]\\d{0,4}$";
|
||||
/**
|
||||
* 十位以内正整数
|
||||
*/
|
||||
public static final String REGEX_PINT10 = "^$|^[1-9]\\d{0,9}$";
|
||||
/**
|
||||
* 十位以内正整或0
|
||||
*/
|
||||
public static final String REGEX_INT10 = "^$|^[1-9]\\d{0,9}$|^0$";
|
||||
/**
|
||||
* 可有8位整数,2位小数
|
||||
*/
|
||||
public static final String REGEX_PFLOAT10_2 = "^$|^(\\d\\.\\d{1})|([1-9]\\d{0,7}(\\.\\d{1,2})?)$";
|
||||
|
||||
/**
|
||||
* STS RoleSessionName
|
||||
*/
|
||||
public static final String REGEX_STS_ROLE_SESSION_NAME = "^[a-zA-Z0-9\\.@\\-_]+$";
|
||||
|
||||
/**
|
||||
* 正则:入参验证
|
||||
*
|
||||
* @param parms
|
||||
* @param regex
|
||||
* @return
|
||||
*/
|
||||
public static boolean regex(String parms, String regex) {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(parms);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 正则验证
|
||||
*
|
||||
* @author yexue
|
||||
* @expl
|
||||
* @time 2017年11月9日 上午11:01:24
|
||||
*/
|
||||
public class RegexUtils {
|
||||
private RegexUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 正则规则:小写字母
|
||||
*/
|
||||
public static final String REGEX_LOWERCASE = "^$|^[a-z\\d_]+$";
|
||||
/**
|
||||
* 正则规则:中国人姓名
|
||||
* 例:张三、买买提·也罗伊
|
||||
*/
|
||||
public static final String CHINA_NAME = "^[\\u4e00-\\u9fa5]+(·[\\u4e00-\\u9fa5]+)*$";
|
||||
;
|
||||
/**
|
||||
* 短信验证码:4位数字
|
||||
*/
|
||||
public static final String REGEX_NUM4 = "^$|^\\d{4}$";
|
||||
/**
|
||||
* cvn2:3位数字
|
||||
*/
|
||||
public static final String REGEX_NUM3 = "^$|^\\d{3}$";
|
||||
|
||||
/**
|
||||
* 正则:入参验证
|
||||
*
|
||||
* @param parms
|
||||
* @param regex
|
||||
* @return
|
||||
*/
|
||||
public static boolean regex(String parms, String regex) {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(parms);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,9 @@ import java.util.regex.Pattern;
|
||||
* @date: 2018/5/12 19:13
|
||||
*/
|
||||
public final class StrUtil {
|
||||
private StrUtil() {
|
||||
}
|
||||
|
||||
public static char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
/**
|
||||
@@ -57,7 +60,7 @@ public final class StrUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成UUID
|
||||
* 生成32位UUID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@@ -65,6 +68,29 @@ public final class StrUtil {
|
||||
return UUID.randomUUID().toString().replaceAll("-", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成指定位数UUID
|
||||
*
|
||||
* @param length
|
||||
* @return
|
||||
*/
|
||||
public static String genUUID(int length) {
|
||||
if (length <= 32) {
|
||||
return genUUID().substring(0, length);
|
||||
} else if (length < 1) {
|
||||
return "";
|
||||
} else {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < length / 32; i++) {
|
||||
sb.append(genUUID());
|
||||
}
|
||||
if (length % 32 > 0) {
|
||||
sb.append(genUUID().substring(0, length % 32));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成11位编号,可以用作订单号,有很小几率出现重复,需要做异常处理<br/>
|
||||
* 左边第一位为正负标识:正数1 负数0<br/>
|
||||
|
||||
@@ -10,10 +10,10 @@ import java.net.URL;
|
||||
* @author: maxf
|
||||
* @date: 2017/12/28 16:12
|
||||
*/
|
||||
public class SysUtils {
|
||||
public class SysUtil {
|
||||
private static final String PROJECT_ROOT_PATH = "java.io.tmpdir";
|
||||
|
||||
private SysUtils() {
|
||||
private SysUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
103
src/main/java/com/yexuejc/base/util/ThreeDES.java
Normal file
103
src/main/java/com/yexuejc/base/util/ThreeDES.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.DESedeKeySpec;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.Key;
|
||||
|
||||
|
||||
/**
|
||||
* 3DES加解密
|
||||
*
|
||||
* @author maxf
|
||||
* @ClassName ThreeDES
|
||||
* @Description
|
||||
* @date 2018/9/3 17:09
|
||||
*/
|
||||
public class ThreeDES {
|
||||
private ThreeDES() {
|
||||
}
|
||||
|
||||
private static final String IV = "1234567-";
|
||||
private final static String encoding = "utf-8";
|
||||
|
||||
/**
|
||||
* DESCBC加密
|
||||
*
|
||||
* @param src 数据源
|
||||
* @param key 密钥
|
||||
* @return 返回加密后的数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encryptDESCBC(final String src, final String key) throws Exception {
|
||||
if (key.length() < 24) {
|
||||
throw new InvalidKeyException("key的length不得小于24");
|
||||
}
|
||||
Key deskey = null;
|
||||
DESedeKeySpec spec = new DESedeKeySpec(key.getBytes());
|
||||
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
|
||||
deskey = keyfactory.generateSecret(spec);
|
||||
|
||||
Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
|
||||
IvParameterSpec ips = new IvParameterSpec(IV.getBytes());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, deskey, ips);
|
||||
byte[] encryptData = cipher.doFinal(src.getBytes(encoding));
|
||||
return Base64.encodeBase64URLSafeString(encryptData);
|
||||
}
|
||||
|
||||
/**
|
||||
* DESCBC解密
|
||||
*
|
||||
* @param src 数据源
|
||||
* @param key 密钥
|
||||
* @return 返回解密后的原始数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decryptDESCBC(final String src, final String key) throws Exception {
|
||||
if (key.length() < 24) {
|
||||
throw new InvalidKeyException("key的length不得小于24");
|
||||
}
|
||||
Key deskey = null;
|
||||
DESedeKeySpec spec = new DESedeKeySpec(key.getBytes());
|
||||
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
|
||||
deskey = keyfactory.generateSecret(spec);
|
||||
Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
|
||||
IvParameterSpec ips = new IvParameterSpec(IV.getBytes());
|
||||
cipher.init(Cipher.DECRYPT_MODE, deskey, ips);
|
||||
|
||||
byte[] decryptData = cipher.doFinal(Base64.decodeBase64(src));
|
||||
|
||||
return new String(decryptData, encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充,不是8的倍数会填充成8的倍数
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String padding(String str) {
|
||||
byte[] oldByteArray;
|
||||
try {
|
||||
oldByteArray = str.getBytes("UTF8");
|
||||
int numberToPad = 8 - oldByteArray.length % 8;
|
||||
byte[] newByteArray = new byte[oldByteArray.length + numberToPad];
|
||||
System.arraycopy(oldByteArray, 0, newByteArray, 0,
|
||||
oldByteArray.length);
|
||||
for (int i = oldByteArray.length; i < newByteArray.length; ++i) {
|
||||
newByteArray[i] = 0;
|
||||
}
|
||||
return new String(newByteArray, "UTF8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
System.out.println("Crypter.padding UnsupportedEncodingException");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user