PreventReplayAspect.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.jiayue.center.aspectj;
  2. import com.jiayue.center.util.*;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.aspectj.lang.ProceedingJoinPoint;
  5. import org.aspectj.lang.annotation.Around;
  6. import org.aspectj.lang.annotation.Aspect;
  7. import org.aspectj.lang.annotation.Pointcut;
  8. import org.springframework.core.annotation.Order;
  9. import org.springframework.stereotype.Component;
  10. /**
  11. * 防重放
  12. *
  13. * @author xsl
  14. * @since 2023/05/24
  15. */
  16. @Aspect
  17. @Component
  18. @Slf4j
  19. @Order(2)
  20. public class PreventReplayAspect {
  21. /**
  22. * 定义切点
  23. */
  24. @Pointcut("@annotation(com.jiayue.center.annotation.PreventReplay)")
  25. public void replayAspect(){
  26. }
  27. @Around("replayAspect()")
  28. public ResponseVO doAround(ProceedingJoinPoint pjp) throws Throwable {
  29. // try {
  30. // // 获取request
  31. // HttpServletRequest request = ServletUtils.getRequest();
  32. // // 时间戳
  33. // String sysTime = request.getParameter("sysTime");
  34. // long sj = System.currentTimeMillis() - Long.parseLong(sysTime);
  35. // // 判断客户端的时间是否超过60秒
  36. // if (sj / 1000 >= 60) {
  37. // // 超过60秒视为无效请求
  38. // ResponseInfo.doResponse(ServletUtils.getResponse(), "本次请求时间戳无效!", 406);
  39. // return null;
  40. // }
  41. // String lk = request.getParameter("lk");
  42. // Object islk = LocalCache.get(lk);
  43. // // 校验服务端授权码
  44. // if (islk == null || "".equals(islk)) {
  45. // // 记录用户失败日志
  46. // ResponseInfo.doResponse(ServletUtils.getResponse(), "本次请求时间戳无效!", 406);
  47. // return null;
  48. // } else {
  49. // // 清除本地授权码存储
  50. // LocalCache.remove(lk);
  51. // }
  52. // }
  53. // catch (Exception e) {
  54. // return ResponseVO.fail("防重放解析失败,不能操作!");
  55. // }
  56. // result的值就是被拦截方法的返回值
  57. ResponseVO result = (ResponseVO)pjp.proceed();
  58. return result;
  59. }
  60. }