| | |
| | | public static String tokenHead=""; |
| | | |
| | | /**Token有效期为1天(Token在reids中缓存时间为两倍) 单位ms*/ |
| | | public static final long EXPIRATION=(1 * 24) * 60 * 60 * 1000; //JWT的超期限时间(60*60*24*1) |
| | | public static final long EXPIRATION=(1 *12) * 60 * 60 * 1000; //JWT的超期限时间(60*60*24*1) |
| | | |
| | | /** |
| | | * token有效期还有30分钟,刷新token 单位ms |
| | |
| | | * @return |
| | | */ |
| | | public static String sign(String username,String secret,Integer identity){ |
| | | Date date=new Date(System.currentTimeMillis()+EXPIRATION*1000); |
| | | Date date=new Date(System.currentTimeMillis()+EXPIRATION); |
| | | Algorithm algorithm=Algorithm.HMAC256(secret); |
| | | return JWT.create().withClaim("username",username) |
| | | .withClaim("identity",identity).withExpiresAt(date).sign(algorithm); |