feat(修改): 🐛 JWT每次生成都一样
This commit is contained in:
parent
d02c498011
commit
77ff5c4cfc
|
@ -28,6 +28,12 @@
|
|||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.14</version>
|
||||
</dependency>
|
||||
<!-- 解决 javax.xml.bind 错误 -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<!-- knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
|
|
|
@ -4,22 +4,264 @@ import io.jsonwebtoken.*;
|
|||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JwtHelper {
|
||||
// 时间 按天 计算
|
||||
private static final long tokenExpiration = 24 * 60 * 60 * 1000;
|
||||
// JWT 的 秘钥
|
||||
private static final String tokenSignKey = "Bunny-Java-Template";
|
||||
// 默认主题
|
||||
private static final String subject = "Bunny";
|
||||
// 默认时间
|
||||
private static final Date time = new Date(System.currentTimeMillis() + tokenExpiration * 7);
|
||||
|
||||
public static String createToken(Long userId, String userName, Integer day) {
|
||||
/**
|
||||
* 使用默认主题,默认时间,默认秘钥,创建自定义集合token
|
||||
*
|
||||
* @param map 集合
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map) {
|
||||
return Jwts.builder()
|
||||
.setSubject("Bunny-USER")
|
||||
.setSubject(subject)
|
||||
.setExpiration(time)
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.compressWith(CompressionCodecs.GZIP).compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用默认主题,默认秘钥,自定义时间,创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param time 过期时间
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, Date time) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.setExpiration(time)
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.compressWith(CompressionCodecs.GZIP).compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用默认主题,默认秘钥,自定义时间,创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param day 过期时间
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, Integer day) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.setExpiration(new Date(System.currentTimeMillis() + tokenExpiration * day))
|
||||
.claim("userId", userId)
|
||||
.claim("userName", userName)
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.compressWith(CompressionCodecs.GZIP).compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用默认主题,默认秘钥,自定义key,创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param tokenSignKey 自定义key
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, String tokenSignKey) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.setExpiration(time)
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.compressWith(CompressionCodecs.GZIP).compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用自定义主题,自定义时间,创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param subject 主题
|
||||
* @param time 过期时间
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, String subject, Date time) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.setExpiration(time)
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param subject 主题
|
||||
* @param tokenSignKey 过期时间
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, String subject, String tokenSignKey) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.setExpiration(time)
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.compressWith(CompressionCodecs.GZIP).compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param tokenSignKey 主题
|
||||
* @param time 过期时间
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, String tokenSignKey, Integer time) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.setExpiration(new Date(System.currentTimeMillis() + tokenExpiration * time))
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param subject 主题
|
||||
* @param day 过期时间
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, String subject, String tokenSignKey, Integer day) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.setExpiration(new Date(System.currentTimeMillis() + tokenExpiration * day))
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建集合形式token
|
||||
*
|
||||
* @param map 集合
|
||||
* @param subject 主题
|
||||
* @param time 过期时间
|
||||
* @return token
|
||||
*/
|
||||
public static String createTokenWithMap(Map<String, Object> map, String subject, String tokenSignKey, Date time) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.setExpiration(time)
|
||||
.setClaims(map)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名和ID创建token
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param userName 用户名
|
||||
* @param day 过期时间
|
||||
* @return token值
|
||||
*/
|
||||
public static String createToken(Long userId, String userName, Integer day) {
|
||||
return Jwts.builder()
|
||||
.setSubject(subject)
|
||||
.setExpiration(new Date(System.currentTimeMillis() + tokenExpiration * day))
|
||||
.claim("userId", userId)
|
||||
.claim("userName", userName)
|
||||
.setId(UUID.randomUUID().toString())
|
||||
.signWith(SignatureAlgorithm.HS256, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用token获取map集合,使用默认秘钥
|
||||
*
|
||||
* @param token token
|
||||
* @return map集合
|
||||
*/
|
||||
public static Map<String, Object> getTokenByMap(String token) {
|
||||
if (!StringUtils.hasText(token)) return null;
|
||||
Claims claims = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token).getBody();
|
||||
|
||||
// 将 body 值转为map
|
||||
return new HashMap<>(claims);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用token获取map集合
|
||||
*
|
||||
* @param token token
|
||||
* @param signKey 秘钥
|
||||
* @return map集合
|
||||
*/
|
||||
public static Map<String, Object> getTokenByMap(String token, String signKey) {
|
||||
if (!StringUtils.hasText(token)) return null;
|
||||
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(signKey).parseClaimsJws(token);
|
||||
Claims body = claimsJws.getBody();
|
||||
// 将 body 值转为map
|
||||
return new HashMap<>(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据token获取主题
|
||||
*
|
||||
* @param token token
|
||||
* @return 主题
|
||||
*/
|
||||
public static String getTokenBySubject(String token) {
|
||||
if (!StringUtils.hasText(token)) return null;
|
||||
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token);
|
||||
Claims body = claimsJws.getBody();
|
||||
|
||||
return body.getSubject();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据token获取主题
|
||||
*
|
||||
* @param token token
|
||||
* @return 主题
|
||||
*/
|
||||
public static String getTokenBySubject(String token, String tokenSignKey) {
|
||||
if (!StringUtils.hasText(token)) return null;
|
||||
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token);
|
||||
Claims body = claimsJws.getBody();
|
||||
|
||||
return body.getSubject();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据token获取用户ID
|
||||
*
|
||||
* @param token token
|
||||
* @return 用户ID
|
||||
*/
|
||||
public static Long getUserId(String token) {
|
||||
if (!StringUtils.hasText(token)) return null;
|
||||
|
||||
|
@ -29,6 +271,12 @@ public class JwtHelper {
|
|||
return Long.valueOf(String.valueOf(claims.get("userId")));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据token获取用户名
|
||||
*
|
||||
* @param token token
|
||||
* @return 用户名
|
||||
*/
|
||||
public static String getUsername(String token) {
|
||||
if (!StringUtils.hasText(token)) return "";
|
||||
|
||||
|
@ -37,14 +285,37 @@ public class JwtHelper {
|
|||
return (String) claims.get("userName");
|
||||
}
|
||||
|
||||
public static void removeToken(String token) {
|
||||
// jwttoken无需删除,客户端扔掉即可。
|
||||
/**
|
||||
* 判断token是否过期
|
||||
*
|
||||
* @param token token
|
||||
* @return 是否过期
|
||||
*/
|
||||
public static boolean isExpired(String token) {
|
||||
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token);
|
||||
Date expiration = claimsJws.getBody().getExpiration();
|
||||
|
||||
return expiration != null && expiration.before(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断token是否过期
|
||||
*
|
||||
* @param token token
|
||||
* @return 是否过期
|
||||
*/
|
||||
public static boolean isExpired(String token, String tokenSignKey) {
|
||||
Jws<Claims> claimsJws = Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token);
|
||||
Date expiration = claimsJws.getBody().getExpiration();
|
||||
|
||||
return expiration != null && expiration.before(new Date());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String token = JwtHelper.createToken(7L, "admin", 7);
|
||||
System.out.println(token);
|
||||
// token = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_6tWKi5NUrJScirNy6vUDQ12DVLSUUqtKFCyMjQ3MTc0NrYwNddRKi1OLfJMUbKyNDIwNLQwMDAzg4j5JeamAjUbGhtaWhoYGJqaOBQW6iXn5yrVAgCrO9jLWAAAAA.DS1wYprXGoIMrjtUWfDSN9AG5gWoRZ17oAgcvC0kwag";
|
||||
System.out.println(JwtHelper.getUserId(token));
|
||||
System.out.println(JwtHelper.getUsername(token));
|
||||
// System.out.println(JwtHelper.getUserId(token));
|
||||
// System.out.println(JwtHelper.getUsername(token));
|
||||
}
|
||||
}
|
|
@ -11,6 +11,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
public class IndexController {
|
||||
@GetMapping()
|
||||
public String index() {
|
||||
return "欢迎访问 Bunny Template 网关服务";
|
||||
return "欢迎访问 Bunny Template 网关服务 微服务模板 欢迎去Gitee:https://gitee.com/BunnyBoss/java-mirror-server.git";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
public class IndexController {
|
||||
@RequestMapping("")
|
||||
public String index() {
|
||||
return "欢迎访问BunnyBBS";
|
||||
return "欢迎访问 Bunny Template 微服务模板 欢迎去Gitee:https://gitee.com/BunnyBoss/java-mirror-server.git";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
public class IndexController {
|
||||
@GetMapping("")
|
||||
public String index() {
|
||||
return "欢迎访问 Bunny Template 微服务模板";
|
||||
return "欢迎访问 Bunny Template 微服务模板 欢迎去Gitee:https://gitee.com/BunnyBoss/java-mirror-server.git";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
package cn.bunny.jwt;
|
||||
|
||||
import cn.bunny.common.service.utils.JwtHelper;
|
||||
import cn.bunny.entity.system.user.User;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
class JwtHelperTest {
|
||||
private static final String key = "my-key";
|
||||
private static final String subject = "my-subject";
|
||||
|
||||
private static Map getMap() {
|
||||
User user = new User();
|
||||
user.setId(123L);
|
||||
user.setAvatar("http://129.211.31.58:4000/#/chat");
|
||||
user.setEmail("user@example.com");
|
||||
user.setNickName("user@example.com");
|
||||
|
||||
// 将对象转为map
|
||||
Map map = JSONObject.parseObject(JSONArray.toJSONString(user), Map.class);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTokenWithMap() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap());
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateTokenWithMap() {
|
||||
// 自定义key
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), new Date(System.currentTimeMillis() + 666666));
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTokenWithMap0() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), 1);
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateTokenWithMap1() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), key);
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateTokenWithMap2() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), subject, key);
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateTokenWithMap3() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), subject, 7);
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createToken1() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), subject, new Date());
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createToken2() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), subject, key, new Date());
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createToken3() {
|
||||
// 自定义 天数过期
|
||||
String token = JwtHelper.createTokenWithMap(getMap(), subject, key, 1);
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTokenByMap() {
|
||||
// createTokenWithMap 的 token
|
||||
String createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MQQqAIBBA0btM21BHC8pVVxlsIClNzCKI7p4HaP_ffyB6t0YKDBbOg_PEN4W0sXB7gBb8DBa1aYEuKpRrtJSSrJSoR6ERhUHRD7ZTSslGuoVKRRzIb3-_9wN8w_-EbwAAAA.WFmbbjfwGycJp6-Ak8uoYdIO0R8brA8rmh5ZrG1kawI";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MTQ6DIBBA4btMt_IzKgqseoLeYQSMtGKJpU0T493LAbr-Xt4BmXZKYI-zgS26x41SAAvvV9iv4Uspr4G7Z4IG6EOF9mpLKdkKga3hLSLvkCtteymluAi3UKlt9GCx7RoIieL6_3cvscI8T1orRwydUazHwTOj1cAmrzTSOKoRNZw_Uq-ijacAAAA.kOxzGz-821wJo-hRJ2FRZQ4ytLfU2JEVOSf-8EvSJLc";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MQQrCMBBG4buM25BkUgWdlSfwDj_pQIMdDTEVofTu9gBdv4-3UkWDkaybo1fJzwdMSWj5aLvrD1Zn9flt5AhfdLS9Tb1XCYHTzSdmP7C_XOUcYwynkCf03ZaRhNPgSA1lPvptf8HXaaZ6AAAA.m-m4uaNM1LhyCcQyncr7tVKcNA5dAE0SLUeNI8THq7w";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MTQ6CMBBA4buMW_ozpa3QlSfwDkM7hipFgtWYEO4uB3D9vbwNFlqpQNj2BuYcH1cqDAHeL14v_KWyTCzjs0AD9KFK62FjrUtQCk0vDaJsUbouWK21Oqk4Uj3anCCgaRvgQnn6_7vXfADq5J3rOtHffCusxV4MNGjB3jEm68_WGNh_tMDYSqcAAAA.G6ARBhqRNiSKHYtEdMW_Qh1d5lAa0CzgXEjlxN3NRLU";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MTQ7CIBBA4buM2_IzQCuw8gTeYQqTFC3aVDQmTe9uD-D6e3kbLLRShbjtHTxKul-pMkR4v3i98JfqMrNMzwod0IcarYdNrS1RKTRBGkRpUfY-Oq21Oqk0UTvakiGisR1wpTL__91aOWDMIRtGFnq0Xrg0oBh7rwUOIZPzaPV5gP0HuCPau6cAAAA.5CGFhEz1i9RLKfFMYHA7cOg3sdfFEDZnqbBHSP9R_XY";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MTQ6CMBBA4buMW_oz7VChK0_gHcZSQpUiwWpMCHe3B3D9vbwdVt44g9-PBpYUHlfOETy8X3G7xC_ndY4yPDM0wB8uvFWbSlm9Umh6aRClRdl2nrTW6qTCxKW2aQCPxjYQM6f5_-9eUgXqWzThRmKk8SzIaBSMzgnXsuuI-sFqguMH0SvcYacAAAA.qW_gqkc8RQJM-UbFVj7xldSEv1RORO4qlw6VMrTEmM0";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MSw7CIBRA0b08p_yhFBi5AvfwApiiRQmiMWm6d7sAx-fmbtCwY4Ww7QQeJd4vWDMEeL9yP-cv1rZmFp8VCOAHB_bDljFa4Fwqz5SUTEs2uWCEEPzE44LjaEuCIJUmkCuW9f_vNsoBaJ1yYnZ0Rqep8VlRnESi3khrklFeXC3sP3hOgQ2nAAAA.bkPBbfpLd21eaJE2gjzniUx5n9VvCqWSY_zBiu8oO9k";
|
||||
|
||||
Map<String, Object> tokenByMap = JwtHelper.getTokenByMap(createTokenWithMapToken);
|
||||
|
||||
// 转为Java实体对戏那个
|
||||
User user = JSONObject.parseObject(JSONObject.toJSONString(tokenByMap), User.class);
|
||||
|
||||
System.out.println(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTokenByMap1() {
|
||||
String createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MSw6CMBRG4b1cp_R5i0BHrsA9_K01VKkSrMaEsHdZgOPv5Kw0Y0Ehv24NPXK8n1ESeXq_0nJKX5R5SjI-CzWEDyqW3cZaZ6-UsYO0xkg2su2901qrg4oj6t7mC3ljuaFUkKf_v1vNO8QIx51l0YIhXOicCGAnrr3trT4OgVOg7Qcl-35JpwAAAA.brAkeCBAcsRqKRbuvfrH-toHOhji6YcTaVPBYIxAdFo";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MyQ3CMBBA0V6Ga7yMY8vLiQroYXBGiiGGyBiEFKV3UgDn9_U3WKlRhbTtAzxKvl-oMiR4v7id-Ut1XVjmZ4UB6EOd2mFz72tSCk2UBlGOKF1IVmutTirP1I-2TJDQjANwpbL8_916OcCbq7dkWeTAXlgfJhEnp4ULGckjZW0i7D9IMrwJpwAAAA.VmohGapOUVUNFQ9XVUX-QALeFQLad1f3Hp8NbcVZuMI";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MTQ7CIBBA4buMW36nQAsrT-AdpoApWrSpaEya3t0ewPX38jZYaKUKYdsZPEq8X6hmCPB-5fWcv1SXOYv4rMCAPtRoPWxqbQlSavQCtRadFnYIRiklTzJO1I62JAgaOwa5Upn__26tHIBjTOSvxB2agRurDCeTHMceE1nne6dH2H-VOEqApwAAAA.j5BcFLT-2HENeYS8LvD27tyRnI1rE-iFzjBy1iY02T4";
|
||||
createTokenWithMapToken = "eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_23MTQ7CIBBA4buM2_JXWkpZeQLvMNIhRYsSRGPS9O5yANffy9shY8EEbj86eER_v2AicPB-UTnTF1PeiPtngg7wgxVLs7XW7IRQ_cx7pbhWfLRukFKKk_Ar1tbGBZzqdQeUMG7_f7caG1zlZCZDyGavFzZ4MzC0ZmIWQ1DWeBtGguMHw7854qcAAAA.V4VLIJ7vUqnfd1LeQkXa3t8V_376DWVAA_g0PE_6_S8";
|
||||
|
||||
Map<String, Object> tokenByMap = JwtHelper.getTokenByMap(createTokenWithMapToken, key);
|
||||
// 转为Java实体对戏那个
|
||||
User user = JSONObject.parseObject(JSONObject.toJSONString(tokenByMap), User.class);
|
||||
System.out.println(user);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue