init
0 parents
Showing
11 changed files
with
315 additions
and
0 deletions
.gitignore
0 → 100644
1 | HELP.md | ||
2 | target/ | ||
3 | !.mvn/wrapper/maven-wrapper.jar | ||
4 | !**/src/main/**/target/ | ||
5 | !**/src/test/**/target/ | ||
6 | |||
7 | ### STS ### | ||
8 | .apt_generated | ||
9 | .classpath | ||
10 | .factorypath | ||
11 | .project | ||
12 | .settings | ||
13 | .springBeans | ||
14 | .sts4-cache | ||
15 | |||
16 | ### IntelliJ IDEA ### | ||
17 | .idea | ||
18 | *.iws | ||
19 | *.iml | ||
20 | *.ipr | ||
21 | |||
22 | ### NetBeans ### | ||
23 | /nbproject/private/ | ||
24 | /nbbuild/ | ||
25 | /dist/ | ||
26 | /nbdist/ | ||
27 | /.nb-gradle/ | ||
28 | build/ | ||
29 | !**/src/main/**/build/ | ||
30 | !**/src/test/**/build/ | ||
31 | |||
32 | ### VS Code ### | ||
33 | .vscode/ |
pom.xml
0 → 100644
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
4 | <modelVersion>4.0.0</modelVersion> | ||
5 | <groupId>com.topdraw</groupId> | ||
6 | <artifactId>docking-api</artifactId> | ||
7 | <version>0.0.1-SNAPSHOT</version> | ||
8 | <name>docking-api</name> | ||
9 | <description>docking-api</description> | ||
10 | <properties> | ||
11 | <java.version>1.8</java.version> | ||
12 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
13 | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
14 | <spring-boot.version>2.6.13</spring-boot.version> | ||
15 | </properties> | ||
16 | <dependencies> | ||
17 | <dependency> | ||
18 | <groupId>org.springframework.boot</groupId> | ||
19 | <artifactId>spring-boot-starter-web</artifactId> | ||
20 | </dependency> | ||
21 | |||
22 | <dependency> | ||
23 | <groupId>org.projectlombok</groupId> | ||
24 | <artifactId>lombok</artifactId> | ||
25 | <optional>true</optional> | ||
26 | </dependency> | ||
27 | <dependency> | ||
28 | <groupId>org.springframework.boot</groupId> | ||
29 | <artifactId>spring-boot-starter-test</artifactId> | ||
30 | <scope>test</scope> | ||
31 | </dependency> | ||
32 | <!--愉快办对接--> | ||
33 | <dependency> | ||
34 | <groupId>com.ykb</groupId> | ||
35 | <artifactId>sdk</artifactId> | ||
36 | <version>1.2.0</version> | ||
37 | </dependency> | ||
38 | </dependencies> | ||
39 | <dependencyManagement> | ||
40 | <dependencies> | ||
41 | <dependency> | ||
42 | <groupId>org.springframework.boot</groupId> | ||
43 | <artifactId>spring-boot-dependencies</artifactId> | ||
44 | <version>${spring-boot.version}</version> | ||
45 | <type>pom</type> | ||
46 | <scope>import</scope> | ||
47 | </dependency> | ||
48 | </dependencies> | ||
49 | </dependencyManagement> | ||
50 | |||
51 | <build> | ||
52 | <plugins> | ||
53 | <plugin> | ||
54 | <groupId>org.apache.maven.plugins</groupId> | ||
55 | <artifactId>maven-compiler-plugin</artifactId> | ||
56 | <version>3.8.1</version> | ||
57 | <configuration> | ||
58 | <source>1.8</source> | ||
59 | <target>1.8</target> | ||
60 | <encoding>UTF-8</encoding> | ||
61 | </configuration> | ||
62 | </plugin> | ||
63 | <plugin> | ||
64 | <groupId>org.springframework.boot</groupId> | ||
65 | <artifactId>spring-boot-maven-plugin</artifactId> | ||
66 | <version>${spring-boot.version}</version> | ||
67 | <configuration> | ||
68 | <mainClass>com.topdraw.dockingapi.DockingApiApplication</mainClass> | ||
69 | <skip>true</skip> | ||
70 | </configuration> | ||
71 | <executions> | ||
72 | <execution> | ||
73 | <id>repackage</id> | ||
74 | <goals> | ||
75 | <goal>repackage</goal> | ||
76 | </goals> | ||
77 | </execution> | ||
78 | </executions> | ||
79 | </plugin> | ||
80 | </plugins> | ||
81 | </build> | ||
82 | |||
83 | </project> |
1 | package com.topdraw.dockingapi; | ||
2 | |||
3 | import lombok.extern.slf4j.Slf4j; | ||
4 | import org.springframework.boot.SpringApplication; | ||
5 | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
6 | |||
7 | @SpringBootApplication | ||
8 | @Slf4j | ||
9 | public class DockingApiApplication { | ||
10 | |||
11 | public static void main(String[] args) { | ||
12 | SpringApplication application = new SpringApplication(DockingApiApplication.class); | ||
13 | application.run(args); | ||
14 | |||
15 | } | ||
16 | |||
17 | |||
18 | } |
1 | package com.topdraw.dockingapi.config; | ||
2 | |||
3 | import lombok.extern.slf4j.Slf4j; | ||
4 | import org.springframework.boot.autoconfigure.web.ServerProperties; | ||
5 | import org.springframework.boot.context.event.ApplicationStartedEvent; | ||
6 | import org.springframework.context.ApplicationListener; | ||
7 | import org.springframework.context.ConfigurableApplicationContext; | ||
8 | import org.springframework.core.env.ConfigurableEnvironment; | ||
9 | import org.springframework.stereotype.Component; | ||
10 | |||
11 | /** | ||
12 | * @author wenxin | ||
13 | * @version 1.0 | ||
14 | * @date 2024/5/10 上午9:23 | ||
15 | */ | ||
16 | @Component | ||
17 | @Slf4j | ||
18 | public class ApplicationStartedListener implements ApplicationListener<ApplicationStartedEvent> { | ||
19 | |||
20 | |||
21 | @Override | ||
22 | public void onApplicationEvent(ApplicationStartedEvent event) { | ||
23 | ConfigurableApplicationContext context = event.getApplicationContext(); | ||
24 | ConfigurableEnvironment environment = context.getEnvironment(); | ||
25 | ServerProperties bean = context.getBean(ServerProperties.class); | ||
26 | Integer port = bean.getPort(); | ||
27 | String activeProfile = environment.getActiveProfiles()[0]; // 获取第一个激活的环境 | ||
28 | log.info("启动环境:{},端口号:{}", activeProfile, port); | ||
29 | } | ||
30 | } |
1 | package com.topdraw.dockingapi.config; | ||
2 | |||
3 | import lombok.Data; | ||
4 | import org.springframework.boot.context.properties.ConfigurationProperties; | ||
5 | import org.springframework.context.annotation.Configuration; | ||
6 | |||
7 | /** | ||
8 | * @author wenxin | ||
9 | * @version 1.0 | ||
10 | * @date 2024/5/9 下午5:57 | ||
11 | */ | ||
12 | @ConfigurationProperties(prefix = "interface.config") | ||
13 | @Configuration | ||
14 | @Data | ||
15 | public class EnvConfiguration { | ||
16 | private String appId; | ||
17 | private String appIv; | ||
18 | private String appKey; | ||
19 | private String appSecret; | ||
20 | private String url; | ||
21 | } |
1 | package com.topdraw.dockingapi.controller; | ||
2 | |||
3 | import com.alibaba.fastjson.JSONArray; | ||
4 | import com.alibaba.fastjson.JSONObject; | ||
5 | import com.digital.szzz.gateway.sdk.api.GatewaySender; | ||
6 | import com.digital.szzz.gateway.sdk.bean.GatewayResponse; | ||
7 | import com.topdraw.dockingapi.config.EnvConfiguration; | ||
8 | import lombok.RequiredArgsConstructor; | ||
9 | import lombok.extern.slf4j.Slf4j; | ||
10 | import org.springframework.web.bind.annotation.GetMapping; | ||
11 | import org.springframework.web.bind.annotation.RequestMapping; | ||
12 | import org.springframework.web.bind.annotation.RestController; | ||
13 | |||
14 | import javax.annotation.PostConstruct; | ||
15 | import java.util.HashMap; | ||
16 | import java.util.Map; | ||
17 | |||
18 | /** | ||
19 | * 对接愉快办接口 | ||
20 | * @author wenxin | ||
21 | * @version 1.0 | ||
22 | * @date 2024/5/9 下午5:46 | ||
23 | */ | ||
24 | @RestController | ||
25 | @Slf4j | ||
26 | @RequestMapping("/api") | ||
27 | @RequiredArgsConstructor | ||
28 | public class ApiController { | ||
29 | private final EnvConfiguration configuration; | ||
30 | |||
31 | String url; | ||
32 | String appId; | ||
33 | String iv; | ||
34 | String appKey; | ||
35 | String appSecretKey; | ||
36 | String authCode; | ||
37 | int readTimeout = 1000; | ||
38 | int connTimeout = 1000; | ||
39 | |||
40 | @PostConstruct | ||
41 | public void init() { | ||
42 | url = configuration.getUrl(); | ||
43 | appId = configuration.getAppId(); | ||
44 | iv = configuration.getAppIv(); | ||
45 | appKey = configuration.getAppKey(); | ||
46 | appSecretKey = configuration.getAppSecret(); | ||
47 | authCode = ""; | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * 获取jsToken | ||
52 | * @return token信息 | ||
53 | */ | ||
54 | @GetMapping("/js/token") | ||
55 | public GatewayResponse getJsApiToken() { | ||
56 | String method = "ykb.app.jsapi.getToken"; | ||
57 | JSONObject param = new JSONObject(); | ||
58 | param.put("appId", appId); | ||
59 | Map<String, String> headerMap = new HashMap<>(); | ||
60 | return GatewaySender.send(url, appId, method, iv, appKey, appSecretKey, param, authCode, headerMap, readTimeout, connTimeout); | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * 获取authCode | ||
65 | * @param userId 用户id | ||
66 | * @return authCode信息 | ||
67 | */ | ||
68 | @GetMapping("/auth/code") | ||
69 | public GatewayResponse getAuthCodeByUserId(String userId) { | ||
70 | String method = "app.ykb.uc.oauth.get"; | ||
71 | JSONObject param = new JSONObject(); | ||
72 | param.put("appId", appId); | ||
73 | param.put("userId", userId); | ||
74 | param.put("forceScopes", new JSONArray().fluentAdd("ykb_user_info").fluentAdd("ykb_divide")); | ||
75 | Map<String, String> headerMap = new HashMap<>(); | ||
76 | return GatewaySender.send(url, appId, method, iv, appKey, appSecretKey, param, authCode, headerMap, readTimeout, connTimeout); | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * 获取用户脱敏信息 | ||
81 | * @param authCode 认证code | ||
82 | * @return 用户信息 | ||
83 | */ | ||
84 | @GetMapping("/user/info") | ||
85 | public GatewayResponse getUserInfoByAuthCode(String authCode) { | ||
86 | String method = "app.ykb.uc.oauth.userInfo"; | ||
87 | JSONObject param = new JSONObject(); | ||
88 | param.put("authCode", authCode); | ||
89 | Map<String, String> headerMap = new HashMap<>(); | ||
90 | return GatewaySender.send(url, appId, method, iv, appKey, appSecretKey, param, authCode, headerMap, readTimeout, connTimeout); | ||
91 | } | ||
92 | } |
src/main/resources/application-prod.yml
0 → 100644
src/main/resources/application-test.yml
0 → 100644
src/main/resources/application.properties
0 → 100644
src/main/resources/static/index.html
0 → 100644
-
Please register or sign in to post a comment