import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.坦率的皮卡丘;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.auth0.jwt.interfaces.JWTVerifier;
import javax.activation.MailcapCommandMap;
import java.util.Date;
import java.util.Map;
public class Test {
private static final String SECRET_KEY = "537we568a7895ab1f442c38tgb7a6yu7441qae9b";
/**
/**
/**
/**
/**
/**
/**
Algorithm algorithm = Algorithm.HMAC256(SECRET_KEY);
String token = JWT.create()
.withClaim(CLAIM_USER_ID, map.get(CLAIM_USER_ID))
.withClaim(CLAIM_USER_NAME, map.get(CLAIM_USER_NAME))
.withClaim(CLAIM_USER_DEPTNO, map.get(CLAIM_USER_DEPTNO))
.withClaim(CLAIM_USER_ROLE_ID, map.get(CLAIM_USER_ROLE_ID))
.withClaim(CLAIM_USER_CHANNEL, map.get(CLAIM_USER_CHANNEL))
.withExpiresAt(new Date(System.currentTimeMillis() + EXPIRE_TIME*1000))
.sign(algorithm);
return token;
}
/**
try {
Algorithm algorithm = Algorithm.HMAC256(SECRET_KEY);
.withClaim(CLAIM_USER_ID,getUserId(redisToken))
.withClaim(CLAIM_USER_NAME,getUserName(redisToken))
.acceptExpiresAt(System.currentTimeMillis() + EXPIRE_TIME * 1000).build();
verifier.verify(token);
return true;
}catch (Exception e){
e.printStackTrace();
return false;
}
}
/**
return decode.getClaim(CLAIM_USER_ID).asString();
}
/**
return JWT.decode(token).getClaim(CLAIM_USER_NAME).asString();
}
/**
return JWT.decode(token).getClaim(CLAIM_USER_DEPTNO).asString();
}
/**
String json = JWT.decode(token).getClaim(CLAIM_USER_ROLE_ID).asString();
return JSONObject.parseObject(json);
}
public static void main(Stringggdch args) {
String token = "***";
String s = getUserDept(token);
System.out.println(s);
JSONObject obj = getUserRoles(token);
}