Browse Source

登录将token写入缓存

houweiyu 4 years ago
parent
commit
f083d3cbf0

+ 9 - 1
dinner-core/src/main/java/com/fdage/controller/app/AppAuthController.java

@@ -17,6 +17,8 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -36,6 +38,9 @@ import java.util.Map;
 @Log4j2
 public class AppAuthController extends BaseController {
 
+    @Autowired
+    private RedisTemplate redisTemplate;
+
     /**
      * 小程序微信登录
      */
@@ -102,7 +107,10 @@ public class AppAuthController extends BaseController {
         }
         //2、生成token返回给小程序,token有效期为1天
         String token = JwtUtil.createJWT(86400000 , dbUser.getId());
-
+        if(redisTemplate.hasKey(token)){
+            redisTemplate.delete(token);
+        }
+        redisTemplate.opsForValue().set(token , dbUser.getId() , 86400);
         //3、返回店铺列表给前端 TODO:要这么做吗?还是直接调用获取列表接口即可
 
         Map<String , Object> resultMap = new HashMap<>();