diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 1a380cb..dfc8203 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -12,6 +12,7 @@
+
@@ -35,6 +36,7 @@
+
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index d903963..f8295f9 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -16,6 +16,7 @@
+
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 03d9549..648d6c6 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -2,5 +2,8 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 676e256..94a25f7 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,6 +2,5 @@
-
\ No newline at end of file
diff --git a/atguigu-tuan/common/http.interceptor.js b/atguigu-tuan/common/http.interceptor.js
index fc1fc02..7e2e168 100644
--- a/atguigu-tuan/common/http.interceptor.js
+++ b/atguigu-tuan/common/http.interceptor.js
@@ -1,7 +1,7 @@
const install = (Vue, vm) => {
Vue.prototype.$u.http.setConfig({
//baseUrl: 'https://gmall-prod.atguigu.cn/api',
- baseUrl: 'http://ggkt2.vipgz1.91tunnel.com/api',
+ baseUrl: 'http://localhost:8200/api',
loadingText: '请求中...', // 请求loading中的文字提示
loadingTime: 800, // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms
loadingMask: true, // 展示loading的时候,是否给一个透明的蒙层,防止触摸穿透
diff --git a/atguigu-tuan/pages/login/login.vue b/atguigu-tuan/pages/login/login.vue
index 63abf98..8955d6e 100644
--- a/atguigu-tuan/pages/login/login.vue
+++ b/atguigu-tuan/pages/login/login.vue
@@ -59,11 +59,11 @@ export default {
data: result.token,
success: async () => {
// 更新用户信息
- await this.$u.api.postUpdateUser({
- sex,
- photoUrl,
- nickName
- });
+ // await this.$u.api.postUpdateUser({
+ // sex,
+ // photoUrl,
+ // nickName
+ // });
// 路由跳转至首页
uni.reLaunch({
url: '/pages/index/index',
diff --git a/guigu-ssyx-parent/common/common-util/src/main/java/com/atguigu/ssyx/common/utils/JwtHelper.java b/guigu-ssyx-parent/common/common-util/src/main/java/com/atguigu/ssyx/common/utils/JwtHelper.java
new file mode 100644
index 0000000..90ec248
--- /dev/null
+++ b/guigu-ssyx-parent/common/common-util/src/main/java/com/atguigu/ssyx/common/utils/JwtHelper.java
@@ -0,0 +1,64 @@
+package com.atguigu.ssyx.common.utils;
+
+import io.jsonwebtoken.*;
+import org.springframework.util.StringUtils;
+
+import java.util.Date;
+
+/**
+ * ClassName: JwtHelper
+ * Package: com.atguigu.ssyx.common.utils
+ *
+ * @author yovinchen
+ * @Create 2023/9/22 15:50
+ */
+public class JwtHelper {
+
+ private static final long tokenExpiration = 365L * 24 * 60 * 60 * 1000;
+ private static final String tokenSignKey = "ssyx";
+
+ public static String createToken(Long userId, String userName) {
+ String token = Jwts.builder()
+ .setSubject("ssyx-USER")
+ .setExpiration(new Date(System.currentTimeMillis() + tokenExpiration))
+ .claim("userId", userId)
+ .claim("userName", userName)
+ .signWith(SignatureAlgorithm.HS512, tokenSignKey)
+ .compressWith(CompressionCodecs.GZIP)
+ .compact();
+ return token;
+ }
+
+ public static Long getUserId(String token) {
+ if (StringUtils.isEmpty(token)) return null;
+
+ Jws claimsJws = Jwts.parser()
+ .setSigningKey(tokenSignKey)
+ .parseClaimsJws(token);
+ Claims claims = claimsJws.getBody();
+ Integer userId = (Integer) claims.get("userId");
+ return userId.longValue();
+ // return 1L;
+ }
+
+ public static String getUserName(String token) {
+ if (StringUtils.isEmpty(token)) return "";
+
+ Jws claimsJws = Jwts.parser()
+ .setSigningKey(tokenSignKey)
+ .parseClaimsJws(token);
+ Claims claims = claimsJws.getBody();
+ return (String) claims.get("userName");
+ }
+
+ public static void removeToken(String token) {
+ //jwttoken无需删除,客户端扔掉即可。
+ }
+
+ public static void main(String[] args) {
+ String token = JwtHelper.createToken(7L, "admin");
+ System.out.println(token);
+ System.out.println(JwtHelper.getUserId(token));
+ System.out.println(JwtHelper.getUserName(token));
+ }
+}
diff --git a/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/AuthContextHolder.java b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/AuthContextHolder.java
new file mode 100644
index 0000000..4e2ca42
--- /dev/null
+++ b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/AuthContextHolder.java
@@ -0,0 +1,50 @@
+package com.atguigu.ssyx.common.auth;
+
+import com.atguigu.ssyx.vo.user.UserLoginVo;
+
+/**
+ * ClassName: AuthContextHolder
+ * Package: com.atguigu.ssyx.common.auth
+ *
+ * @author yovinchen
+ * @Create 2023/9/22 17:40
+ */
+//ThreadLocal工具类
+public class AuthContextHolder {
+
+ //用户id
+ private static final ThreadLocal userId = new ThreadLocal<>();
+
+ //用户仓库id
+ private static final ThreadLocal wareId = new ThreadLocal<>();
+
+ //用户信息对象
+ private static final ThreadLocal userLoginVo = new ThreadLocal<>();
+
+ public static Long getUserId() {
+ return userId.get();
+ }
+
+ //userId操作的方法
+ public static void setUserId(Long _userId) {
+ userId.set(_userId);
+ }
+
+ public static Long getWareId() {
+ return wareId.get();
+ }
+
+ public static void setWareId(Long _wareId) {
+ wareId.set(_wareId);
+ }
+
+ public static UserLoginVo getUserLoginVo() {
+ return userLoginVo.get();
+ }
+
+ public static void setUserLoginVo(UserLoginVo _userLoginVo) {
+ userLoginVo.set(_userLoginVo);
+ }
+
+
+}
diff --git a/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/LoginMvcConfigurerAdapter.java b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/LoginMvcConfigurerAdapter.java
new file mode 100644
index 0000000..214ad8e
--- /dev/null
+++ b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/LoginMvcConfigurerAdapter.java
@@ -0,0 +1,30 @@
+package com.atguigu.ssyx.common.auth;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+
+import javax.annotation.Resource;
+
+/**
+ * ClassName: LoginMvcConfigurerAdapter
+ * Package: com.atguigu.ssyx.common.auth
+ *
+ * @author yovinchen
+ * @Create 2023/9/22 23:58
+ */
+@Configuration
+public class LoginMvcConfigurerAdapter extends WebMvcConfigurationSupport {
+
+ @Resource
+ private RedisTemplate redisTemplate;
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new UserLoginInterceptor(redisTemplate))
+ .addPathPatterns("/api/**")
+ .excludePathPatterns("/api/user/weixin/wxLogin/*");
+ super.addInterceptors(registry);
+ }
+}
diff --git a/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/UserLoginInterceptor.java b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/UserLoginInterceptor.java
new file mode 100644
index 0000000..c405123
--- /dev/null
+++ b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/auth/UserLoginInterceptor.java
@@ -0,0 +1,53 @@
+package com.atguigu.ssyx.common.auth;
+
+import com.atguigu.ssyx.common.constant.RedisConst;
+import com.atguigu.ssyx.common.utils.JwtHelper;
+import com.atguigu.ssyx.vo.user.UserLoginVo;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.util.StringUtils;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * ClassName: UserLoginInterceptor
+ * Package: com.atguigu.ssyx.common.auth
+ *
+ * @author yovinchen
+ * @Create 2023/9/22 23:47
+ */
+public class UserLoginInterceptor implements HandlerInterceptor {
+
+ private final RedisTemplate redisTemplate;
+
+ public UserLoginInterceptor(RedisTemplate redisTemplate) {
+ this.redisTemplate = redisTemplate;
+ }
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ this.getUserLoginVo(request);
+ return true;
+ }
+
+ private void getUserLoginVo(HttpServletRequest request) {
+ //从请求头获取token
+ String token = request.getHeader("token");
+
+ //判断token不为空
+ if (!StringUtils.isEmpty(token)) {
+ //从token获取userId
+ Long userId = JwtHelper.getUserId(token);
+ //根据userId到Redis获取用户信息
+ UserLoginVo userLoginVo = (UserLoginVo) redisTemplate.opsForValue()
+ .get(RedisConst.USER_LOGIN_KEY_PREFIX + userId);
+ //获取数据放到ThreadLocal里面
+ if (userLoginVo != null) {
+ AuthContextHolder.setUserId(userLoginVo.getUserId());
+ AuthContextHolder.setWareId(userLoginVo.getWareId());
+ AuthContextHolder.setUserLoginVo(userLoginVo);
+ }
+ }
+ }
+}
diff --git a/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/config/RedisConfig.java b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/config/RedisConfig.java
new file mode 100644
index 0000000..da30210
--- /dev/null
+++ b/guigu-ssyx-parent/common/service-util/src/main/java/com/atguigu/ssyx/common/config/RedisConfig.java
@@ -0,0 +1,105 @@
+package com.atguigu.ssyx.common.config;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.interceptor.KeyGenerator;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.cache.RedisCacheConfiguration;
+import org.springframework.data.redis.cache.RedisCacheManager;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.RedisSerializationContext;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import java.lang.reflect.Method;
+import java.time.Duration;
+
+/**
+ * ClassName: RedisConfig
+ * Package: com.atguigu.ssyx.common.config
+ * Redis配置类
+ *
+ * @author yovinchen
+ * @Create 2023/9/22 15:55
+ */
+
+@Configuration
+@EnableCaching
+public class RedisConfig {
+
+ // 使用默认标签做缓存
+ @Bean
+ public KeyGenerator wiselyKeyGenerator() {
+ return new KeyGenerator() {
+ @Override
+ public Object generate(Object target, Method method, Object... params) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(target.getClass()
+ .getName());
+ sb.append(method.getName());
+ for (Object obj : params) {
+ sb.append(obj.toString());
+ }
+ return sb.toString();
+ }
+ };
+ }
+
+ // 声明模板
+ /*
+ ref = 表示引用
+ value = 具体的值
+
+
+
+ */
+ // 工具类:
+ @Bean
+ public RedisTemplate