package com.jiayue.center.aspectj; import com.jiayue.center.util.*; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** * 防重放 * * @author xsl * @since 2023/05/24 */ @Aspect @Component @Slf4j @Order(2) public class PreventReplayAspect { /** * 定义切点 */ @Pointcut("@annotation(com.jiayue.center.annotation.PreventReplay)") public void replayAspect(){ } @Around("replayAspect()") public ResponseVO doAround(ProceedingJoinPoint pjp) throws Throwable { // try { // // 获取request // HttpServletRequest request = ServletUtils.getRequest(); // // 时间戳 // String sysTime = request.getParameter("sysTime"); // long sj = System.currentTimeMillis() - Long.parseLong(sysTime); // // 判断客户端的时间是否超过60秒 // if (sj / 1000 >= 60) { // // 超过60秒视为无效请求 // ResponseInfo.doResponse(ServletUtils.getResponse(), "本次请求时间戳无效!", 406); // return null; // } // String lk = request.getParameter("lk"); // Object islk = LocalCache.get(lk); // // 校验服务端授权码 // if (islk == null || "".equals(islk)) { // // 记录用户失败日志 // ResponseInfo.doResponse(ServletUtils.getResponse(), "本次请求时间戳无效!", 406); // return null; // } else { // // 清除本地授权码存储 // LocalCache.remove(lk); // } // } // catch (Exception e) { // return ResponseVO.fail("防重放解析失败,不能操作!"); // } // result的值就是被拦截方法的返回值 ResponseVO result = (ResponseVO)pjp.proceed(); return result; } }