张涛 1 vuosi sitten
vanhempi
commit
710fab43f6

+ 20
- 11
pom.xml Näytä tiedosto

@@ -86,21 +86,30 @@
86 86
             <version>3.3.1</version>
87 87
         </dependency>
88 88
 
89
-        <!--mybatis-plus start-->
90
-        <dependency>
91
-            <groupId>com.baomidou</groupId>
92
-            <artifactId>mybatis-plus-boot-starter</artifactId>
93
-            <version>3.5.1</version>
94
-        </dependency>
95
-        <!--mybatis-plus end-->
96
-
97
-        <!--weixin-miniapp start-->
89
+<!--        &lt;!&ndash;mybatis-plus start&ndash;&gt;-->
90
+<!--        <dependency>-->
91
+<!--            <groupId>com.baomidou</groupId>-->
92
+<!--            <artifactId>mybatis-plus-boot-starter</artifactId>-->
93
+<!--            <version>3.5.1</version>-->
94
+<!--        </dependency>-->
95
+<!--        &lt;!&ndash;mybatis-plus end&ndash;&gt;-->
96
+
97
+        <!--weixin-h5 start-->
98 98
         <dependency>
99 99
             <groupId>com.github.binarywang</groupId>
100
-            <artifactId>weixin-java-miniapp</artifactId>
100
+            <artifactId>weixin-java-cp</artifactId>
101 101
             <version>4.4.0</version>
102 102
         </dependency>
103
-        <!--weixin-miniapp start-->
103
+        <!--weixin-h5 end-->
104
+
105
+
106
+<!--        &lt;!&ndash;weixin-miniapp start&ndash;&gt;-->
107
+<!--        <dependency>-->
108
+<!--            <groupId>com.github.binarywang</groupId>-->
109
+<!--            <artifactId>weixin-java-miniapp</artifactId>-->
110
+<!--            <version>4.4.0</version>-->
111
+<!--        </dependency>-->
112
+<!--        &lt;!&ndash;weixin-miniapp end&ndash;&gt;-->
104 113
 
105 114
         <!--swagger start-->
106 115
         <dependency>

+ 0
- 28
src/main/java/com/example/civilizedcity/config/CorsConfig.java Näytä tiedosto

@@ -1,28 +0,0 @@
1
-//package com.example.civilizedcity.config;
2
-//
3
-//import org.springframework.context.annotation.Bean;
4
-//import org.springframework.context.annotation.Configuration;
5
-//import org.springframework.web.cors.CorsConfiguration;
6
-//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
7
-//import org.springframework.web.filter.CorsFilter;
8
-//
9
-///**
10
-// * 解决跨域问题
11
-// */
12
-//@Configuration
13
-//public class CorsConfig {
14
-//    private CorsConfiguration buildConfig() {
15
-//        CorsConfiguration corsConfiguration = new CorsConfiguration();
16
-//        corsConfiguration.addAllowedOrigin("*"); // 1 允许任何域名使用
17
-//        corsConfiguration.addAllowedHeader("*"); // 2 允许任何头
18
-//        corsConfiguration.addAllowedMethod("*"); // 3 允许任何方法(post、get等)
19
-//        return corsConfiguration;
20
-//    }
21
-//
22
-//    @Bean
23
-//    public CorsFilter corsFilter() {
24
-//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
25
-//        source.registerCorsConfiguration("/**", buildConfig()); // 4
26
-//        return new CorsFilter(source);
27
-//    }
28
-//}

+ 61
- 0
src/main/java/com/example/civilizedcity/config/CorsFilter.java Näytä tiedosto

@@ -0,0 +1,61 @@
1
+package com.example.civilizedcity.config;
2
+
3
+import java.io.IOException;
4
+
5
+import javax.servlet.Filter;
6
+import javax.servlet.FilterChain;
7
+import javax.servlet.FilterConfig;
8
+import javax.servlet.ServletException;
9
+import javax.servlet.ServletRequest;
10
+import javax.servlet.ServletResponse;
11
+import javax.servlet.http.HttpServletRequest;
12
+import javax.servlet.http.HttpServletResponse;
13
+
14
+import org.springframework.core.annotation.Order;
15
+import org.springframework.stereotype.Component;
16
+
17
+/**
18
+ * 跨域过滤器
19
+ * @author click33
20
+ */
21
+@Component
22
+@Order(-200)
23
+public class CorsFilter implements Filter {
24
+
25
+    static final String OPTIONS = "OPTIONS";
26
+
27
+    @Override
28
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
29
+            throws IOException, ServletException {
30
+        HttpServletRequest request = (HttpServletRequest) req;
31
+        HttpServletResponse response = (HttpServletResponse) res;
32
+
33
+        // 允许指定域访问跨域资源
34
+        response.setHeader("Access-Control-Allow-Origin", "*");
35
+        // 允许所有请求方式
36
+        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT");
37
+        // 有效时间
38
+        response.setHeader("Access-Control-Max-Age", "3600");
39
+        // 允许的header参数
40
+        response.setHeader("Access-Control-Allow-Headers", "*");
41
+
42
+        // 如果是预检请求,直接返回
43
+        if (OPTIONS.equals(request.getMethod())) {
44
+            System.out.println("=======================浏览器发来了OPTIONS预检请求==========");
45
+            response.getWriter().print("");
46
+            return;
47
+        }
48
+
49
+        // System.out.println("*********************************过滤器被使用**************************");
50
+        chain.doFilter(req, res);
51
+    }
52
+
53
+    @Override
54
+    public void init(FilterConfig filterConfig) {
55
+    }
56
+
57
+    @Override
58
+    public void destroy() {
59
+    }
60
+
61
+}

+ 0
- 24
src/main/java/com/example/civilizedcity/controller/H5Controller.java Näytä tiedosto

@@ -1,24 +0,0 @@
1
-package com.example.civilizedcity.controller;
2
-
3
-
4
-import cn.dev33.satoken.util.SaResult;
5
-import com.example.civilizedcity.common.BaseController;
6
-import io.swagger.annotations.Api;
7
-import io.swagger.annotations.ApiOperation;
8
-import org.springframework.web.bind.annotation.PostMapping;
9
-import org.springframework.web.bind.annotation.RequestMapping;
10
-import org.springframework.web.bind.annotation.RestController;
11
-
12
-@Api(tags = "H5")
13
-@RestController
14
-@RequestMapping("/h5")
15
-public class H5Controller extends BaseController {
16
-
17
-
18
-    @PostMapping("/login")
19
-    @ApiOperation(value = "h5登录")
20
-    public SaResult login() throws Exception {
21
-
22
-        return SaResult.data("");
23
-    }
24
-}