forked from fdzcxy212206413/jty
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
913 B
35 lines
913 B
package jty.expressdistributionsystem.utils;
|
|
|
|
import com.auth0.jwt.JWT;
|
|
import com.auth0.jwt.algorithms.Algorithm;
|
|
|
|
import java.util.Date;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* JWT检验
|
|
*/
|
|
public class JwtUtil {
|
|
|
|
private static final String KEY = "catSys";
|
|
|
|
// 接收业务数据,生成token并返回
|
|
public static String genToken(Map<String, Object> claims) {
|
|
return JWT.create()
|
|
.withClaim("claims", claims)
|
|
// 一天过期
|
|
.withExpiresAt(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24))
|
|
.sign(Algorithm.HMAC256(KEY));
|
|
}
|
|
|
|
// 接收token,验证token,并返回业务数据
|
|
public static Map<String, Object> parseToken(String token) {
|
|
return JWT.require(Algorithm.HMAC256(KEY))
|
|
.build()
|
|
.verify(token)
|
|
.getClaim("claims")
|
|
.asMap();
|
|
}
|
|
|
|
}
|