diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 375fb80..d10b5f7 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -14,6 +14,7 @@ + @@ -26,6 +27,7 @@ + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index ea9b294..680a666 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -14,6 +14,7 @@ + diff --git a/spzx-common/common-log/src/main/java/com/atguigu/log/aspect/LogAspect.java b/spzx-common/common-log/src/main/java/com/atguigu/log/aspect/LogAspect.java index 0dc9561..28c2afa 100644 --- a/spzx-common/common-log/src/main/java/com/atguigu/log/aspect/LogAspect.java +++ b/spzx-common/common-log/src/main/java/com/atguigu/log/aspect/LogAspect.java @@ -28,7 +28,7 @@ public class LogAspect { SysOperLog sysOperLog = new SysOperLog(); LogUtil.beforeHandleLog(sysLog, joinPoint, sysOperLog); Object proceed = null; - + try { proceed = joinPoint.proceed(); // 执行业务方法 diff --git a/spzx-common/common-service/pom.xml b/spzx-common/common-service/pom.xml index 7e6f691..78dbf0d 100644 --- a/spzx-common/common-service/pom.xml +++ b/spzx-common/common-service/pom.xml @@ -29,11 +29,6 @@ org.springframework.boot spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-data-redis - org.springframework.boot @@ -59,5 +54,12 @@ jetty-util 9.3.7.v20160115 + + + + org.springframework.cloud + spring-cloud-starter-openfeign + provided + diff --git a/spzx-common/common-service/src/main/java/com/atguigu/anno/EnableUserWebMvcConfiguration.java b/spzx-common/common-service/src/main/java/com/atguigu/anno/EnableUserWebMvcConfiguration.java new file mode 100644 index 0000000..b32490f --- /dev/null +++ b/spzx-common/common-service/src/main/java/com/atguigu/anno/EnableUserWebMvcConfiguration.java @@ -0,0 +1,17 @@ +package com.atguigu.anno; + +import com.atguigu.config.WebMvcConfiguration; +import com.atguigu.interceptor.UserLoginAuthInterceptor; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = ElementType.TYPE) +@Import(value = {UserLoginAuthInterceptor.class, WebMvcConfiguration.class}) +public @interface EnableUserWebMvcConfiguration { + +} \ No newline at end of file diff --git a/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java b/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java index c7a3214..283f669 100644 --- a/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java +++ b/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java @@ -3,14 +3,18 @@ package com.atguigu.config; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; +import lombok.extern.slf4j.Slf4j; import org.springdoc.core.models.GroupedOpenApi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration +@Slf4j public class Knife4jConfig { @Bean public OpenAPI customOpenAPI() { + log.info("尚品甑选API接口文档"); + // 设定作者 return new OpenAPI().info(new Info().title("尚品甑选API接口文档") .version("1.0").description("尚品甑选API接口文档").contact(new Contact().name("bunny"))); @@ -18,16 +22,22 @@ public class Knife4jConfig { @Bean public GroupedOpenApi adminApi() { + log.info("admin请求接口"); + return GroupedOpenApi.builder().group("admin请求接口").pathsToMatch("/admin/**").build();// 接口请求路径规则 } @Bean public GroupedOpenApi productApi() { + log.info("商品管理接口"); + return GroupedOpenApi.builder().group("商品管理接口").pathsToMatch("/api/product/**").build(); // 接口请求路径规则 } @Bean public GroupedOpenApi userApi() { + log.info("用户接口"); + return GroupedOpenApi.builder().group("用户接口").pathsToMatch("/api/user/**").build(); } } \ No newline at end of file diff --git a/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java b/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java index 7cdcaf0..14ba6d9 100644 --- a/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java +++ b/spzx-common/common-service/src/main/java/com/atguigu/config/WebMvcConfiguration.java @@ -1,28 +1,30 @@ package com.atguigu.config; import com.atguigu.interceptor.LoginAuthInterceptor; +import com.atguigu.interceptor.UserLoginAuthInterceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -@Component @Slf4j -public class WebMvcConfiguration extends WebMvcConfigurationSupport { +public class WebMvcConfiguration implements WebMvcConfigurer { @Autowired private LoginAuthInterceptor loginAuthInterceptor; + @Autowired + private UserLoginAuthInterceptor userLoginAuthInterceptor; /** * * 解决跨域 * * @param registry 跨域注册表 */ - protected void addCorsMappings(CorsRegistry registry) { + @Override + public void addCorsMappings(CorsRegistry registry) { log.info("WebMvcConfiguration===>开始跨域注册表..."); - registry.addMapping("/admin/**")// 添加路径规则 + registry.addMapping("/**")// 添加路径规则 .allowCredentials(true)// 是否允许在跨域的情况下传递Cookie .allowedOriginPatterns("*")// 允许请求来源的域规则 .allowedMethods("*").allowedHeaders("*");// 允许所有的请求头 @@ -33,11 +35,17 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport { * * @param registry InterceptorRegistry */ - protected void addInterceptors(InterceptorRegistry registry) { + @Override + public void addInterceptors(InterceptorRegistry registry) { log.info("WebMvcConfiguration===>开始注册自定义拦截器..."); + String[] loginAuthInterceptors = {"/admin/system/index/login", "/admin/system/index/generateValidateCode", "/admin/product/category/exportData"}; // 需要拦截的 registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin/**") - .excludePathPatterns("/admin/system/index/login", "/admin/system/index/generateValidateCode", "/admin/product/category/exportData"); + .excludePathPatterns(loginAuthInterceptors); + + String[] userLoginAuthInterceptors = {}; + registry.addInterceptor(userLoginAuthInterceptor).addPathPatterns("/api/**") + .excludePathPatterns(userLoginAuthInterceptors); } } \ No newline at end of file diff --git a/spzx-common/common-service/src/main/java/com/atguigu/interceptor/LoginAuthInterceptor.java b/spzx-common/common-service/src/main/java/com/atguigu/interceptor/LoginAuthInterceptor.java index bb590ca..ec67d00 100644 --- a/spzx-common/common-service/src/main/java/com/atguigu/interceptor/LoginAuthInterceptor.java +++ b/spzx-common/common-service/src/main/java/com/atguigu/interceptor/LoginAuthInterceptor.java @@ -65,8 +65,6 @@ public class LoginAuthInterceptor implements HandlerInterceptor { */ @Override public void afterCompletion(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler, @Nullable Exception ex) throws Exception { - log.info("LoginAuthInterceptor===>请求完成后删除ThreadLocal"); - BaseContext.removeSysUser(); } } diff --git a/spzx-common/common-service/src/main/java/com/atguigu/interceptor/UserLoginAuthInterceptor.java b/spzx-common/common-service/src/main/java/com/atguigu/interceptor/UserLoginAuthInterceptor.java new file mode 100644 index 0000000..9f8d5ef --- /dev/null +++ b/spzx-common/common-service/src/main/java/com/atguigu/interceptor/UserLoginAuthInterceptor.java @@ -0,0 +1,47 @@ +package com.atguigu.interceptor; + +import com.alibaba.fastjson.JSON; +import com.atguigu.constant.MessageConstant; +import com.atguigu.context.BaseContext; +import com.atguigu.spzx.model.entity.user.UserInfo; +import com.atguigu.utils.EmptyUtil; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.lang.Nullable; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +@Configuration +@Slf4j +public class UserLoginAuthInterceptor implements HandlerInterceptor { + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private EmptyUtil emptyUtil; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + log.info("UserLoginAuthInterceptor===>preHandle拦截请求前"); + + // 判断token是否为空 + String token = request.getHeader("token"); + emptyUtil.isEmpty(token, MessageConstant.TOKEN_IS_EMPTY); + + String userJSON = (String) redisTemplate.opsForValue().get(token); + BaseContext.setUserInfo(JSON.parseObject(userJSON, UserInfo.class)); + return true; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { + BaseContext.removeUserInfo(); + } +} \ No newline at end of file diff --git a/spzx-common/common-util/pom.xml b/spzx-common/common-util/pom.xml index 0af8385..cea3886 100644 --- a/spzx-common/common-util/pom.xml +++ b/spzx-common/common-util/pom.xml @@ -36,5 +36,10 @@ minio 8.5.9 + + + org.springframework.boot + spring-boot-starter-data-redis + diff --git a/spzx-common/common-service/src/main/java/com/atguigu/exception/BunnyException.java b/spzx-common/common-util/src/main/java/com/atguigu/exception/BunnyException.java similarity index 100% rename from spzx-common/common-service/src/main/java/com/atguigu/exception/BunnyException.java rename to spzx-common/common-util/src/main/java/com/atguigu/exception/BunnyException.java diff --git a/spzx-server-gateway/pom.xml b/spzx-server-gateway/pom.xml index 11be49c..f35b535 100644 --- a/spzx-server-gateway/pom.xml +++ b/spzx-server-gateway/pom.xml @@ -20,7 +20,7 @@ com.atguigu - spzx-model + common-service 1.0-SNAPSHOT diff --git a/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java b/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java index 2625f39..3b02a8d 100644 --- a/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java +++ b/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java @@ -3,8 +3,10 @@ package com.atguigu.gateway; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication +@ComponentScan("com.atguigu") @Slf4j public class GatewayApplication { public static void main(String[] args) { diff --git a/spzx-server-gateway/src/main/java/com/atguigu/gateway/config/CorsConfig.java b/spzx-server-gateway/src/main/java/com/atguigu/gateway/config/CorsConfig.java deleted file mode 100644 index 812ac49..0000000 --- a/spzx-server-gateway/src/main/java/com/atguigu/gateway/config/CorsConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.atguigu.gateway.config; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.reactive.CorsWebFilter; -import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; - -@Configuration -@Slf4j -public class CorsConfig { - /** - * * 解决跨域 - */ - @Bean - protected CorsWebFilter addCorsMappings() { - log.info("WebMvcConfiguration===>开始跨域注册表..."); - - // 当allowCredentials设置为true时,allowedOrigins属性不能使用通配符"*",而是需要显式列出允许的源或使用allowedOriginPatterns - CorsConfiguration config = new CorsConfiguration(); - // 设置跨域请求地址 - // config.addAllowedOrigin("*"); - config.addAllowedMethod("*"); - config.addAllowedHeader("*"); - // 使用allowedOriginPatterns属性:在Spring Framework 5.3及更高版本中, - // 您可以使用allowedOriginPatterns属性,它允许您使用正则表达式模式来匹配允许的源。这样,您可以更灵活地配置允许的源。例如 - // 使用"https?://example.com"来匹配http://example.com和https://example.com两个源。 - config.addAllowedOriginPattern("*"); - config.setAllowCredentials(true); - - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/api/**", config); - - return new CorsWebFilter(source); - } -} \ No newline at end of file diff --git a/spzx-server-gateway/src/main/java/com/atguigu/gateway/filter/AuthGlobalFilter.java b/spzx-server-gateway/src/main/java/com/atguigu/gateway/filter/AuthGlobalFilter.java new file mode 100644 index 0000000..edb8d19 --- /dev/null +++ b/spzx-server-gateway/src/main/java/com/atguigu/gateway/filter/AuthGlobalFilter.java @@ -0,0 +1,75 @@ +package com.atguigu.gateway.filter; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.atguigu.constant.MessageConstant; +import com.atguigu.spzx.model.entity.user.UserInfo; +import com.atguigu.spzx.model.vo.result.Result; +import com.atguigu.spzx.model.vo.result.ResultCodeEnum; +import com.atguigu.utils.EmptyUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.StringUtils; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.nio.charset.StandardCharsets; +import java.util.List; + +@Configuration +public class AuthGlobalFilter implements GlobalFilter, Ordered { + private final AntPathMatcher antPathMatcher = new AntPathMatcher(); + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private EmptyUtil emptyUtil; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + ServerHttpRequest request = exchange.getRequest(); + String path = request.getURI().getPath(); + // 判断请求路径 + if (antPathMatcher.match("/api/**/auth/**", path)) { + UserInfo userInfo = getUserinfo(request); + emptyUtil.isEmpty(userInfo, MessageConstant.USER_DOES_NOT_EXIST); + ServerHttpResponse response = exchange.getResponse(); + return out(exchange.getResponse()); + + } + return chain.filter(exchange); + } + + private UserInfo getUserinfo(ServerHttpRequest request) { + List tokenList = request.getHeaders().get("token"); + emptyUtil.isEmpty(tokenList, MessageConstant.TOKEN_IS_EMPTY); + String token = tokenList.get(0); + if (StringUtils.hasText(token)) { + String userJson = (String) redisTemplate.opsForValue().get(token); + emptyUtil.isEmpty(userJson, MessageConstant.TOKEN_IS_EMPTY); + return JSON.parseObject(userJson, UserInfo.class); + } + return null; + } + + @Override + public int getOrder() { + return 0; + } + + private Mono out(ServerHttpResponse response) { + Result result = Result.build(null, ResultCodeEnum.LOGIN_AUTH); + byte[] bits = JSONObject.toJSONString(result).getBytes(StandardCharsets.UTF_8); + DataBuffer buffer = response.bufferFactory().wrap(bits); + // 指定编码,否则在浏览器中会中文乱码 + response.getHeaders().add("Content-Type", "application/json;charset=UTF-8"); + return response.writeWith(Mono.just(buffer)); + } +} diff --git a/spzx-server-gateway/src/main/resources/application-dev.yml b/spzx-server-gateway/src/main/resources/application-dev.yml index c00244b..ea08af1 100644 --- a/spzx-server-gateway/src/main/resources/application-dev.yml +++ b/spzx-server-gateway/src/main/resources/application-dev.yml @@ -4,3 +4,7 @@ bunny: discovery: namespace: spzx + redis: + host: 106.15.251.123 + port: 6379 + database: 2 \ No newline at end of file diff --git a/spzx-server-gateway/src/main/resources/application.yml b/spzx-server-gateway/src/main/resources/application.yml index 60452e0..622350a 100644 --- a/spzx-server-gateway/src/main/resources/application.yml +++ b/spzx-server-gateway/src/main/resources/application.yml @@ -47,6 +47,11 @@ spring: uri: lb://service-order predicates: - Path=/*/order/** + data: + redis: + host: ${bunny.redis.host} + port: ${bunny.redis.port} + database: ${bunny.redis.database} logging: level: diff --git a/spzx-service/pom.xml b/spzx-service/pom.xml index a6da8d3..090e1f4 100644 --- a/spzx-service/pom.xml +++ b/spzx-service/pom.xml @@ -15,6 +15,7 @@ service-user service-order + service-cart @@ -27,11 +28,6 @@ common-service 1.0-SNAPSHOT - - - org.springframework.boot - spring-boot-starter-data-redis - diff --git a/spzx-service/service-cart/pom.xml b/spzx-service/service-cart/pom.xml new file mode 100644 index 0000000..3d7467a --- /dev/null +++ b/spzx-service/service-cart/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + + com.atguigu + spzx-service + 1.0-SNAPSHOT + + + service-cart + jar + + service-cart + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + diff --git a/spzx-service/service-cart/src/main/java/com/atguigu/cart/CartApplication.java b/spzx-service/service-cart/src/main/java/com/atguigu/cart/CartApplication.java new file mode 100644 index 0000000..672e6f2 --- /dev/null +++ b/spzx-service/service-cart/src/main/java/com/atguigu/cart/CartApplication.java @@ -0,0 +1,13 @@ +package com.atguigu.cart; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +// 排除数据库的自动化配置,Cart微服务不需要访问数据库 +@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) +public class CartApplication { + public static void main(String[] args) { + SpringApplication.run(CartApplication.class, args); + } +} \ No newline at end of file diff --git a/spzx-service/service-cart/src/main/resources/application-dev.yml b/spzx-service/service-cart/src/main/resources/application-dev.yml new file mode 100644 index 0000000..c27cb60 --- /dev/null +++ b/spzx-service/service-cart/src/main/resources/application-dev.yml @@ -0,0 +1,10 @@ +bunny: + redis: + host: 106.15.251.123 + port: 6379 + database: 2 + + nacos: + server-addr: z-bunny.cn:8848 + discovery: + namespace: spzx \ No newline at end of file diff --git a/spzx-service/service-cart/src/main/resources/application.yml b/spzx-service/service-cart/src/main/resources/application.yml new file mode 100644 index 0000000..7bd3151 --- /dev/null +++ b/spzx-service/service-cart/src/main/resources/application.yml @@ -0,0 +1,29 @@ +server: + port: 8513 +spring: + profiles: + active: dev + application: + name: service-cart + + cloud: + nacos: + discovery: + namespace: ${bunny.nacos.discovery.namespace} + server-addr: ${bunny.nacos.server-addr} + + data: + redis: + host: ${bunny.redis.host} + port: ${bunny.redis.port} + database: ${bunny.redis.database} + +logging: + level: + com.atguigu.spzx.user.mapper: debug + com.atguigu.spzx.user.controller: info + com.atguigu.spzx.user.service: info + pattern: + dateformat: HH:mm:ss:SSS + file: + path: "logs/${spring.application.name}" \ No newline at end of file diff --git a/spzx-service/service-cart/src/main/resources/banner.txt b/spzx-service/service-cart/src/main/resources/banner.txt new file mode 100644 index 0000000..cc77fc2 --- /dev/null +++ b/spzx-service/service-cart/src/main/resources/banner.txt @@ -0,0 +1,16 @@ +-----------------▄██-█▄--------- +-----------------███▄██▄-------- +-----------------███████-------- +-----------------▀███████------- +-------------------██████▄▄----- +-------------------█████████▄--- +-------------------██████▄████-- +-------▄███████████████████████- +-----▄███████████████████████▀-- +---▄██████████████████████------ +---███████████████████████------ +---███████████████████████------ +-▄▄██████████████████████▀------ +-█████████████████▀█████-------- +-▀██████████████▀▀-▀█████▄------ +-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------ \ No newline at end of file diff --git a/spzx-service/service-cart/src/main/resources/favicon.ico b/spzx-service/service-cart/src/main/resources/favicon.ico new file mode 100644 index 0000000..1ba397c Binary files /dev/null and b/spzx-service/service-cart/src/main/resources/favicon.ico differ diff --git a/spzx-service/service-cart/src/main/resources/logback-spring.xml b/spzx-service/service-cart/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..2477ac8 --- /dev/null +++ b/spzx-service/service-cart/src/main/resources/logback-spring.xml @@ -0,0 +1,57 @@ + + + + logback + + + + + + + + + + + + + + + + + + + + + + + INFO + + + ${CONSOLE_LOG_PATTERN} + ${ENCODING} + + + + + + ${log.path}//log.log + true + + %date{yyyy-MM-dd HH:mm:ss} %msg%n + ${ENCODING} + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/SmsServiceImpl.java b/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/SmsServiceImpl.java index 17877ee..d98b583 100644 --- a/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/SmsServiceImpl.java +++ b/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/SmsServiceImpl.java @@ -33,7 +33,7 @@ public class SmsServiceImpl implements SmsService { UserInfo userInfo = userInfoMapper.selectByUsername(phone); emptyUtil.isNotEmpty(isExist, MessageConstant.MESSAGE_CODE_NOT_PASS); emptyUtil.isNotEmpty(userInfo, MessageConstant.USER_DOES_IS_EXIST); - + // 1. 生成验证码 String code = RandomStringUtils.randomNumeric(4); // 2. 生成的验证码放到Redis中,设置过期时间 diff --git a/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/UserInfoServiceImpl.java b/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/UserInfoServiceImpl.java index 98afe47..8ea91b8 100644 --- a/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/UserInfoServiceImpl.java +++ b/spzx-service/service-user/src/main/java/com/atguigu/user/service/impl/UserInfoServiceImpl.java @@ -3,6 +3,7 @@ package com.atguigu.user.service.impl; import com.alibaba.fastjson.JSON; import com.atguigu.constant.MessageConstant; import com.atguigu.constant.UserConstant; +import com.atguigu.context.BaseContext; import com.atguigu.exception.BunnyException; import com.atguigu.spzx.model.dto.h5.UserLoginDto; import com.atguigu.spzx.model.dto.h5.UserRegisterDto; @@ -107,10 +108,12 @@ public class UserInfoServiceImpl implements UserInfoService { */ @Override public UserInfoVo getCurrentUserInfo(String token) { - Object tokenObject = redisTemplate.opsForValue().get(token); - emptyUtil.isEmpty(tokenObject, MessageConstant.TOKEN_IS_EMPTY); - - UserInfo userInfo = JSON.parseObject((String) tokenObject, UserInfo.class); + // Object tokenObject = redisTemplate.opsForValue().get(token); + // emptyUtil.isEmpty(tokenObject, MessageConstant.TOKEN_IS_EMPTY); + // + // UserInfo userInfo = JSON.parseObject((String) tokenObject, UserInfo.class); + + UserInfo userInfo = BaseContext.getUserInfo(); UserInfoVo userInfoVo = new UserInfoVo(); BeanUtils.copyProperties(userInfo, userInfoVo);