/**
* 过期时间(秒):2 天
*/
public static final long EXPIRE = 2 * 24 * 60 * 60;
/**
* 自定义:密钥
*/
private static final byte[] KEY = "xxx".getBytes();
public static String getToken(Map<String, Object> pyloadMap) {
//1、创建JWT对象
JWT jwt = JWT.create();
//2、设置携带数据
pyloadMap.forEach(jwt::setPayload);
//3、设置密钥
jwt.setKey(KEY);
//4、设置过期时间
Date expiresAt = new Date(System.currentTimeMillis() + EXPIRE * 1000);
jwt.setExpiresAt(expiresAt);
//5、返回:token
return jwt.sign();
}
06-05
1496