Przeglądaj źródła

gateway网关配置

yinhao 4 lat temu
rodzic
commit
d8ab5d237d

+ 53 - 0
huimv-mobile-video/huimv-gateway/pom.xml

@@ -0,0 +1,53 @@
+<?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.4.5</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.huimv</groupId>
+    <artifactId>huimv-gateway</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>huimv-gateway</name>
+    <description>Demo project for Gateway</description>
+    <properties>
+        <java.version>1.8</java.version>
+        <spring-cloud.version>2020.0.2</spring-cloud.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-gateway</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </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>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
huimv-mobile-video/huimv-gateway/src/main/java/com/huimv/gateway/HuimvGatewayApplication.java

@@ -0,0 +1,13 @@
+package com.huimv.gateway;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class HuimvGatewayApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(HuimvGatewayApplication.class, args);
+    }
+
+}

+ 32 - 0
huimv-mobile-video/huimv-gateway/src/main/resources/application-dev.yml

@@ -0,0 +1,32 @@
+server:
+  port: 8088
+
+spring:
+  application:
+    name: huimv-gateway
+
+  cloud:
+
+    gateway:
+      globalcors:
+        cors-configurations:
+          '[/**]':
+            allowedHeaders: "*"
+            allowedOrigins: "*"
+#            allowCredentials: true
+            allowedMethods:
+              - GET
+              - POST
+              - DELETE
+              - PUT
+              - OPTION
+            maxAge: 1800
+      routes:
+        - id: huimv-manager
+          uri: http://192.168.1.57:9105/
+          predicates:
+            - Path=/manager/**
+          filters:
+            - RewritePath=/manager/(?<segment>/?.*), /$\{segment}
+
+

+ 1 - 0
huimv-mobile-video/huimv-gateway/src/main/resources/application.properties

@@ -0,0 +1 @@
+spring.profiles.active=dev

+ 13 - 0
huimv-mobile-video/huimv-gateway/src/test/java/com/huimv/gateway/HuimvGatewayApplicationTests.java

@@ -0,0 +1,13 @@
+package com.huimv.gateway;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class HuimvGatewayApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}

+ 4 - 0
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/entity/MobileUnit.java

@@ -47,4 +47,8 @@ public class MobileUnit implements Serializable {
     private String api;
 
 
+    @Column(name = "fid")
+    @ApiModelProperty("fid")
+    private Integer fid;
+
 }

+ 3 - 1
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/service/impl/MobileUserServiceImpl.java

@@ -90,12 +90,14 @@ public class MobileUserServiceImpl implements MobileUserService {
             String ycgApi = mobileUnitRepository.findByShortNameLike("油车港").get(0).getApi();
             String wyApi = mobileUnitRepository.findByShortNameLike("武义").get(0).getApi();
             String wjjApi = mobileUnitRepository.findByShortNameLike("王江泾").get(0).getApi();
+
+            entity.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
             mobileUserRepository.save(entity);
 
             RestTemplate restTemplate  = new RestTemplate();
             Integer id = mobileUserRepository.findID();
             Integer grantClass = entity.getGrantClass();
-            entity.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
+
             if (grantClass ==null){
                 return new Result(10000,"msg");
             }

+ 10 - 39
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/util/JwtUtils.java

@@ -15,7 +15,16 @@ import java.util.Date;
  */
 public class JwtUtils {
 
-    private static final long EXPIRE = 1000 * 60 * 60 * 24;
+//    /**
+//     * 一天
+//     */
+//    private static final long EXPIRE = 1000 * 60 * 60 * 24;
+
+    /**
+     * 一小时
+     */
+    private static final long EXPIRE = 1000 * 60 * 60;
+
     private static final String APP_SECRET = "ukc8BDbRigUDaY6pZFfWus2jZWLPHO";
     private static final int REFRESH_TIME = 300;
 
@@ -128,42 +137,4 @@ public class JwtUtils {
             return 2;
         }
     }
-
-
-    /**
-     * 获取token中的claims信息
-     *
-     * @param token
-     * @return
-     */
-    private static Jws<Claims> getJws(String token) {
-        return Jwts.parser()
-                .setSigningKey(generalKey())
-                .parseClaimsJws(token);
-    }
-
-    /**
-     * 获取payload body信息
-     *
-     * @param token
-     * @return
-     */
-    public static Claims getClaimsBody(String token) {
-        try {
-            return getJws(token).getBody();
-        }catch (ExpiredJwtException e){
-            return null;
-        }
-    }
-
-    /**
-     * 由字符串生成加密key
-     *
-     * @return
-     */
-    public static SecretKey generalKey() {
-        byte[] encodedKey = Base64.getEncoder().encode(APP_SECRET.getBytes());
-        SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
-        return key;
-    }
 }