From 9332621f5a70e2c05bcd6ec08ec97277fbb21efc Mon Sep 17 00:00:00 2001 From: hanrenchun Date: Tue, 2 Dec 2025 13:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9token=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/util/aspect/responseAspect.java | 57 ------------------- .../controller/SmallProgramController.java | 3 +- .../web/controller/aspect/responseAspect.java | 55 ------------------ .../controller/system/SysLoginController.java | 2 + .../framework/web/service/TokenService.java | 2 +- 5 files changed, 4 insertions(+), 115 deletions(-) delete mode 100644 gather-app/src/main/java/com/ruoyi/business/util/aspect/responseAspect.java delete mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/aspect/responseAspect.java diff --git a/gather-app/src/main/java/com/ruoyi/business/util/aspect/responseAspect.java b/gather-app/src/main/java/com/ruoyi/business/util/aspect/responseAspect.java deleted file mode 100644 index 0751035..0000000 --- a/gather-app/src/main/java/com/ruoyi/business/util/aspect/responseAspect.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.ruoyi.business.util.aspect; - -import cn.hutool.core.util.DesensitizedUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import com.ruoyi.common.core.page.TableDataInfo; -import lombok.RequiredArgsConstructor; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.stereotype.Component; - -import java.lang.reflect.Field; -import java.util.List; - -@Aspect -@Component -@RequiredArgsConstructor -public class responseAspect { - - @Around("execution(* com.ruoyi.database.controller.SmallProgramController.*(..))") - public TableDataInfo around(ProceedingJoinPoint joinPoint) throws Throwable { - Object proceed = joinPoint.proceed(); - TableDataInfo tableDataInfo = (TableDataInfo) proceed; - List list = (List) tableDataInfo.getRows(); - - for (Object o : list) { - // 获取list表中类的类型 - Class aClass = o.getClass(); - - // 遍历实体类的字段 - for (Field field : aClass.getDeclaredFields()) { - String fieldName = field.getName(); - // 判断字段是否为电话号码或身份证号码,并对其进行脱敏 - if (StrUtil.containsIgnoreCase(fieldName, "idcard")) { - field.setAccessible(true); - String value = String.valueOf(field.get(o)); - try { - ReflectUtil.setFieldValue(o, fieldName, DesensitizedUtil.idCardNum(value, 4, 4)); - } catch (Exception ignored) { - } - } - - if (StrUtil.containsIgnoreCase(fieldName, "phone")) { - field.setAccessible(true); - String value = String.valueOf(field.get(o)); - try { - ReflectUtil.setFieldValue(o, fieldName, DesensitizedUtil.mobilePhone(value)); - } catch (Exception ignored) { - } - } - } - } - tableDataInfo.setRows(list); - return tableDataInfo; - } -} diff --git a/gather-app/src/main/java/com/ruoyi/database/controller/SmallProgramController.java b/gather-app/src/main/java/com/ruoyi/database/controller/SmallProgramController.java index 336cd93..1930a33 100644 --- a/gather-app/src/main/java/com/ruoyi/database/controller/SmallProgramController.java +++ b/gather-app/src/main/java/com/ruoyi/database/controller/SmallProgramController.java @@ -151,8 +151,7 @@ public class SmallProgramController extends BaseController { customerPlateNoInfo.setPlateNo(plateNo); customerPlateNoInfo.setPlateType(bindTheVehicle.getPlateType()); customerPlateNoInfo.setPhone(loginUserByPhone.getPhone()); - customerPlateNoInfoService.saveOrUpdate(customerPlateNoInfo); - return AjaxResult.success(customerPlateNoInfo); + return toAjax(customerPlateNoInfoService.saveOrUpdate(customerPlateNoInfo)); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/aspect/responseAspect.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/aspect/responseAspect.java deleted file mode 100644 index 3ca6878..0000000 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/aspect/responseAspect.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ruoyi.web.controller.aspect; - -import cn.hutool.core.util.DesensitizedUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import com.ruoyi.common.core.page.TableDataInfo; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.stereotype.Component; - -import java.lang.reflect.Field; -import java.util.List; - -@Aspect -@Component -public class responseAspect { - - @Around("execution(* com.ruoyi.web.controller.system.SysLoginController.getCustomerInfo())") - public TableDataInfo around(ProceedingJoinPoint joinPoint) throws Throwable { - Object proceed = joinPoint.proceed(); - TableDataInfo tableDataInfo = (TableDataInfo) proceed; - List list = (List) tableDataInfo.getRows(); - - for (Object o : list) { - // 获取list表中类的类型 - Class aClass = o.getClass(); - - // 遍历实体类的字段 - for (Field field : aClass.getDeclaredFields()) { - String fieldName = field.getName(); - // 判断字段是否为电话号码或身份证号码,并对其进行脱敏 - if (StrUtil.containsIgnoreCase(fieldName, "idcard")) { - field.setAccessible(true); - String value = String.valueOf(field.get(o)); - try { - ReflectUtil.setFieldValue(o, fieldName, DesensitizedUtil.idCardNum(value, 4, 4)); - } catch (Exception ignored) { - } - } - - if (StrUtil.containsIgnoreCase(fieldName, "phone")) { - field.setAccessible(true); - String value = String.valueOf(field.get(o)); - try { - ReflectUtil.setFieldValue(o, fieldName, DesensitizedUtil.mobilePhone(value)); - } catch (Exception ignored) { - } - } - } - } - tableDataInfo.setRows(list); - return tableDataInfo; - } -} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index a116508..a369d0c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -1,5 +1,6 @@ package com.ruoyi.web.controller.system; +import cn.hutool.core.util.DesensitizedUtil; import com.ruoyi.business.util.StringKit; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; @@ -186,6 +187,7 @@ public class SysLoginController { .eq(BaseCustomerInfo::getPhone, loginUser.getPhone()) .last("limit 1") .one(); + one.setPhone(DesensitizedUtil.mobilePhone(one.getPhone())); return AjaxResult.success(one); } return AjaxResult.success(loginUser); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index f2968b1..bfc35b0 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -183,7 +183,7 @@ public class TokenService { loginUserByPhone.setLoginTime(System.currentTimeMillis()); loginUserByPhone.setExpireTime(loginUserByPhone.getLoginTime() + expireTime * MILLIS_MINUTE); String userKey = getTokenKey(loginUserByPhone.getToken()); - redisCache.setCacheObject(userKey, loginUserByPhone, expireTime, TimeUnit.MINUTES); + redisCache.setCacheObject(userKey, loginUserByPhone, expireTime, TimeUnit.DAYS); } /**