瀏覽代碼

bug修复

yinhao 4 年之前
父節點
當前提交
96cef5be00

+ 2 - 2
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/enums/AuthExceptionEnum.java

@@ -17,12 +17,12 @@ public enum AuthExceptionEnum implements AbstractBaseExceptionEnum {
     /**
      * 账号或密码为空
      */
-    ACCOUNT_PWD_EMPTY(1, "账号或密码为空,请检查account或password参数"),
+    ACCOUNT_PWD_EMPTY(1, "账号或密码为空!"),
 
     /**
      * 账号密码错误
      */
-    ACCOUNT_PWD_ERROR(2, "账号或密码错误,请检查account或password参数"),
+    ACCOUNT_PWD_ERROR(2, "账号或密码错误!"),
 
     /**
      * 验证码错误

+ 7 - 1
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/interceptor/JWTInterceptor.java

@@ -46,7 +46,13 @@ public class JWTInterceptor implements HandlerInterceptor {
             return false;
         }
 
-        Claims claims = JwtUtils.getClaims(token);
+        Claims claims = null;
+        try {
+            claims = JwtUtils.getClaims(token);
+        } catch (Exception e) {
+            response.getWriter().write(JSONObject.toJSONString(R.error(419,"token信息有误,请检查!")));
+            return false;
+        }
         Integer id = claims.get("id", Integer.class);
         if (mobileUserService == null) {
 

+ 1 - 1
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/repository/MobileUserRepository.java

@@ -14,7 +14,7 @@ public interface MobileUserRepository extends JpaRepository<MobileUser, Integer>
     MobileUser findByAccount(String account);
 
 
-    @Query(nativeQuery = true ,value = "select * from mobile_user where user_name like %?1% limit ?2 , ?3")
+    @Query(nativeQuery = true ,value = "select * from mobile_user where user_name like %?1% and grant_class != 1 limit ?2 , ?3")
     List<MobileUser> findAll(String name, Integer startPage, Integer pageSize);
 
     @Query(nativeQuery = true ,value = "select MAX(id) from mobile_user")

+ 19 - 9
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/service/impl/MobileUserServiceImpl.java

@@ -75,14 +75,22 @@ public class MobileUserServiceImpl implements MobileUserService {
 
     @Override
     public Result add(MobileUser entity){
+
+
         if (entity == null){
             return new Result(10002, ResultStatus.addNull);
         }
+
+        String account = entity.getAccount();
+        MobileUser mobileUser = mobileUserRepository.findByAccount(account);
+        if (mobileUser != null) {
+            return new Result(10001,"账号已存在,添加失败!");
+        }
         try {
             String ycgApi = mobileUnitRepository.findByShortNameLike("油车港").get(0).getApi();
             String wyApi = mobileUnitRepository.findByShortNameLike("武义").get(0).getApi();
             String wjjApi = mobileUnitRepository.findByShortNameLike("王江泾").get(0).getApi();
-
+            mobileUserRepository.save(entity);
 
             RestTemplate restTemplate  = new RestTemplate();
             Integer id = mobileUserRepository.findID();
@@ -91,10 +99,12 @@ public class MobileUserServiceImpl implements MobileUserService {
             if (grantClass ==null){
                 return new Result(10000,"msg");
             }
-            restTemplate.getForEntity(ycgApi+"/video/mobileUser/register?id="+(id+1)+"&password=123456",null);
-            restTemplate.getForEntity(wyApi+"/video/mobileUser/register?id="+(id+1)+"&password=123456",null);
-            restTemplate.getForEntity(wjjApi+"/video/mobileUser/register?id="+(id+1)+"&password=123456",null);
-            mobileUserRepository.save(entity);
+            Long start = System.currentTimeMillis();
+
+            restTemplate.getForEntity(ycgApi+"/video/mobileUser/register?account="+start+"&id="+id+"&password=123456",null);
+            restTemplate.getForEntity(wyApi+"/video/mobileUser/register?account="+start+"&id="+id+"&password=123456",null);
+            restTemplate.getForEntity(wjjApi+"/video/mobileUser/register?account="+start+"&id="+id+"&password=123456",null);
+
             return new Result(10000,ResultStatus.addSuccess);
         }catch (Exception e){
             log.error(e.getMessage(),e);
@@ -112,10 +122,10 @@ public class MobileUserServiceImpl implements MobileUserService {
         String wjjApi = mobileUnitRepository.findByShortNameLike("王江泾").get(0).getApi();
 
 
-        RestTemplate restTemplate  = new RestTemplate();
-        restTemplate.getForEntity(wjjApi+"/video/mobileUser/remove?ids="+ids,null);
-        restTemplate.getForEntity(wyApi+"/video/mobileUser/remove?ids="+ids,null);
-        restTemplate.getForEntity(ycgApi+"/video/mobileUser/remove?ids="+ids,null);
+//        RestTemplate restTemplate  = new RestTemplate();
+//        restTemplate.getForEntity(wjjApi+"/video/mobileUser/remove?ids="+ids,null);
+//        restTemplate.getForEntity(wyApi+"/video/mobileUser/remove?ids="+ids,null);
+//        restTemplate.getForEntity(ycgApi+"/video/mobileUser/remove?ids="+ids,null);
 
 
         try {

+ 40 - 19
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/util/JwtUtils.java

@@ -1,10 +1,12 @@
 package com.huimv.manager.util;
 
 import io.jsonwebtoken.*;
-import org.springframework.util.DigestUtils;
 import org.springframework.util.StringUtils;
 
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
+import java.util.Base64;
 import java.util.Date;
 
 /**
@@ -89,20 +91,6 @@ public class JwtUtils {
         return (Integer) claims.get("id");
     }
 
-    /**
-     * 根据token获取会员nickname
-     *
-     * @param request
-     * @return
-     */
-    public static String getMemberNicknameByJwtToken(HttpServletRequest request) {
-        String jwtToken = request.getHeader("token");
-        if (StringUtils.isEmpty(jwtToken)) {
-            return "";
-        }
-        Claims claims = getClaims(jwtToken);
-        return (String) claims.get("nickname");
-    }
 
     /**
      * 获取claims对象
@@ -129,7 +117,7 @@ public class JwtUtils {
             claims.getExpiration()
                     .before(new Date());
             // 需要自动刷新TOKEN
-            if ((claims.getExpiration().getTime() - System.currentTimeMillis()) > REFRESH_TIME * 1000) {
+            if ((claims.getExpiration().getTime() - System.currentTimeMillis()) < REFRESH_TIME * 1000) {
                 return -1;
             } else {
                 return 0;
@@ -141,8 +129,41 @@ public class JwtUtils {
         }
     }
 
-    public static void main(String[] args) {
-        System.out.println(DigestUtils.md5DigestAsHex("123456".getBytes()));
-//        System.out.println(JwtUtils.getJwtToken(10));
+
+    /**
+     * 获取token中的claims信息
+     *
+     * @param token
+     * @return
+     */
+    private static Jws<Claims> getJws(String token) {
+        return Jwts.parser()
+                .setSigningKey(generalKey())
+                .parseClaimsJws(token);
+    }
+
+    /**
+     * 获取payload body信息
+     *
+     * @param token
+     * @return
+     */
+    public static Claims getClaimsBody(String token) {
+        try {
+            return getJws(token).getBody();
+        }catch (ExpiredJwtException e){
+            return null;
+        }
+    }
+
+    /**
+     * 由字符串生成加密key
+     *
+     * @return
+     */
+    public static SecretKey generalKey() {
+        byte[] encodedKey = Base64.getEncoder().encode(APP_SECRET.getBytes());
+        SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
+        return key;
     }
 }