tianboguang пре 3 година
родитељ
комит
96b8e910ac

+ 1 - 15
platform-api/src/main/java/com/platform/api/ApiBrandController.java

@@ -86,20 +86,6 @@ public class ApiBrandController extends ApiBaseAction {
         if (ObjectUtils.isEmpty(userId)) {
             return toResponsObject(401, "请先登录", "");
         }
-        // 获取用户手机号
-        UserVo userVo = apiUserService.queryObject(userId);
-        String phone = userVo.getMobile();
-        if (ObjectUtils.isEmpty(phone)) {
-            logger.error("用户未绑定手机号:{}", userId);
-            return toResponsSuccess(new ApiPageUtils(new PageInfo(new ArrayList<BrandVo>())));
-        }
-        // 根据手机号获取系统用户ID
-        TbUser userEntity = zhiHouseService.queryByUserMobile(phone);
-        if (ObjectUtils.isEmpty(userEntity)) {
-            logger.error("获取系统用户失败:{}", phone);
-            return toResponsSuccess(new ApiPageUtils(new PageInfo(new ArrayList<BrandVo>())));
-        }
-        userId = userEntity.getId();
 
         ApiPageUtils result = null;
 
@@ -176,7 +162,7 @@ public class ApiBrandController extends ApiBaseAction {
             if(type == 21){
                 requestScene.setUserId(-1L);
             }else if(params.containsKey("userId")){
-                requestScene.setPhone(phone);
+                requestScene.setPhone(getUserName());
             }
 
             if(params.containsKey("name"))

+ 17 - 6
platform-api/src/main/java/com/platform/util/ApiBaseAction.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.platform.entity.TokenEntity;
 import com.platform.interceptor.AuthorizationInterceptor;
 import com.platform.service.TokenService;
+import com.platform.utils.JwtUtil;
+import io.jsonwebtoken.Claims;
 import org.apache.shiro.authz.UnauthorizedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -161,11 +163,20 @@ public class ApiBaseAction {
      */
     public Long getUserId() {
         String token = request.getHeader(AuthorizationInterceptor.LOGIN_TOKEN_KEY);
-        //查询token信息
-        TokenEntity tokenEntity = tokenService.queryByToken(token);
-        if (tokenEntity == null || tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()) {
-            return null;
-        }
-        return tokenEntity.getUserId();
+
+        Claims claims = JwtUtil.parseJWT(token);
+        return Long.valueOf(claims.get("id", String.class));
+    }
+
+    /**
+     * 获取请求的用户Id
+     *
+     * @return 客户端Ip
+     */
+    public String getUserName() {
+        String token = request.getHeader(AuthorizationInterceptor.LOGIN_TOKEN_KEY);
+
+        Claims claims = JwtUtil.parseJWT(token);
+        return claims.get("username", String.class);
     }
 }