dev-v2 #3
|
@ -18,10 +18,10 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- lombok的依赖 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>com.atguigu</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>spzx-model</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- gateway -->
|
<!-- gateway -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
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("/**", config);
|
||||||
|
|
||||||
|
return new CorsWebFilter(source);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.atguigu.gateway.controller;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.model.vo.result.Result;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RequestMapping("/")
|
||||||
|
@RestController
|
||||||
|
@Slf4j
|
||||||
|
public class IndexController {
|
||||||
|
@GetMapping()
|
||||||
|
public Result<String> index() {
|
||||||
|
return Result.success("欢迎访问。。。");
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,9 @@ spring:
|
||||||
active: dev
|
active: dev
|
||||||
application:
|
application:
|
||||||
name: service-gateway
|
name: service-gateway
|
||||||
|
main:
|
||||||
|
web-application-type: reactive
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
|
@ -20,16 +23,16 @@ spring:
|
||||||
locator:
|
locator:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 解决跨域
|
# 解决跨域
|
||||||
globalcors:
|
# globalcors:
|
||||||
cors-configurations:
|
# cors-configurations:
|
||||||
'[/**]':
|
# '[/**]':
|
||||||
allowedOriginPatterns: "*"
|
# allowedOriginPatterns: "*"
|
||||||
# 允许请求中携带的头信息
|
# # 允许请求中携带的头信息
|
||||||
allowedHeaders: "*"
|
# allowedHeaders: "*"
|
||||||
# 运行跨域的请求方式
|
# # 运行跨域的请求方式
|
||||||
allowedMethods: "*"
|
# allowedMethods: "*"
|
||||||
# 跨域检测的有效期,单位s
|
# # 跨域检测的有效期,单位s
|
||||||
maxAge: 36000
|
# maxAge: 3600099
|
||||||
# 路由
|
# 路由
|
||||||
routes:
|
routes:
|
||||||
- id: service-product
|
- id: service-product
|
||||||
|
|
|
@ -20,4 +20,16 @@
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<target>8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.atguigu.user.service.impl;
|
package com.atguigu.user.service.impl;
|
||||||
|
|
||||||
import com.atguigu.constant.MessageConstant;
|
import com.atguigu.constant.MessageConstant;
|
||||||
import com.atguigu.exception.BunnyException;
|
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||||
|
import com.atguigu.user.mapper.UserInfoMapper;
|
||||||
import com.atguigu.user.service.SmsService;
|
import com.atguigu.user.service.SmsService;
|
||||||
import com.atguigu.user.service.module.SmsServiceModule;
|
import com.atguigu.user.service.module.SmsServiceModule;
|
||||||
|
import com.atguigu.utils.EmptyUtil;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
@ -15,6 +17,10 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class SmsServiceImpl implements SmsService {
|
public class SmsServiceImpl implements SmsService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private UserInfoMapper userInfoMapper;
|
||||||
|
@Autowired
|
||||||
|
private EmptyUtil emptyUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送短信
|
* 发送短信
|
||||||
|
@ -24,9 +30,10 @@ public class SmsServiceImpl implements SmsService {
|
||||||
@Override
|
@Override
|
||||||
public void sendValidateCode(String phone) throws Exception {
|
public void sendValidateCode(String phone) throws Exception {
|
||||||
Object isExist = redisTemplate.opsForValue().get(phone);
|
Object isExist = redisTemplate.opsForValue().get(phone);
|
||||||
if (isExist != null) {
|
UserInfo userInfo = userInfoMapper.selectByUsername(phone);
|
||||||
throw new BunnyException(MessageConstant.MESSAGE_CODE_NOT_PASS);
|
emptyUtil.isNotEmpty(isExist, MessageConstant.MESSAGE_CODE_NOT_PASS);
|
||||||
}
|
emptyUtil.isNotEmpty(userInfo, MessageConstant.USER_DOES_IS_EXIST);
|
||||||
|
|
||||||
// 1. 生成验证码
|
// 1. 生成验证码
|
||||||
String code = RandomStringUtils.randomNumeric(4);
|
String code = RandomStringUtils.randomNumeric(4);
|
||||||
// 2. 生成的验证码放到Redis中,设置过期时间
|
// 2. 生成的验证码放到Redis中,设置过期时间
|
||||||
|
|
Loading…
Reference in New Issue