diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index da85e9b..c2bc136 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -100,16 +100,32 @@ public class LoginFilter implements Filter { } String message = ""; String tokenKey=""; + + JSONObject jsonObject1 = TokenUtil.parseParamFromToken(token); + if (jsonObject1.containsKey("status")){ + String openId = request.getHeader("openId"); + String userId = request.getHeader("id"); + redisUtil.deleteByKey(RedisCst.ONLINE_USER.concat(openId)); + redisUtil.deleteByKey(RedisCst.ONLINE_USER.concat(userId)); + redisUtil.deleteByKey(RedisCst.ONLINE_APP_USER.concat(userId)); + Result result = new Result(CodeEnum.TOKEN_EXPIRED); + String jsonString = JSONObject.toJSONString(result); + JSONObject jsonObject = JSONObject.parseObject(jsonString, JSONObject.class); + response.getWriter().print(jsonObject); + response.getWriter().flush();//流里边的缓存刷出 + return; + } + if(environment.equals("app")){ //获取当前登录人的用户id - String userId = TokenUtil.parseParamFromToken(token).getString("userId"); + String userId = jsonObject1.getString("userId"); tokenKey=RedisCst.ONLINE_APP_USER.concat(userId); //获取redis中的token }else if(environment.equals("wx")){ //获取当前登录人的用户id - String openId = TokenUtil.parseParamFromToken(token).getString("openId"); + String openId = jsonObject1.getString("openId"); if(StringUtils.isBlank(openId)){ - openId = TokenUtil.parseParamFromToken(token).getString("userId"); + openId = jsonObject1.getString("userId"); } tokenKey=RedisCst.ONLINE_USER.concat(openId); } @@ -131,15 +147,6 @@ public class LoginFilter implements Filter { response.getWriter().flush();//流里边的缓存刷出 return; } - JSONObject jsonObject1 = TokenUtil.parseParamFromToken(token); - if (jsonObject1.containsKey("status")){ - Result result = new Result(CodeEnum.TOKEN_EXPIRED); - String jsonString = JSONObject.toJSONString(result); - JSONObject jsonObject = JSONObject.parseObject(jsonString, JSONObject.class); - response.getWriter().print(jsonObject); - response.getWriter().flush();//流里边的缓存刷出 - return; - } checkRenewal(tokenKey); chain.doFilter(req, resp); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java index 0cc66d9..a4155f3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java @@ -1,15 +1,10 @@ package com.chaozhanggui.system.cashierservice.rabbit; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.chaozhanggui.system.cashierservice.exception.MsgException; -import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; -import com.chaozhanggui.system.cashierservice.service.CartService; import com.chaozhanggui.system.cashierservice.service.IntegralService; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Autowired;