|
@@ -0,0 +1,81 @@
|
|
|
+package com.example.xiaoshiweixinback.checkLogin;
|
|
|
+
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.example.xiaoshiweixinback.business.common.Response;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.annotation.*;
|
|
|
+import org.aspectj.lang.reflect.MethodSignature;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.script.ScriptEngine;
|
|
|
+import javax.script.ScriptEngineManager;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Order(2)
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class CheckLoginAop {
|
|
|
+ @Autowired
|
|
|
+ private CacheUtil cacheUtil;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定义切点
|
|
|
+ */
|
|
|
+ @Pointcut("@annotation(com.example.xiaoshiweixinback.checkLogin.checkLogin)")
|
|
|
+ public void annotationPointcut() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Before("annotationPointcut()")
|
|
|
+ public void beforePointcut(JoinPoint joinPoint) {
|
|
|
+ //此处进入到方法前 可以实现一些业务逻辑
|
|
|
+ //获取目标对象方法参数
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param joinPoint 当前执行的方法
|
|
|
+ */
|
|
|
+ @Around("annotationPointcut()")
|
|
|
+ public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ // 是否通过切面过滤标记
|
|
|
+ Boolean isPass = true;
|
|
|
+ try { cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ return Response.unLogin("未登录");
|
|
|
+ }
|
|
|
+ //判断不通过
|
|
|
+ if (!isPass) {
|
|
|
+ return Response.unLogin("未登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断通过
|
|
|
+ return joinPoint.proceed();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在切入点return内容之后切入内容(可以用来对处理返回值做一些加工处理)
|
|
|
+ *
|
|
|
+ * @param joinPoint 切点
|
|
|
+ */
|
|
|
+ @AfterReturning("annotationPointcut()")
|
|
|
+ public void doAfterReturning(JoinPoint joinPoint) {
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkToken(String token) {
|
|
|
+ }
|
|
|
+}
|
|
|
+
|