From 53e9765219ea5e885393dc9c02ee0c46cc42ae08 Mon Sep 17 00:00:00 2001 From: lidongdong <1459917685@qq.com> Date: 星期六, 08 十月 2022 15:06:25 +0800 Subject: [PATCH] 修改小程序token --- flower_city/src/main/java/com/dg/core/interceptor/AuthorizationInterceptor.java | 64 +++++++++++++++++--------------- 1 files changed, 34 insertions(+), 30 deletions(-) diff --git a/flower_city/src/main/java/com/dg/core/interceptor/AuthorizationInterceptor.java b/flower_city/src/main/java/com/dg/core/interceptor/AuthorizationInterceptor.java index 2ec7af8..7bf2201 100644 --- a/flower_city/src/main/java/com/dg/core/interceptor/AuthorizationInterceptor.java +++ b/flower_city/src/main/java/com/dg/core/interceptor/AuthorizationInterceptor.java @@ -31,7 +31,6 @@ @Autowired private TokenManager manager; - @Autowired com.dg.core.service.ISysUserService IUserService; @@ -53,26 +52,29 @@ if(StringUtils.isEmpty(token)) { - if(StringUtils.isEmpty(HCtoken)) - { - String reponse = "{\"result\": 448, \"message\": \"token not is null \"}"; - response.setStatus(200); - response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); - ResponseFacade facade = (ResponseFacade) response; - facade.setContentLength(reponse.getBytes(StandardCharsets.UTF_8).length); - facade.getWriter().write(reponse); - return false; - } - else - { - //花城e+ token - if (manager.checkHCToken(HCtoken)) { - //如果token验证成功,权限检查通过,将token对应的用户id存在request中,便于之后注入 - request.setAttribute(Constant.CURRENT_USER_ID, manager.getHCUserId(HCtoken)); +// if(StringUtils.isEmpty(HCtoken)) +// { +// String reponse = "{\"result\": 448, \"message\": \"token not is null \"}"; +// response.setStatus(200); +// response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); +// ResponseFacade facade = (ResponseFacade) response; +// facade.setContentLength(reponse.getBytes(StandardCharsets.UTF_8).length); +// facade.getWriter().write(reponse); +// return false; +// } +// else +// { +// +// } + + //花城e+ token + if (manager.checkHCToken(HCtoken)) { + //如果token验证成功,权限检查通过,将token对应的用户id存在request中,便于之后注入 + request.setAttribute(Constant.CURRENT_USER_ID, manager.getHCUserId(HCtoken)); // SysUser ss = IUserService.selectData(manager.getHCUserId(HCtoken)+""); - return true; - } + return true; } + } else { @@ -84,18 +86,20 @@ } } - - //如果验证token失败,并且方法或类注明了Authorization,返回401错误 - if (method.getAnnotation(Authorization.class) != null || - bean.getClass().getAnnotation(Authorization.class) != null) + if(!StringUtils.isEmpty(token)) { - String reponse = "{\"result\": 449, \"message\": \"Overdue token\"}"; - response.setStatus(200); - response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); - ResponseFacade facade = (ResponseFacade) response; - facade.setContentLength(reponse.getBytes(StandardCharsets.UTF_8).length); - facade.getWriter().write(reponse); - return false; + //如果验证token失败,并且方法或类注明了Authorization,返回401错误 + if (method.getAnnotation(Authorization.class) != null || + bean.getClass().getAnnotation(Authorization.class) != null) + { + String reponse = "{\"result\": 449, \"message\": \"Overdue token\"}"; + response.setStatus(200); + response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); + ResponseFacade facade = (ResponseFacade) response; + facade.setContentLength(reponse.getBytes(StandardCharsets.UTF_8).length); + facade.getWriter().write(reponse); + return false; + } } return true; } -- Gitblit v1.7.1