| | |
| | | } |
| | | }else if (beanType.isAnnotationPresent(LoginShopRequired.class)) { |
| | | //获取token |
| | | String token = request.getHeader(JwtTokenUtil.HEADER_KEY); // 从 http 请求头中取出 token |
| | | String token = request.getHeader(JwtTokenUtil.SHOP_HEADER_KEY); // 从 http 请求头中取出 token |
| | | if (StringUtils.isNotBlank(token)) { |
| | | checkShopLogin(request,response); |
| | | checkShopLogin(token,request,response); |
| | | } else { |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"未登录"); |
| | | throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE.getCode(),"未登录"); |
| | | } |
| | | }else if (handlerMethod.hasMethodAnnotation(LoginShopRequired.class)){ |
| | | //获取token |
| | | String token = request.getHeader(JwtTokenUtil.HEADER_KEY); // 从 http 请求头中取出 token |
| | | String token = request.getHeader(JwtTokenUtil.SHOP_HEADER_KEY); // 从 http 请求头中取出 token |
| | | if (StringUtils.isNotBlank(token)) { |
| | | checkShopLogin(request,response); |
| | | checkShopLogin(token,request,response); |
| | | } else { |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"未登录"); |
| | | throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE.getCode(),"未登录"); |
| | | } |
| | | }else if (beanType.isAnnotationPresent(LoginDriverRequired.class)) { |
| | | //获取token |
| | |
| | | } |
| | | |
| | | |
| | | public Boolean checkShopLogin(HttpServletRequest request, HttpServletResponse response){ |
| | | String token = request.getHeader(JwtTokenUtil.HEADER_KEY); |
| | | public Boolean checkShopLogin(String token,HttpServletRequest request, HttpServletResponse response){ |
| | | try { |
| | | if(!token.startsWith(Constants.TWO+"")){ |
| | | throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME); |
| | | throw new BusinessException(ResponseStatus.SHOP_TOKEN_EXCEED_TIME); |
| | | } |
| | | String tokenRedis = (String) redisTemplate.opsForValue().get(Constants.REDIS_TOKEN_KEY+token); |
| | | if(StringUtils.isBlank(tokenRedis)){ |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE); |
| | | throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE); |
| | | } |
| | | ShopInfo shop = JSONObject.parseObject(tokenRedis, ShopInfo.class); |
| | | if(Objects.isNull(shop)){ |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE); |
| | | throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE); |
| | | } |
| | | String openid = shop.getOpenid(); |
| | | Integer shopId = getTokenId(token); |
| | |
| | | } |
| | | String dbOpenid = dao.queryForObject(" select ifnull(openid,'') from shop_info where id = ?", String.class, shopId); |
| | | if(StringUtils.isBlank(dbOpenid)||!openid.equals(dbOpenid)){ |
| | | throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME); |
| | | throw new BusinessException(ResponseStatus.SHOP_TOKEN_EXCEED_TIME); |
| | | } |
| | | Integer count = dao.queryForObject("select count(1) from shop_info where id = ?", Integer.class, shopId); |
| | | if (count != null && count > 0) { |
| | | request.setAttribute(JwtTokenUtil.SHOP_ID, shop.getId()); |
| | | return true; |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"用户信息出错"); |
| | | throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE.getCode(),"用户信息出错"); |
| | | } |
| | | } catch (IllegalArgumentException | JwtException e) { |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE); |
| | | throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE); |
| | | } |
| | | } |
| | | |