Bläddra i källkod

增加短信登录

wwh 3 veckor sedan
förälder
incheckning
c7b6b77711

+ 4 - 0
huimv-employment/fe-api/pom.xml

@@ -30,6 +30,10 @@
30 30
             <groupId>org.springframework.boot</groupId>
31 31
             <artifactId>spring-boot-starter-validation</artifactId>
32 32
         </dependency>
33
+        <dependency>
34
+            <groupId>com.github.xiaoymin</groupId>
35
+            <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
36
+        </dependency>
33 37
         <dependency>
34 38
             <groupId>org.springframework.boot</groupId>
35 39
             <artifactId>spring-boot-starter-test</artifactId>

+ 44 - 0
huimv-employment/fe-api/src/main/java/com/huimv/employment/config/OpenApiConfig.java

@@ -0,0 +1,44 @@
1
+package com.huimv.employment.config;
2
+
3
+import io.swagger.v3.oas.models.Components;
4
+import io.swagger.v3.oas.models.OpenAPI;
5
+import io.swagger.v3.oas.models.info.Contact;
6
+import io.swagger.v3.oas.models.info.Info;
7
+import io.swagger.v3.oas.models.security.SecurityScheme;
8
+import org.springdoc.core.GroupedOpenApi;
9
+import org.springframework.context.annotation.Bean;
10
+import org.springframework.context.annotation.Configuration;
11
+
12
+/**
13
+ * OpenAPI / Knife4j 接口文档配置。
14
+ * <p>文档入口:{@code http://localhost:8080/doc.html}</p>
15
+ */
16
+@Configuration
17
+public class OpenApiConfig {
18
+
19
+    @Bean
20
+    public OpenAPI openAPI() {
21
+        return new OpenAPI()
22
+                .info(new Info()
23
+                        .title("灵活用工 fe-server API")
24
+                        .description("灵活用工与用工税筹 — 小程序端及内部接口")
25
+                        .version("1.0.0")
26
+                        .contact(new Contact().name("huimv")))
27
+                .components(new Components().addSecuritySchemes("Authorization",
28
+                        new SecurityScheme()
29
+                                .type(SecurityScheme.Type.HTTP)
30
+                                .scheme("bearer")
31
+                                .bearerFormat("JWT")
32
+                                .in(SecurityScheme.In.HEADER)
33
+                                .name("Authorization")));
34
+    }
35
+
36
+    /** 小程序端 API 分组 */
37
+    @Bean
38
+    public GroupedOpenApi mpApi() {
39
+        return GroupedOpenApi.builder()
40
+                .group("小程序端")
41
+                .pathsToMatch("/api/v1/mp/**")
42
+                .build();
43
+    }
44
+}

+ 5 - 0
huimv-employment/fe-api/src/main/java/com/huimv/employment/controller/mp/AuthController.java

@@ -6,6 +6,8 @@ import com.huimv.employment.service.auth.dto.LoginResponse;
6 6
 import com.huimv.employment.service.auth.dto.SmsLoginRequest;
7 7
 import com.huimv.employment.service.auth.dto.SmsSendRequest;
8 8
 import com.huimv.employment.service.auth.dto.SmsSendResponse;
9
+import io.swagger.v3.oas.annotations.Operation;
10
+import io.swagger.v3.oas.annotations.tags.Tag;
9 11
 import org.springframework.validation.annotation.Validated;
10 12
 import org.springframework.web.bind.annotation.PostMapping;
11 13
 import org.springframework.web.bind.annotation.RequestBody;
@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
21 23
  */
22 24
 @RestController
23 25
 @RequestMapping("/api/v1/mp/auth")
26
+@Tag(name = "认证", description = "短信验证码登录,匿名访问")
24 27
 public class AuthController {
25 28
 
26 29
     private final AuthService authService;
@@ -42,6 +45,7 @@ public class AuthController {
42 45
      * @return 是否 Mock 模式、验证码有效期(秒)
43 46
      */
44 47
     @PostMapping("/sms/send")
48
+    @Operation(summary = "发送登录验证码")
45 49
     public R<SmsSendResponse> sendSmsCode(@Validated @RequestBody SmsSendRequest request) {
46 50
         return R.ok(authService.sendLoginCode(request));
47 51
     }
@@ -57,6 +61,7 @@ public class AuthController {
57 61
      * @return Token、用户 ID、脱敏手机号等
58 62
      */
59 63
     @PostMapping("/sms/login")
64
+    @Operation(summary = "短信验证码登录")
60 65
     public R<LoginResponse> loginBySms(@Validated @RequestBody SmsLoginRequest request) {
61 66
         return R.ok(authService.loginBySms(request));
62 67
     }

+ 4 - 0
huimv-employment/fe-api/src/main/java/com/huimv/employment/controller/mp/HealthController.java

@@ -1,5 +1,7 @@
1 1
 package com.huimv.employment.controller.mp;
2 2
 
3
+import io.swagger.v3.oas.annotations.Operation;
4
+import io.swagger.v3.oas.annotations.tags.Tag;
3 5
 import org.springframework.web.bind.annotation.GetMapping;
4 6
 import org.springframework.web.bind.annotation.RequestMapping;
5 7
 import org.springframework.web.bind.annotation.RestController;
@@ -12,9 +14,11 @@ import java.util.Map;
12 14
  */
13 15
 @RestController
14 16
 @RequestMapping("/api/v1/mp")
17
+@Tag(name = "系统", description = "健康检查等")
15 18
 public class HealthController {
16 19
 
17 20
     @GetMapping("/health")
21
+    @Operation(summary = "健康检查")
18 22
     public Map<String, Object> health() {
19 23
         Map<String, Object> body = new HashMap<>(4);
20 24
         body.put("code", 200);

+ 11 - 0
huimv-employment/fe-api/src/main/resources/application.yml

@@ -11,6 +11,17 @@ logging:
11 11
   file:
12 12
     path: logs
13 13
 
14
+springdoc:
15
+  api-docs:
16
+    enabled: true
17
+  swagger-ui:
18
+    enabled: false
19
+
20
+knife4j:
21
+  enable: true
22
+  setting:
23
+    language: zh_cn
24
+
14 25
 fe:
15 26
   security:
16 27
     jwt-secret: 68df79f4d75b6afc89738872b3e41625330b052dcfcf2bc421450df0290a65g0

+ 6 - 0
huimv-employment/fe-api/src/test/resources/application-test.yml

@@ -9,3 +9,9 @@ spring:
9 9
 fe:
10 10
   sms:
11 11
     mock-enabled: true
12
+
13
+springdoc:
14
+  api-docs:
15
+    enabled: false
16
+knife4j:
17
+  enable: false