|
|
@ -102,6 +102,10 @@ public class TokenProvider {
|
|
|
|
.compact();
|
|
|
|
.compact();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
JwtUser jwtUser = getJWTUserByZhiYun("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb2xsZWdlIjoi5ryU56S65a2m6ZmiIiwiaWNpYnRTY2hvb2xJZCI6NCwibWQ1UHdkIjoiNDYtRjktNEMtOEQtRTEtNEYtQjMtNjYtODAtODUtMDctNjgtRkYtMUItN0YtMkEiLCJyb2xlaWQiOiI0Iiwic2V4Ijoi55S3IiwidXNlcklkIjoiNDg3Iiwic3R1ZGVudElkIjoiNDA0OCIsInBhc3N3b3JkIjoiMTIzcXdlIiwiY2xhc3NJZCI6IjIxMSIsImljaWJ0Q2xhc3NJZCI6MjA0LCJtYWpvciI6IuS6p-WTgea8lOekuuS4k-S4miIsInNjaG9vbCI6IuWkqeaLqeWkp-WtpiIsInNjaG9vbElkIjoiMjMyIiwibmFtZSI6InR6czAwMSIsInN0dWRlbnRObyI6InR6czAwMSIsImFwcGxpY2F0aW9uSWQiOiIxMTkiLCJjbGFzcyI6IuWkqeaLqea8lOekujHnj60iLCJ1c2VybmFtZSI6InR6czAwMSJ9.p6Uu15B1zNzuuCMOkDTkMksvjU6EOvGWprMWuJB0OII");
|
|
|
|
|
|
|
|
System.out.println(jwtUser);
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 解析智云平台的token
|
|
|
|
* 解析智云平台的token
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -124,6 +128,8 @@ public class TokenProvider {
|
|
|
|
jwtUser.setClassId(Integer.valueOf(claims.get("classId")==null?"0":claims.get("classId").toString()));
|
|
|
|
jwtUser.setClassId(Integer.valueOf(claims.get("classId")==null?"0":claims.get("classId").toString()));
|
|
|
|
jwtUser.setSchoolId(Integer.valueOf(claims.get("schoolId")==null?"0":claims.get("schoolId").toString()));
|
|
|
|
jwtUser.setSchoolId(Integer.valueOf(claims.get("schoolId")==null?"0":claims.get("schoolId").toString()));
|
|
|
|
jwtUser.setUsername(claims.get("username").toString());
|
|
|
|
jwtUser.setUsername(claims.get("username").toString());
|
|
|
|
|
|
|
|
jwtUser.setPassword(claims.get("password").toString());
|
|
|
|
|
|
|
|
jwtUser.setStudentId(claims.get("studentNo").toString());
|
|
|
|
return jwtUser;
|
|
|
|
return jwtUser;
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new UnAuthorizedException("token解析失败");
|
|
|
|
throw new UnAuthorizedException("token解析失败");
|
|
|
@ -132,41 +138,41 @@ public class TokenProvider {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成智云平台32字节密钥
|
|
|
|
//生成智云平台32字节密钥
|
|
|
|
public static void main(String[] args) {
|
|
|
|
// public static void main(String[] args) {
|
|
|
|
// String prefix = "zy_wh_mnjy_";
|
|
|
|
//// String prefix = "zy_wh_mnjy_";
|
|
|
|
// String generatedKey = generateKey(prefix);
|
|
|
|
//// String generatedKey = generateKey(prefix);
|
|
|
|
// System.out.println("Generated Key: " + generatedKey);
|
|
|
|
//// System.out.println("Generated Key: " + generatedKey);
|
|
|
|
// getJWTUserByZhiYun(null);
|
|
|
|
//// getJWTUserByZhiYun(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成一个新的长度为512字节的随机密钥供智云平台解析token
|
|
|
|
|
|
|
|
// int keyLength = 512; // 根据您的要求进行调整
|
|
|
|
|
|
|
|
// KeyGenerator keyGenerator;
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// keyGenerator = KeyGenerator.getInstance("HmacSHA512");
|
|
|
|
|
|
|
|
// keyGenerator.init(keyLength);
|
|
|
|
|
|
|
|
// SecretKey secretKey = keyGenerator.generateKey();
|
|
|
|
|
|
|
|
// byte[] secretBytes = secretKey.getEncoded();
|
|
|
|
|
|
|
|
// String secret = Base64.getUrlEncoder().withoutPadding().encodeToString(secretBytes);
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// System.out.println("Generated Secret: " + secret);
|
|
|
|
//
|
|
|
|
// } catch (NoSuchAlgorithmException e) {
|
|
|
|
////生成一个新的长度为512字节的随机密钥供智云平台解析token
|
|
|
|
// e.printStackTrace();
|
|
|
|
//// int keyLength = 512; // 根据您的要求进行调整
|
|
|
|
// }
|
|
|
|
//// KeyGenerator keyGenerator;
|
|
|
|
|
|
|
|
//// try {
|
|
|
|
JwtUser user = new JwtUser();
|
|
|
|
//// keyGenerator = KeyGenerator.getInstance("HmacSHA512");
|
|
|
|
user.setUserId("486");
|
|
|
|
//// keyGenerator.init(keyLength);
|
|
|
|
user.setRoleId(3);
|
|
|
|
//// SecretKey secretKey = keyGenerator.generateKey();
|
|
|
|
user.setUsername("tzt006");
|
|
|
|
//// byte[] secretBytes = secretKey.getEncoded();
|
|
|
|
user.setSchoolId(1);
|
|
|
|
//// String secret = Base64.getUrlEncoder().withoutPadding().encodeToString(secretBytes);
|
|
|
|
user.setSchoolName("天择大学");
|
|
|
|
////
|
|
|
|
user.setCollegeId(1);
|
|
|
|
//// System.out.println("Generated Secret: " + secret);
|
|
|
|
user.setCollegeName("演示学院");
|
|
|
|
//// } catch (NoSuchAlgorithmException e) {
|
|
|
|
user.setMajorId(1);
|
|
|
|
//// e.printStackTrace();
|
|
|
|
user.setMajorName("产品演示专业");
|
|
|
|
//// }
|
|
|
|
String token = createZHIYUNToken(user);
|
|
|
|
//
|
|
|
|
System.out.println(token);
|
|
|
|
// JwtUser user = new JwtUser();
|
|
|
|
}
|
|
|
|
// user.setUserId("486");
|
|
|
|
|
|
|
|
// user.setRoleId(3);
|
|
|
|
|
|
|
|
// user.setUsername("tzt006");
|
|
|
|
|
|
|
|
// user.setSchoolId(1);
|
|
|
|
|
|
|
|
// user.setSchoolName("天择大学");
|
|
|
|
|
|
|
|
// user.setCollegeId(1);
|
|
|
|
|
|
|
|
// user.setCollegeName("演示学院");
|
|
|
|
|
|
|
|
// user.setMajorId(1);
|
|
|
|
|
|
|
|
// user.setMajorName("产品演示专业");
|
|
|
|
|
|
|
|
// String token = createZHIYUNToken(user);
|
|
|
|
|
|
|
|
// System.out.println(token);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public static String generateKey(String prefix) {
|
|
|
|
public static String generateKey(String prefix) {
|
|
|
|
String characters = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
|
String characters = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
|