Browse Source

first commit1

anderx 1 year ago
parent
commit
682f41e25a

+ 11 - 0
Dockerfile

@@ -0,0 +1,11 @@
+FROM openjdk:11-jre
+
+RUN echo "Asia/Shanghai" > /etc/timezone && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+
+WORKDIR /app
+
+COPY target/api_gateway.jar /app
+
+EXPOSE 8082
+
+CMD ["java", "-jar", "api_gateway.jar"]

+ 85 - 0
pom.xml

@@ -0,0 +1,85 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.jishutao.brain</groupId>
+        <artifactId>core-parent</artifactId>
+        <version>1.0.1</version>
+    </parent>
+
+    <artifactId>api_gateway</artifactId>
+    <version>0.0.1</version>
+    <name>API Gateway</name>
+    <description>API Gateway</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-gateway</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-devtools</artifactId>
+            <optional>true</optional>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.jishutao.brain</groupId>
+            <artifactId>common-library</artifactId>
+            <version>1.0.1</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-web</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <!-- jwt -->
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt</artifactId>
+            <version>${jjwt.version}</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <!-- redis -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>jakarta.xml.bind</groupId>
+            <artifactId>jakarta.xml.bind-api</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <finalName>api_gateway</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <includeSystemScope>true</includeSystemScope>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 11 - 0
src/main/java/com/sciradar/api_gateway/APIGatewayApplication.java

@@ -0,0 +1,11 @@
+package com.sciradar.api_gateway;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class APIGatewayApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(APIGatewayApplication.class, args);
+    }
+}

+ 28 - 0
src/main/java/com/sciradar/api_gateway/config/ApiGatewayConfiguration.java

@@ -0,0 +1,28 @@
+package com.sciradar.api_gateway.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@Configuration
+@ConfigurationProperties(prefix = "api-gateway")
+@Data
+public class ApiGatewayConfiguration {
+    private Endpoint endpoint;
+
+    private Filter filter;
+
+    @Data
+    public static class Filter {
+        private List<String> ignores;
+
+    }
+
+    @Data
+    public static class Endpoint {
+        private String search = "http://search-service:8080";
+        private String user = "http://user-service:8080";
+    }
+}

+ 31 - 0
src/main/java/com/sciradar/api_gateway/config/CorsConfig.java

@@ -0,0 +1,31 @@
+package com.sciradar.api_gateway.config;
+
+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;
+import org.springframework.web.util.pattern.PathPatternParser;
+
+@Configuration
+public class CorsConfig {
+
+    @Bean
+    public CorsWebFilter corsFilter() {
+        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
+        final CorsConfiguration config = new CorsConfiguration();
+        // 允许cookies跨域
+        config.setAllowCredentials(true);
+        // #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
+        config.addAllowedOriginPattern("*");
+        // #允许访问的头信息,*表示全部
+        config.addAllowedHeader("*");
+        // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
+        config.setMaxAge(18000L);
+        // 允许提交请求的方法,*表示全部允许
+        config.addAllowedMethod("*");
+        source.registerCorsConfiguration("/**", config);
+
+        return new CorsWebFilter(source);
+    }
+}

+ 35 - 0
src/main/java/com/sciradar/api_gateway/config/Routes.java

@@ -0,0 +1,35 @@
+package com.sciradar.api_gateway.config;
+
+import org.springframework.cloud.gateway.route.RouteLocator;
+import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+@Component
+public class Routes {
+    private final ApiGatewayConfiguration configuration;
+
+    public Routes(ApiGatewayConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    @Bean
+    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
+        ApiGatewayConfiguration.Endpoint endpoint = configuration.getEndpoint();
+        System.out.println(endpoint);
+        System.out.println(endpoint.getSearch());
+        System.out.println(endpoint.getUser());
+        return builder.routes()
+                .route("search",
+                        r -> r.path("/gw/search/**")
+                                .filters(f ->
+                                        f.rewritePath("/gw/search/(?<segment>.*)", "/v1/${segment}"))
+                                .uri(endpoint.getSearch()))
+                .route("user",
+                        r -> r.path("/gw/user/**")
+                                .filters(f ->
+                                        f.rewritePath("/gw/user/(?<segment>.*)", "/${segment}"))
+                                .uri(endpoint.getUser()))
+                .build();
+    }
+}

+ 22 - 0
src/main/java/com/sciradar/api_gateway/fallback/DefaultHystrixController.java

@@ -0,0 +1,22 @@
+package com.sciradar.api_gateway.fallback;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @deseription 服务默认降级处理
+ * @author: tq
+ * @date: 2021/12/18 17:42
+ * @version 1.0
+ **/
+@RestController
+@Slf4j
+public class DefaultHystrixController {
+
+    @RequestMapping("/defaultfallback")
+    public void fallback() {
+        //响应体
+        log.error("fallback,服务不可用,降级处理");
+    }
+}

+ 206 - 0
src/main/java/com/sciradar/api_gateway/filter/PreAdminTokenRequestFilter.java

@@ -0,0 +1,206 @@
+package com.sciradar.api_gateway.filter;
+
+import com.sciradar.api_gateway.config.ApiGatewayConfiguration;
+import com.sciradar.api_gateway.jwt.JwtTokenHelper;
+import com.sciradar.api_gateway.util.RedisCacheUtils;
+import com.sciradar.component.DefaultMessageSource;
+import com.sciradar.constant.Constants;
+import com.sciradar.support.R;
+import com.sciradar.support.entity.UserVO;
+import com.sciradar.util.JsonUtil;
+import io.jsonwebtoken.JwtBuilder;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.gateway.filter.GatewayFilterChain;
+import org.springframework.cloud.gateway.filter.GlobalFilter;
+import org.springframework.context.support.ResourceBundleMessageSource;
+import org.springframework.core.Ordered;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.stereotype.Component;
+import org.springframework.util.AntPathMatcher;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.Key;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import static com.sciradar.constant.Constants.HTTP_HEADER_FROM;
+import static com.sciradar.constant.Constants.HTTP_HEADER_USER_ID;
+
+
+/**
+ * 过滤拦截器
+ **/
+@Slf4j
+@Component
+public class PreAdminTokenRequestFilter implements GlobalFilter, Ordered {
+
+    private final AntPathMatcher pathMatcher = new AntPathMatcher();
+
+    @Autowired
+    private RedisCacheUtils redisCacheUtils;
+
+    @Value("${jwt.header:Authorization}")
+    private String header;
+
+    private final List<String> ignores;
+
+    @Autowired
+    private JwtTokenHelper jwtTokenHelper;
+
+    @Autowired
+    private ResourceBundleMessageSource messageSource;
+
+    private DefaultMessageSource defaultMessageSource = new DefaultMessageSource();
+
+    ExecutorService exec = Executors.newFixedThreadPool(2);
+
+    public PreAdminTokenRequestFilter(ApiGatewayConfiguration configuration) {
+        this.ignores = configuration.getFilter().getIgnores();
+    }
+
+    @Override
+    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
+        ServerHttpResponse response = exchange.getResponse();
+        ServerHttpRequest request = exchange.getRequest();
+
+        String uri = request.getURI().getPath();
+        log.info("send {} request to {}", request.getMethod(), uri);
+        // 过滤排除项
+        for (String path : ignores) {
+            if (pathMatcher.match(path, uri)) {
+                log.info("ignore auth for url {}", uri);
+                //向headers中放文件
+                String secretKey = redisCacheUtils.createToken(Constants.SECRET_KEY);
+                ServerHttpRequest host = request.mutate().header(Constants.SECRET_KEY, secretKey).build();
+                //将现在的request 变成 change对象
+                ServerWebExchange build = exchange.mutate().request(host).build();
+                return chain.filter(build);
+            }
+        }
+
+        log.info("authentication verification");
+
+//        response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
+
+        String token = request.getHeaders().getFirst(header);
+        if (token == null || token.trim().equals("")) {
+            token = request.getQueryParams().getFirst("token");
+        }
+
+        String json = JsonUtil.getJsonFromObject(i18nConverter(1002));
+        DataBuffer data = exchange.getResponse().bufferFactory().wrap(json.getBytes(StandardCharsets.UTF_8));
+        if (token == null || "".equals(token)) {
+            response.setStatusCode(HttpStatus.UNAUTHORIZED);
+            return response.writeWith(Mono.just(data));
+        }
+
+        String key = "oauth_token:" + token;
+        if (!redisCacheUtils.hasKey(key)) {
+            response.setStatusCode(HttpStatus.UNAUTHORIZED);
+            return response.writeWith(Mono.just(data));
+        }
+
+        //校验TOKEN
+        R<UserVO> result = jwtTokenHelper.checkToken(redisCacheUtils.opsForValueGet(key));
+        if (result == null || !Constants.DEFAULT_SUCCESS_STATUS.equals(result.getStatus()) || result.getData() == null) {
+            response.setStatusCode(HttpStatus.UNAUTHORIZED);
+            return response.writeWith(Mono.just(data));
+        }
+
+        String userToken = generateUserToken(result.getData());
+        redisCacheUtils.opsForValueSet(key, userToken, Constants.JWTEXPIRATION * 2, TimeUnit.SECONDS);
+
+        String userInfo = JsonUtil.getJsonFromObject(result.getData());
+        String secretKey = redisCacheUtils.createToken(Constants.SECRET_KEY);
+        //向headers中放文件
+        ServerHttpRequest newRequest = null;
+        try {
+            newRequest = request.mutate()
+                    .header(Constants.CURRENT_USER, URLEncoder.encode(userInfo, Constants.CHARSET_UTF8))
+                    .header(Constants.SECRET_KEY, secretKey)
+                    .header(HTTP_HEADER_USER_ID, ""+result.getData().getId())
+                    .header(HTTP_HEADER_FROM, "PRO")
+                    .build();
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        // 将现在的request 变成 change对象
+        ServerWebExchange build = null;
+        if (newRequest != null) {
+            build = exchange.mutate().request(newRequest).build();
+        }
+
+        return chain.filter(build);
+
+    }
+
+    @Override
+    public int getOrder() {
+        return -100;
+    }
+
+    private static R<Object> i18nConverter(ServerHttpRequest request, ResourceBundleMessageSource messageSource, Integer status, String... args) {
+        String lang = !StringUtils.isEmpty(request.getHeaders().getFirst(HttpHeaders.ACCEPT_LANGUAGE)) ? request.getHeaders().getFirst(HttpHeaders.ACCEPT_LANGUAGE) : request.getQueryParams().getFirst("lang");
+        messageSource.addBasenames("default");
+        Locale locale = !StringUtils.isEmpty(lang) ? new Locale(lang) : Locale.getDefault();
+        String message = messageSource.getMessage(String.valueOf(status), args, locale);
+        return new R<>(status, message);
+    }
+
+    private R<Object> i18nConverter(Integer status, String... args) {
+        String message = defaultMessageSource.getMessage(status, args);
+        return new R<>(status, message);
+    }
+
+    /**
+     *  生成token
+     * @author tq
+     * @date 2021/12/10 23:37
+     * @param User
+     */
+    private String generateUserToken(UserVO User) {
+        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
+
+        long nowMillis = System.currentTimeMillis();
+        Date now = new Date(nowMillis);
+        // 生成签名密钥
+        byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(Constants.JWTSECTET);
+        Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());
+        // 添加构成JWT的参数
+
+        JwtBuilder builder = Jwts.builder().claim(Constants.CURRENT_USER, JsonUtil.getJsonFromObject(User))
+                .setIssuer(Constants.JWTISSUER)
+                .setAudience(User.getId().toString())
+                .setIssuedAt(now)
+                .signWith(signatureAlgorithm, signingKey);
+        // 添加Token过期时间
+        if (Constants.JWTEXPIRATION >= 0) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.SECOND, Constants.JWTEXPIRATION);
+            builder.setNotBefore(now).setExpiration(calendar.getTime());
+        }
+        // 生成JWT
+        return Constants.JWTPREFIX + builder.compact();
+    }
+}

+ 59 - 0
src/main/java/com/sciradar/api_gateway/jwt/JwtTokenHelper.java

@@ -0,0 +1,59 @@
+package com.sciradar.api_gateway.jwt;
+
+import com.sciradar.constant.Constants;
+import com.sciradar.support.R;
+import com.sciradar.support.entity.UserVO;
+import com.sciradar.util.JsonUtil;
+import io.jsonwebtoken.*;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Calendar;
+import java.util.Date;
+
+
+/**
+ * @deseription token生成解析
+ * @author: tq
+ * @date: 2021/12/18 17:52
+ * @version 1.0
+ **/
+@Component
+@Slf4j
+public class JwtTokenHelper {
+
+    public R<UserVO> checkToken(String token) {
+        log.debug("解析TOKEN:" + token);
+        try {
+            if (token != null && token.startsWith(Constants.JWTPREFIX)) {
+                String authToken = token.substring(Constants.JWTPREFIX.length());
+                Claims claims = Jwts.parser().setSigningKey(DatatypeConverter.parseBase64Binary(Constants.JWTSECTET))
+                        .parseClaimsJws(authToken).getBody();
+                if (claims != null) {
+                    String userInfoStr = claims.get(Constants.CURRENT_USER, String.class);
+                    if (userInfoStr != null) {
+                        UserVO userVO = JsonUtil.getObjectFromJson(URLDecoder.decode(userInfoStr, Constants.CHARSET_UTF8), UserVO.class);
+                        return R.ok(userVO);
+                    }
+                }
+            }
+        } catch (ExpiredJwtException e) {
+            log.error("token 已经过期:" + token);
+        } catch (IllegalArgumentException e) {
+            log.error("token 非法:" + token);
+        } catch (MalformedJwtException e) {
+            log.error("解析TOKEN 错误:" + token);
+        } catch (SignatureException e) {
+            log.error("解析TOKEN 错误:" + token);
+        } catch (UnsupportedJwtException e) {
+            log.error("解析TOKEN 错误:" + token);
+        } catch (UnsupportedEncodingException e) {
+            log.error("解析TOKEN 错误:" + token);
+        }
+        log.debug("token 校验失败:" + token);
+        return null;
+    }
+}

+ 151 - 0
src/main/java/com/sciradar/api_gateway/util/RedisCacheUtils.java

@@ -0,0 +1,151 @@
+package com.sciradar.api_gateway.util;
+
+import com.sciradar.constant.Constants;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * @deseription Redis操作类
+ * @author: tq
+ * @date: 2021/12/18 22:58
+ * @version 1.0
+**/
+@Component
+public class RedisCacheUtils {
+
+    @Autowired
+    private StringRedisTemplate stringredisTemplate;
+
+    //opsForValue相关操作
+    public void opsForValueSet(String key, String value) {
+        stringredisTemplate.opsForValue().set(key, value);
+    }
+    public void opsForValueSet(String key, String value, long timeout, TimeUnit unit) {
+        stringredisTemplate.opsForValue().set(key, value, timeout, unit);
+    }
+    public String opsForValueGet(String key) {
+        return stringredisTemplate.opsForValue().get(key);
+    }
+
+
+    //opsForSet 相关操作
+    public Set<String> opsForSetGet(String prex){
+
+        return stringredisTemplate.keys(prex);
+    }
+
+    //opsForHash相关操作
+    public void opsForHashPut(String key, String hashKey, Object value) {
+        stringredisTemplate.opsForHash().put(key, hashKey, value);
+    }
+    public void opsForHashDel(String key, String hashKey) {
+        stringredisTemplate.opsForHash().delete(key, hashKey);
+    }
+    public Boolean opsForHashHasKey(String key, String hashKey) {
+        return stringredisTemplate.opsForHash().hasKey(key, hashKey);
+    }
+    public Object opsForHashGet(String key, String hashKey) {
+        return stringredisTemplate.opsForHash().get(key, hashKey);
+    }
+    public Set<Object> opsForHashKeys(String key) {
+        return stringredisTemplate.opsForHash().keys(key);
+    }
+    public List<?> opsForHashValues(String key) {
+        return stringredisTemplate.opsForHash().values(key);
+    }
+
+
+    //opsForSet相关操作
+    public void opsForSetAdd(String key, String value) {
+        stringredisTemplate.opsForSet().add(key, value);
+    }
+    public Set<String> opsForSetRange(String key) {
+        return stringredisTemplate.opsForSet().members(key);
+    }
+    public void opsForSetDel(String key, Object value) {
+        stringredisTemplate.opsForSet().remove(key, value);
+    }
+
+
+    //opsForList相关操作
+    public void opsForListLeftPush(String key, String value) {
+        stringredisTemplate.opsForList().leftPush(key, value);
+    }
+    public void opsForListRightPush(String key, String value) {
+        stringredisTemplate.opsForList().rightPush(key, value);
+    }
+    public String opsForListLeftPop(String key) {
+        return stringredisTemplate.opsForList().leftPop(key);
+    }
+    public Long opsForListSize(String key) {
+        return stringredisTemplate.opsForList().size(key);
+    }
+    public List<String> opsForListRange(String key, final long start, final long end) {
+        return stringredisTemplate.opsForList().range(key, start, end);
+    }
+    public List<String> opsForListGet(String key) {
+        List<String> dataList = new ArrayList<>();
+        Long listSize = opsForListSize(key);
+        for (int i = 0; i < listSize; i++) {
+            dataList.add(stringredisTemplate.opsForList().index(key,i));
+        }
+        return dataList;
+    }
+    public void opsForListSet(String key, List<String> list) {
+        if(list!=null) {
+            int listSize = list.size();
+            for (int i = 0; i < listSize; i++) {
+                stringredisTemplate.opsForList().leftPush(key, list.get(i));
+            }
+        }
+    }
+
+
+    //基本操作 删除、存在
+    public Boolean hasKey(String key) {
+        return stringredisTemplate.hasKey(key);
+    }
+    public void delKey(String key) {
+        stringredisTemplate.delete(key);
+    }
+    public long ttl(String key, final TimeUnit timeUnit) {
+        return stringredisTemplate.getExpire(key, timeUnit);
+    }
+    public void expire(String key, long timeout, TimeUnit unit) {
+        stringredisTemplate.expire(key, timeout, unit);
+    }
+
+
+    /**
+     *
+     * @author tq 添加token
+     * @date 2021/12/18 22:59
+     * @param key
+     * @return java.lang.String
+     */
+    public String createToken(String key) {
+        if (null == key || "".equals(key)) {
+            return null;
+        }
+        String secretKey;
+        if (hasKey(key)) {
+            if (ttl(key, TimeUnit.SECONDS) < Constants.LASTTIME) {
+                opsForValueSet(key, new BCryptPasswordEncoder(Constants.PW_ENCORDER_SALT).encode((UUID.randomUUID().toString())), Constants.EXPIRATION, TimeUnit.SECONDS);
+            }
+            secretKey = opsForValueGet(key);
+        } else {
+            secretKey = new BCryptPasswordEncoder(Constants.PW_ENCORDER_SALT).encode((UUID.randomUUID().toString()));
+            opsForValueSet(key, secretKey, Constants.EXPIRATION, TimeUnit.SECONDS);
+        }
+        return secretKey;
+    }
+}

+ 32 - 0
src/main/resources/application.yml

@@ -0,0 +1,32 @@
+server:
+  port: 8088
+
+spring:
+  redis:
+    host: 127.0.0.1
+    port: 6379
+    password: aft123456
+    timeout: 5000
+    jedis:
+      pool:
+        max-active: 1024
+        max-wait: -1
+        max-idle: 200
+        min-idle: 0
+
+api-gateway:
+  endpoint:
+    user: "http://localhost:8081"
+    search: "http://localhost:8082"
+
+  filter:
+    ignores:
+      - /**/login/**
+      - /**/usersApply/**
+      - /**/doc.html
+      - /**/ui
+      - /**/swagger-resources
+      - /**/api-docs
+      - /**/webjars/**
+      - /**/sendSmsMessage/**
+      - /**/user/rest/**

+ 3 - 0
src/main/resources/bootstrap.yml

@@ -0,0 +1,3 @@
+spring:
+  application:
+    name: api_gateway

+ 0 - 0
src/main/resources/messages.properties


+ 1 - 0
src/main/resources/messages_en_US.properties

@@ -0,0 +1 @@
+0=此消息配置可以为空,但不能删除,否则不会触发spring boot 消息自动配置

+ 1 - 0
src/main/resources/messages_zh_CN.properties

@@ -0,0 +1 @@
+0=此消息配置可以为空,但不能删除,否则不会触发spring boot 消息自动配置