chao 4 سال پیش
والد
کامیت
f31deb13b8
1فایلهای تغییر یافته به همراه13 افزوده شده و 49 حذف شده
  1. 13 49
      src/main/java/com/caimei365/user/utils/JwtUtil.java

+ 13 - 49
src/main/java/com/caimei365/user/utils/JwtUtil.java

@@ -37,12 +37,8 @@ public class JwtUtil {
 
     /**
      * 生成签名,6EXPIRE_TIME过期
-     *
-     * @param **User**
-     * @param **password**
-     * @return
      */
-    public static String createToken(Integer userID) {
+    public static String createToken(Integer userId) {
         try {
             // 设置过期时间
             Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
@@ -55,30 +51,8 @@ public class JwtUtil {
             // 返回token字符串
             return JWT.create()
                     .withHeader(header)
-                    .withClaim("uid", userID)
-                    /*.withClaim("aud", mobileOrEmail)*/
-                    .withExpiresAt(date)
-                    .sign(algorithm);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
-
-        public static String createTokenBySecret(String secret) {
-        try {
-            // 设置过期时间
-            Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
-            // 私钥和加密算法
-            Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
-            // 设置头部信息
-            Map<String, Object> header = new HashMap<>(2);
-            header.put("typ", "JWT");
-            header.put("alg", "HS256");
-            // 返回token字符串
-            return JWT.create()
-                    .withHeader(header)
-                    .withClaim("uid", secret)
+                    .withClaim("uid", userId)
+                    /*.withClaim("aud", mobile)*/
                     .withExpiresAt(date)
                     .sign(algorithm);
         } catch (Exception e) {
@@ -89,9 +63,6 @@ public class JwtUtil {
 
     /**
      * 检验token是否正确
-     *
-     * @param **token**
-     * @return
      */
     public static boolean isVerify(String token) {
         try {
@@ -106,31 +77,14 @@ public class JwtUtil {
 
     /**
      * 从token解析出uid信息,用户ID
-     *
-     * @param token
-     * @return
      */
     public static int parseTokenUid(String token) {
         DecodedJWT jwt = JWT.decode(token);
         return jwt.getClaim("uid").asInt();
     }
 
-    /**
-     * 从token解析出aud信息,用户名
-     *
-     * @param token
-     * @return
-     */
-    /*public static String parseTokenAud(String token) {
-        DecodedJWT jwt = JWT.decode(token);
-        return jwt.getClaim("aud").asString();
-    }*/
-
     /**
      * 从token解析出过期日期时间
-     *
-     * @param token
-     * @return Date
      */
     public static Date paraseExpiresAt(String token) {
         DecodedJWT jwt = JWT.decode(token);
@@ -146,4 +100,14 @@ public class JwtUtil {
         return EXPIRE_TIME / 1000;
     }
 
+    /**
+     * 从token解析出aud信息,用户名
+     *
+     * @param token
+     * @return
+     */
+    /*public static String parseTokenAud(String token) {
+        DecodedJWT jwt = JWT.decode(token);
+        return jwt.getClaim("aud").asString();
+    }*/
 }