15810770710@163.com il y a 4 ans
Parent
commit
6dd386a796

+ 82 - 0
deploy/cloud-yysj-gateway-protal.yaml

@@ -0,0 +1,82 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: cloud-yysj-gateway-protal
+  labels:
+    app: cloud-yysj-gateway-protal
+    svcEndpoints: actuator
+spec:
+  type: NodePort
+  ports:
+    - name: server
+      port: 8080
+      targetPort: 8080
+    - name: management
+      port: 8081
+      targetPort: 8081
+  selector:
+    app: cloud-yysj-gateway-protal
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: cloud-yysj-gateway-protal
+  labels:
+    app: cloud-yysj-gateway-protal
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: cloud-yysj-gateway-protal
+  template:
+    metadata:
+      name: cloud-yysj-gateway-protal
+      labels:
+        app: cloud-yysj-gateway-protal
+    spec:
+      restartPolicy: Always
+      containers:
+      - name: service-provider
+        image: hub.i139.cn/cloud-yysj/cloud-yysj-gateway-protal:1.0.0
+        imagePullPolicy: IfNotPresent
+        ports:
+        - name: server
+          containerPort: 8080
+        - name: management
+          containerPort: 8081
+        env:
+        - name: KUBERNETES_NAMESPACE
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.namespace
+        - name: POD_NAME
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.name
+        - name: JAVA_OPTS
+          value: ""
+        - name: APP_OPTS
+          value: ""
+        resources:
+          limits:
+            memory: 1000Mi
+            cpu: 2000m
+          requests:
+            memory: 256Mi
+            cpu: 1000m
+        readinessProbe:
+          initialDelaySeconds: 20
+          periodSeconds: 5
+          timeoutSeconds: 10
+          failureThreshold: 5
+          httpGet:
+            path: /actuator/health
+            port: 8081
+        livenessProbe:
+          initialDelaySeconds: 60
+          periodSeconds: 5
+          timeoutSeconds: 5
+          failureThreshold: 3
+          httpGet:
+            path: /actuator/health
+            port: 8081

+ 100 - 0
deploy/config-map.yaml

@@ -0,0 +1,100 @@
+kind: ConfigMap
+apiVersion: v1
+metadata:
+  name: cloud-yysj-gateway-protal
+data:
+  application.yaml: |-
+    url:
+      #处理路径
+      stateHandlingUrl:
+        - "/authentication/**"
+      #忽略鉴权路径
+      ignoreUrl:
+        - "/authentication/login/**"
+
+    hystrix:
+      command:
+        myusers-service:
+          execution:
+            isolation:
+              thread:
+                timeoutInMilliseconds: 20000
+
+    ribbon:
+      ReadTimeout: 60000
+      ConnectTimeout: 10000
+      SocketTimeout: 30000
+
+    zuul:
+      host:
+        connect-timeout-millis: 10000
+        socket-timeout-millis: 30000
+        max-per-route-connections: 100
+      routes:
+        #登录鉴权接口
+        login-authentication-service:
+          path: /authentication/**
+          url: http://cloud-yysj-login.cloud-yysj:8080
+        #首页及统计分析相关接口
+        analysis-info-service:
+          path: /analysisQuery/**
+          url: http://cloud-yysj-analysis-info.cloud-yysj:8080
+        #车辆查询相关接口
+        car-query-service:
+          path: /carQuery/**
+          url: http://cloud-yysj-car-query.cloud-yysj:8080
+        #费用管理相关接口
+        cost-query-service:
+          path: /costQuery/**
+          url: http://cloud-yysj-cost-query.cloud-yysj:8080
+        #运单查询相关接口
+        waybill-query-service:
+          path: /waybillQuery/**
+          url: http://cloud-yysj-waybill-query.cloud-yysj:8080
+        #司机查询相关接口
+        driver-info-service:
+          path: /driverQuery/**
+          url: http://cloud-yysj-driver-info.cloud-yysj:8080
+        #产品配置相关接口
+        product-info-service:
+          path: /productConfig/**
+          url: http://cloud-yysj-product-info.cloud-yysj:8080
+        #订单查询相关接口
+        order-query-service:
+          path: /orderQuery/**
+          url: http://cloud-yysj-order-query.cloud-yysj:8080
+
+#    zuul:
+#      routes:
+#        #登录鉴权接口
+#        login-authentication-service:
+#          path: /authentication/**
+#          serviceId: CLOUD-YYSJ-LOGIN-AUTHENTICATION
+#        #首页及统计分析相关接口
+#        analysis-info-service:
+#          path: /analysisQuery/**
+#          serviceId: CLOUD-YYSJ-ANALYSIS-INFO
+#        #车辆查询相关接口
+#        car-query-service:
+#          path: /carQuery/**
+#          serviceId: CLOUD-YYSJ-CAR-QUERY
+#        #费用管理相关接口
+#        cost-query-service:
+#          path: /costQuery/**
+#          serviceId: CLOUD-YYSJ-COST-QUERY
+#        #运单查询相关接口
+#        waybill-query-service:
+#          path: /waybillQuery/**
+#          serviceId: CLOUD-YYSJ-WAYBILL-QUERY
+#        #司机查询相关接口
+#        driver-info-service:
+#          path: /driverQuery/**
+#          serviceId: CLOUD-YYSJ-DRIVER-INFO
+#        #产品配置相关接口
+#        product-info-service:
+#          path: /productConfig/**
+#          serviceId: CLOUD-YYSJ-PRODUCT-INFO
+#        #订单查询相关接口
+#        order-query-service:
+#          path: /orderQuery/**
+#          serviceId: CLOUD-YYSJ-ORDER-QUERY

+ 134 - 0
pom.xml

@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.2.2.RELEASE</version>
+    </parent>
+
+    <groupId>info.aspirecn.cloud.yysj</groupId>
+    <artifactId>cloud-yysj-gateway-protal</artifactId>
+    <version>1.0.0</version>
+    <name>cloud-yysj-gateway-protal</name>
+    <description>cloud yysj platform gateway protal</description>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
+    </properties>
+
+    <dependencies>
+        <!--web-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <!--actuator-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <!--springcloud-kubernetes-config-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-kubernetes-config</artifactId>
+        </dependency>
+        <!--configuration-processor-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+        </dependency>
+        <!--lombok-->
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <!-- zuul-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
+        </dependency>
+        <!-- feign -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
+        </dependency>
+        <!-- commons-lang -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.9</version>
+        </dependency>
+        <!-- fastjson -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.62</version>
+        </dependency>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <!--设置应用 Main 参数启动依赖查找的地址指向外部 lib 文件夹-->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <addClasspath>true</addClasspath>
+                            <classpathPrefix>lib/</classpathPrefix>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+            <!--设置 SpringBoot 打包插件不包含任何 Jar 依赖包-->
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <includes>
+                        <include>
+                            <groupId>nothing</groupId>
+                            <artifactId>nothing</artifactId>
+                        </include>
+                    </includes>
+                </configuration>
+            </plugin>
+            <!--设置将 lib 拷贝到应用 Jar 外面-->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-dependencies</id>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 25 - 0
src/main/java/info/aspirecn/cloud/yysj/Application.java

@@ -0,0 +1,25 @@
+package info.aspirecn.cloud.yysj;
+
+import info.aspirecn.cloud.yysj.config.ConfigProperties;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
+import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @author dingliqiang
+ */
+@EnableZuulProxy
+@EnableFeignClients
+@SpringBootApplication
+@EnableCircuitBreaker
+@EnableConfigurationProperties({ConfigProperties.class})
+public class Application {
+
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+
+}

+ 18 - 0
src/main/java/info/aspirecn/cloud/yysj/config/ConfigProperties.java

@@ -0,0 +1,18 @@
+package info.aspirecn.cloud.yysj.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import java.util.List;
+
+/**
+ * @author dingliqiang
+ */
+@Data
+@ConfigurationProperties(prefix = "url")
+public class ConfigProperties {
+
+    private List<String> ignoreUrl;
+
+    private List<String> stateHandlingUrl;
+
+}

+ 29 - 0
src/main/java/info/aspirecn/cloud/yysj/config/ZuulConfig.java

@@ -0,0 +1,29 @@
+package info.aspirecn.cloud.yysj.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+
+/**
+ * @author dingliqiang
+ */
+@Configuration
+public class ZuulConfig {
+
+    /**
+     * Zuul 动态路由配置
+     *
+     * @return Zuul 参数对象
+     */
+    @Bean
+    @Primary
+    @RefreshScope
+    @ConfigurationProperties("zuul")
+    public ZuulProperties zuulProperties() {
+        return new ZuulProperties();
+    }
+
+}

+ 79 - 0
src/main/java/info/aspirecn/cloud/yysj/filters/error/ErrorFilter.java

@@ -0,0 +1,79 @@
+package info.aspirecn.cloud.yysj.filters.error;
+
+import com.alibaba.fastjson.JSON;
+import com.netflix.zuul.ZuulFilter;
+import com.netflix.zuul.context.RequestContext;
+import com.netflix.zuul.exception.ZuulException;
+import info.aspirecn.cloud.yysj.model.ResultResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpStatus;
+import org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ReflectionUtils;
+import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
+
+/**
+ * 异常处理
+ *
+ * @author dingliqiang
+ */
+@Slf4j
+@Component
+public class ErrorFilter extends ZuulFilter {
+
+    @Override
+    public String filterType() {
+        return "error";
+    }
+
+    @Override
+    public int filterOrder() {
+        return 0;
+    }
+
+    @Override
+    public boolean shouldFilter() {
+        return true;
+    }
+
+    @Override
+    public Object run() throws ZuulException {
+        PrintWriter writer = null;
+        try {
+            RequestContext context = RequestContext.getCurrentContext();
+            // 获取异常信息
+            ZuulException exception = this.findZuulException(context.getThrowable());
+            log.error("Zuul 异常处理", exception);
+            // 获取响应对象,并设置响应信息
+            HttpServletResponse response = context.getResponse();
+            response.setContentType("application/json; charset=utf8");
+            response.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
+            // 设置响应体
+            ResultResponse resultResponse = new ResultResponse();
+            resultResponse.setCode(500).setMessage("服务器繁忙").setData("");
+            String json = JSON.toJSONString(response);
+            // 响应信息
+            writer = response.getWriter();
+            writer.print(json);
+        } catch (Exception var5) {
+            ReflectionUtils.rethrowRuntimeException(var5);
+        } finally {
+            if (writer != null) {
+                writer.close();
+            }
+        }
+        return null;
+    }
+
+    ZuulException findZuulException(Throwable throwable) {
+        if (throwable.getCause() instanceof ZuulRuntimeException) {
+            return (ZuulException) throwable.getCause().getCause();
+        } else if (throwable.getCause() instanceof ZuulException) {
+            return (ZuulException) throwable.getCause();
+        } else {
+            return throwable instanceof ZuulException ? (ZuulException) throwable : new ZuulException(throwable, 500, "系统繁忙");
+        }
+    }
+
+}

+ 35 - 0
src/main/java/info/aspirecn/cloud/yysj/filters/error/ErrorHandlerController.java

@@ -0,0 +1,35 @@
+package info.aspirecn.cloud.yysj.filters.error;
+
+import info.aspirecn.cloud.yysj.model.ResultResponse;
+import org.apache.http.HttpStatus;
+import org.springframework.boot.web.servlet.error.ErrorController;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author dingliqiang
+ */
+@RestController
+public class ErrorHandlerController implements ErrorController {
+
+    @Override
+    public String getErrorPath() {
+        return "/error";
+    }
+
+    @GetMapping("/error")
+    public Object error(HttpServletRequest request, HttpServletResponse response) {
+        ResultResponse resultResponse = new ResultResponse();
+        Integer status = (Integer) request.getAttribute("javax.servlet.error.status_code");
+        if (status == HttpStatus.SC_NOT_FOUND) {
+            response.setStatus(HttpStatus.SC_NOT_FOUND);
+            resultResponse.setMessage("输入的地址不存在");
+            return resultResponse;
+        }
+        resultResponse.setMessage("系统繁忙");
+        return resultResponse;
+    }
+
+}

+ 73 - 0
src/main/java/info/aspirecn/cloud/yysj/filters/post/StateHandlingFilter.java

@@ -0,0 +1,73 @@
+package info.aspirecn.cloud.yysj.filters.post;
+
+import com.alibaba.fastjson.JSON;
+import com.netflix.zuul.ZuulFilter;
+import com.netflix.zuul.context.RequestContext;
+import com.netflix.zuul.exception.ZuulException;
+import info.aspirecn.cloud.yysj.model.ResultResponse;
+import info.aspirecn.cloud.yysj.utils.UrlUtil;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpStatus;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StreamUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * @author dingliqiang
+ */
+@Slf4j
+@Component
+public class StateHandlingFilter extends ZuulFilter {
+
+    @Autowired
+    private UrlUtil urlUtil;
+
+    @Override
+    public String filterType() {
+        return "post";
+    }
+
+    @Override
+    public int filterOrder() {
+        return 0;
+    }
+
+    @Override
+    public boolean shouldFilter() {
+        RequestContext context = RequestContext.getCurrentContext();
+        // 获取请求地址
+        String url = context.getRequest().getRequestURI();
+        // 验证请求地址是否为需要处理状态的地址,是则 true 执行,否则 false 不执行
+        return urlUtil.isStateHandingUrl(url);
+    }
+
+    @SneakyThrows(value = IOException.class)
+    @Override
+    public Object run() throws ZuulException {
+        RequestContext context = RequestContext.getCurrentContext();
+        InputStream stream = context.getResponseDataStream();
+        context.setSendZuulResponse(true);
+        if (stream != null) {
+            // 获取响应体数据
+            String body = StreamUtils.copyToString(stream, StandardCharsets.UTF_8);
+            // 设置响应内容
+            ResultResponse resultResponse = new ResultResponse();
+            resultResponse.setMessage("服务器繁忙,请稍后再试");
+            context.setResponseStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+            if (body.length() > 1) {
+                resultResponse = JSON.parseObject(body, ResultResponse.class);
+            }
+            context.setResponseStatusCode(resultResponse.getCode());
+            context.getResponse().setContentType("application/json; charset=utf8");
+            context.setResponseBody(JSON.toJSONString(resultResponse));
+
+        }
+        return null;
+    }
+
+}

+ 101 - 0
src/main/java/info/aspirecn/cloud/yysj/filters/pre/AuthenticationFilter.java

@@ -0,0 +1,101 @@
+package info.aspirecn.cloud.yysj.filters.pre;
+
+import com.alibaba.fastjson.JSON;
+import com.netflix.zuul.ZuulFilter;
+import com.netflix.zuul.context.RequestContext;
+import com.netflix.zuul.exception.ZuulException;
+import info.aspirecn.cloud.yysj.model.ResultResponse;
+import info.aspirecn.cloud.yysj.model.TokenEntity;
+import info.aspirecn.cloud.yysj.service.LoginService;
+import info.aspirecn.cloud.yysj.utils.UrlUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpStatus;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author dingliqiang
+ */
+@Slf4j
+@Component
+public class AuthenticationFilter extends ZuulFilter {
+
+    @Autowired
+    private UrlUtil urlUtil;
+
+    @Autowired
+    private LoginService loginService;
+
+    /**
+     * pre:可以在请求被路由之前调用
+     * route:在路由请求时候被调用
+     * post:在route和error过滤器之后被调用
+     * error:处理请求时发生错误时被调用
+     */
+    @Override
+    public String filterType() {
+        return "pre";
+    }
+
+    /**
+     * 优先级为0,数字越大,优先级越低
+     */
+    @Override
+    public int filterOrder() {
+        return 0;
+    }
+
+    @Override
+    public boolean shouldFilter() {
+        RequestContext context = RequestContext.getCurrentContext();
+        // 获取请求地址
+        String url = context.getRequest().getRequestURI();
+        // 验证请求地址是否为忽略地址
+        boolean isExecute = urlUtil.isIngressUrl(url);
+        // 如果是忽略地址,则设置为 false 不执行过滤器,否则 true 执行过滤器
+        return !isExecute;
+    }
+
+    @Override
+    public Object run() throws ZuulException {
+        RequestContext context = RequestContext.getCurrentContext();
+        // 检测 Headers 里面是否有 Token 信息
+        context.setSendZuulResponse(false);
+        String token = context.getRequest().getHeader("token");
+        if (token != null) {
+            // 验证 Token 是否正确,并且获取 userId
+            TokenEntity tokenEntity = new TokenEntity();
+            tokenEntity.setToken(token);
+            ResultResponse resultResponse = loginService.checkToken(tokenEntity);
+            if (resultResponse == null) {
+                // 如果为空,则返回500错误和自定义错误信息
+                ResultResponse response = new ResultResponse();
+                response.setCode(500).setMessage("服务器繁忙").setData("");
+                String json = JSON.toJSONString(response);
+                context.getResponse().setContentType("application/json; charset=utf8");
+                context.setResponseBody(json);
+                context.setResponseStatusCode(500);
+            } else if (resultResponse.getCode() != HttpStatus.SC_OK) {
+                // 如果响应体 code 不等于 200,则返回响应信息
+                context.setResponseStatusCode(resultResponse.getCode());
+                context.getResponse().setContentType("application/json; charset=utf8");
+                String json = JSON.toJSONString(resultResponse);
+                context.setResponseBody(json);
+            } else {
+                // 默认继续执行后续调用链
+                String userId = String.valueOf(resultResponse.getData());
+                context.addZuulRequestHeader("userId", userId);
+                context.setSendZuulResponse(true);
+            }
+        }else {
+            ResultResponse response = new ResultResponse();
+            response.setCode(400).setMessage("请求参数错误,请确认登录后再尝试").setData("");
+            String json = JSON.toJSONString(response);
+            context.getResponse().setContentType("application/json; charset=utf8");
+            context.setResponseBody(json);
+            context.setResponseStatusCode(400);
+        }
+        return null;
+    }
+
+}

+ 20 - 0
src/main/java/info/aspirecn/cloud/yysj/model/ResultResponse.java

@@ -0,0 +1,20 @@
+package info.aspirecn.cloud.yysj.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+@Data
+@ToString
+@Accessors(chain = true)
+public class ResultResponse {
+
+    @JSONField(serialize = false)
+    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
+    private Integer code;
+    private String message = "";
+    private Object data = "";
+
+}

+ 13 - 0
src/main/java/info/aspirecn/cloud/yysj/model/TokenEntity.java

@@ -0,0 +1,13 @@
+package info.aspirecn.cloud.yysj.model;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class TokenEntity {
+    /**
+     * token
+     */
+    private String token;
+}

+ 24 - 0
src/main/java/info/aspirecn/cloud/yysj/service/LoginService.java

@@ -0,0 +1,24 @@
+package info.aspirecn.cloud.yysj.service;
+
+import info.aspirecn.cloud.yysj.model.ResultResponse;
+import info.aspirecn.cloud.yysj.model.TokenEntity;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * @author dingliqiang
+ */
+@FeignClient(value = "${zuul.routes.login-authentication-service.url}",url = "${zuul.routes.login-authentication-service.url}")
+//@FeignClient(value = "http://10.8.17.119:31518", url ="http://10.8.17.119:31518")
+public interface LoginService {
+
+    /**
+     * 验证 Token
+     * @param tokenEntity 请求条件
+     * @return 验证结果
+     */
+    @PostMapping("/check")
+    ResultResponse checkToken(@RequestBody TokenEntity tokenEntity);
+
+}

+ 49 - 0
src/main/java/info/aspirecn/cloud/yysj/utils/UrlUtil.java

@@ -0,0 +1,49 @@
+package info.aspirecn.cloud.yysj.utils;
+
+import info.aspirecn.cloud.yysj.config.ConfigProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.AntPathMatcher;
+import java.util.List;
+
+/**
+ * @author dingliqiang
+ */
+@Component
+public class UrlUtil {
+
+    @Autowired
+    private ConfigProperties configProperties;
+
+    /**
+     * 路径匹配工具
+     */
+    private final AntPathMatcher antPathMatcher = new AntPathMatcher();
+
+    public synchronized boolean isIngressUrl(String url) {
+        // 路径匹配工具
+
+        // 获取忽略列表
+        List<String> ignoreUrlList = configProperties.getIgnoreUrl();
+        for (String ignoreUrl : ignoreUrlList) {
+            boolean isMatch = antPathMatcher.match(ignoreUrl, url);
+            if (isMatch) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public synchronized boolean isStateHandingUrl(String url) {
+        // 获取忽略列表
+        List<String> ignoreUrlList = configProperties.getStateHandlingUrl();
+        for (String ignoreUrl : ignoreUrlList) {
+            boolean isMatch = antPathMatcher.match(ignoreUrl, url);
+            if (isMatch) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

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

@@ -0,0 +1,74 @@
+#url:
+#  #处理路径
+#  stateHandlingUrl:
+#    - "/authentication/**"
+#  #忽略鉴权路径
+#  ignoreUrl:
+#    - "/authentication/login/**"
+#
+#hystrix:
+#  command:
+#    myusers-service:
+#      execution:
+#        isolation:
+#          thread:
+#            timeoutInMilliseconds: 15000
+#
+#ribbon:
+#  ReadTimeout: 60000
+#  ConnectTimeout: 10000
+#  SocketTimeout: 30000
+#
+#zuul:
+#  host:
+#    connect-timeout-millis: 5000
+#    socket-timeout-millis: 10000
+#  routes:
+#    #登录鉴权接口
+#    login-authentication-service:
+#      path: /authentication/**
+#      url: http://10.8.17.119:31518
+#      #url: http://cloud-yysj-login-authentication:8080
+#    product-info-service:
+#      path: /productConfig/**
+#      url: http://10.8.17.119:31469
+#
+#
+#
+##zuul:
+##  host:
+##    connect-timeout-millis: 5000
+##    socket-timeout-millis: 10000
+##  routes:
+##    #登录鉴权接口
+##    login-authentication-service:
+##      path: /authentication/**
+##      url: http://cloud-yysj-login-authentication:8080
+##    #首页及统计分析相关接口
+##    analysis-info-service:
+##      path: /analysisQuery/**
+##      url: http://cloud-yysj-analysis-info:8080
+##    #车辆查询相关接口
+##    car-query-service:
+##      path: /carQuery/**
+##      url: http://cloud-yysj-car-query:8080
+##    #费用管理相关接口
+##    cost-query-service:
+##      path: /costQuery/**
+##      url: http://cloud-yysj-cost-query:8080
+##    #运单查询相关接口
+##    waybill-query-service:
+##      path: /waybillQuery/**
+##      url: http://cloud-yysj-waybill-query:8080
+##    #司机查询相关接口
+##    driver-info-service:
+##      path: /driverQuery/**
+##      url: http://cloud-yysj-driver-info:8080
+##    #产品配置相关接口
+##    product-info-service:
+##      path: /productConfig/**
+##      url: http://cloud-yysj-product-info:8080
+##    #订单查询相关接口
+##    order-query-service:
+##      path: /orderQuery/**
+##      url: http://cloud-yysj-order-query:8080

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

@@ -0,0 +1,39 @@
+#ConfigMap 配置参数
+server:
+  port: 8080
+spring:
+  application:
+    name: cloud-yysj-gateway-protal
+  cloud:
+    kubernetes:
+      reload:
+        enabled: true
+        mode: polling
+        period: 10000
+        strategy: refresh
+        monitoring-secrets: true
+      config:
+        enabled: true
+        enableApi: true
+        sources:
+          - namespace: cloud-yysj
+            name: ${spring.application.name}
+
+#监控配置参数
+management:
+  server:
+    port: 8081
+  endpoint:
+    restart:
+      enabled: true
+    health:
+      show-details: always
+  endpoints:
+    enabled-by-default: true
+    web:
+      exposure:
+        include: "*"
+
+info:
+  name: protal 网关服务
+  version: 1.0.0