jwt 整理
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.78</version>
</dependency>
@Slf4j
public class JwtUtil {
private static int EXPIRE_TIME;
private static String TOKEN_SECRET;
private static String USER_NAME;
static {
ResourceBundle bundle = ResourceBundle.getBundle("jwt");
EXPIRE_TIME =Integer.parseInt( bundle.getString("EXPIRE_TIME"));
TOKEN_SECRET = bundle.getString("TOKEN_SECRET");
USER_NAME = bundle.getString("USER_NAME");
}
public static String createToken(User user) {
Calendar nowTime = Calendar.getInstance();
nowTime.add(Calendar.MINUTE, EXPIRE_TIME);
Date expiresDate = nowTime.getTime();
String userJson = JSON.toJSONString(user);
return JWT.create().withAudience(user.getId()+