|
|
|
@ -20,9 +20,10 @@ public class JwtUtil {
|
|
|
|
|
*
|
|
|
|
|
* @param identity_id 身份ID
|
|
|
|
|
* @param person_id 人员ID
|
|
|
|
|
* @param bureau_id 机构ID
|
|
|
|
|
* @return JWT签名
|
|
|
|
|
*/
|
|
|
|
|
public static String generateToken(int identity_id, String person_id) {
|
|
|
|
|
public static String generateToken(int identity_id, String person_id, String bureau_id) {
|
|
|
|
|
// 获取当前日期和时间
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
// 格式化日期
|
|
|
|
@ -30,6 +31,7 @@ public class JwtUtil {
|
|
|
|
|
claims.put("create_time", now.toString());
|
|
|
|
|
claims.put("identity_id", identity_id);
|
|
|
|
|
claims.put("person_id", person_id);
|
|
|
|
|
claims.put("bureau_id", bureau_id);
|
|
|
|
|
return AUTHORIZATION_STARTER + Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS256, SECRET).compact();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -58,13 +60,14 @@ public class JwtUtil {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
GwApplication gw = new GwApplication();
|
|
|
|
|
String token = generateToken(4, "0b64e31e-a85e-43eb-ba5f-3088d986a8da");
|
|
|
|
|
String token = generateToken(4, "0b64e31e-a85e-43eb-ba5f-3088d986a8da","3f7f4c90-645a-4fb9-9902-447846cf1dcc");
|
|
|
|
|
/**
|
|
|
|
|
结论:
|
|
|
|
|
1、JWT的里面有两个关键信息,一个是identity_id,另一个是person_id
|
|
|
|
|
1、JWT的里面有三个关键信息,一个是identity_id,另一个是person_id,还有一个bureau_id
|
|
|
|
|
*/
|
|
|
|
|
Claims claims = getClaims(token);
|
|
|
|
|
System.out.println(claims.get("identity_id"));
|
|
|
|
|
System.out.println(claims.get("person_id"));
|
|
|
|
|
System.out.println(claims.get("bureau_id"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|