package com.gkhy.safePlatform.account.utils;
|
|
import com.google.common.base.Charsets;
|
import com.google.common.hash.Hashing;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
|
|
/**
|
* @Description: jwt工具类
|
* @date 2022/6/14 10:34
|
*/
|
@Component
|
public class TokenUtil {
|
|
|
@Value("${token.secret}")
|
private String secret;
|
@Value("${token.expiration}")
|
private Long expiration;
|
@Value("${token.refreshExpiration}")
|
private Long refreshExpiration;
|
@Value("${token.header}")
|
private String header;
|
@Value("${token.tokenHead}")
|
private String tokenHead;
|
@Value("${token.loginUserHeader}")
|
private String loginUserHeader;
|
|
/**
|
* @Description: 根据用户信息生成token
|
*/
|
public static String makeToken(String username, Long userId) {
|
long current = System.currentTimeMillis();
|
return Hashing.md5().newHasher().putString(username + userId + current, Charsets.UTF_8).hash().toString();
|
}
|
|
|
|
/**
|
* @Description: 刷新token
|
*/
|
public static String makeRefreshToken(String username, Long userId) {
|
long current = System.nanoTime();
|
return Hashing.md5().newHasher().putString(username + userId + current, Charsets.UTF_8).hash().toString();
|
}
|
|
|
public String getSecret() {
|
return secret;
|
}
|
|
public void setSecret(String secret) {
|
this.secret = secret;
|
}
|
|
public Long getExpiration() {
|
return expiration;
|
}
|
|
public void setExpiration(Long expiration) {
|
this.expiration = expiration;
|
}
|
|
public Long getRefreshExpiration() {
|
return refreshExpiration;
|
}
|
|
public void setRefreshExpiration(Long refreshExpiration) {
|
this.refreshExpiration = refreshExpiration;
|
}
|
|
public String getHeader() {
|
return header;
|
}
|
|
public void setHeader(String header) {
|
this.header = header;
|
}
|
|
public String getTokenHead() {
|
return tokenHead;
|
}
|
|
public void setTokenHead(String tokenHead) {
|
this.tokenHead = tokenHead;
|
}
|
|
public String getLoginUserHeader() {
|
return loginUserHeader;
|
}
|
|
public void setLoginUserHeader(String loginUserHeader) {
|
this.loginUserHeader = loginUserHeader;
|
}
|
}
|