|
|
@ -22,25 +22,21 @@ public class JwtUtils {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String JWT_TOKEN_TYPE = "tokenType";
|
|
|
|
private static final String JWT_TOKEN_TYPE = "tokenType";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String JWT_TOKEN_TIME = "tokenTime";
|
|
|
|
|
|
|
|
|
|
|
|
//生成token
|
|
|
|
//生成token
|
|
|
|
public static String generatorToken(String passengerPhone,String identity,String tokenType) {
|
|
|
|
public static String generatorToken(String passengerPhone,String identity,String tokenType) {
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
map.put(JWT_KEY_PHONE,passengerPhone);
|
|
|
|
map.put(JWT_KEY_PHONE,passengerPhone);
|
|
|
|
map.put(JWT_KEY_IDENTITY,identity);
|
|
|
|
map.put(JWT_KEY_IDENTITY,identity);
|
|
|
|
map.put(JWT_TOKEN_TYPE,tokenType);
|
|
|
|
map.put(JWT_TOKEN_TYPE,tokenType);
|
|
|
|
//token过期时间
|
|
|
|
map.put(JWT_TOKEN_TIME,Calendar.getInstance().getTime().toString());
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
|
|
|
calendar.add(Calendar.DATE, 1);
|
|
|
|
|
|
|
|
// Date date = calendar.getTime();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JWTCreator.Builder builder = JWT.create();
|
|
|
|
JWTCreator.Builder builder = JWT.create();
|
|
|
|
map.forEach(
|
|
|
|
map.forEach(
|
|
|
|
(k, v) -> {
|
|
|
|
(k, v) -> {
|
|
|
|
builder.withClaim(k, v);
|
|
|
|
builder.withClaim(k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
//整合过期时间
|
|
|
|
|
|
|
|
// builder.withExpiresAt(date);//token保持到redis,已经设置有效期时间
|
|
|
|
|
|
|
|
//生成token
|
|
|
|
//生成token
|
|
|
|
String sign = builder.sign(Algorithm.HMAC256(SIGN));
|
|
|
|
String sign = builder.sign(Algorithm.HMAC256(SIGN));
|
|
|
|
return sign;
|
|
|
|
return sign;
|
|
|
|