官网:https://jwt.io/introduction
@Test
public void test01(){
//HashMap map=new HashMap<>();
Calendar instance=Calendar.getInstance();
instance.add(Calendar.HOUR,1);
String token = JWT.create()
// .withHeader(map) //header
.withClaim("userId",21) //payload
.withClaim("userName","良")
.withExpiresAt(instance.getTime()) //指定令牌过期时间
.sign(Algorithm.HMAC256("!@#¥%……")); //签名
System.out.println(token);
}
@Test
public void test02(){
//创建解码对象
JWTVerifier jwtVerifier=JWT.require(Algorithm.HMAC256("!@#¥%……")).build();
DecodedJWT decodedJWT=jwtVerifier.verify("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6IuiJryIsImV4cCI6MTYxMDUyMDQ4OSwidXNlcklkIjoyMX0.PDj4tCFn4X4ZxoPxH6Tr8jtL1Yx2GD2mi0MYEebzC4E");
System.out.println(decodedJWT.getClaim("userId").asLong());
System.out.println(decodedJWT.getClaim("userName").asString());
System.out.println("过期时间:"+decodedJWT.getExpiresAt());
}



