Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JWT 工具类
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import net.xdclass.xdvideo.domain.User;
import java.util.Date;
* jwt工具类
public class JwtUtils {
public static final String SUBJECT = "xdclass";
public static final long EXPIRE = 1000*60*60*24*7; //过期时间,毫秒,一周
public static final String APPSECRET = "xd666";
* 生成jwt
* @param user
* @return
public static String geneJsonWebToken(User user){
if(user == null || user.getId() == null || user.getName() == null
|| user.getHeadImg()==null){
return null;
String token = Jwts.builder().setSubject(SUBJECT)
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis()+EXPIRE))
return token;
* 校验token
* @param token
* @return
public static Claims checkJWT(String token ){
final Claims claims = Jwts.parser().setSigningKey(APPSECRET).
return claims;
}catch (Exception e){ }
return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.