Commit 7465e7da by 胡懿

创建项目

parent 543acd11
/mvnw text eol=lf
*.cmd text eol=crlf
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
url="http://localhost:8080/loginScrt"
securityServerUrl="127.0.0.1"
\ No newline at end of file
<?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>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.yzkj</groupId>
<artifactId>scrt-sdk</artifactId>
<version>1.0.0</version>
<name>scrt-sdk</name>
<description>scrt-sdk</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip> <!-- 禁止生成可执行JAR -->
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.yzkj.scrtsdk;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ScrtSdkApplication {
public static void main(String[] args) {
SpringApplication.run(ScrtSdkApplication.class, args);
}
}
package com.yzkj.scrtsdk.controller;
import com.yzkj.scrtsdk.utils.CallbackUrlUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
@Controller
@RequestMapping("/loginScrt")
public class LoginScrtController {
@GetMapping("/jumpLogin")
public String jumpLogin(Model model) {
try {
model.addAttribute("jumpUrl", CallbackUrlUtils.getCallbackUrl());
model.addAttribute("securityServerUrl", CallbackUrlUtils.getSecurityServerUrl());
} catch (IOException e) {
throw new RuntimeException(e);
}
return "scrtLogin";
}
}
package com.yzkj.scrtsdk.utils;
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class CallbackUrlUtils {
public static String getCallbackUrl() throws IOException {
// 1. 定位项目根目录下的 callbackUrl 文件
File file = new File("callbackUrl");
if (!file.exists() || file.isDirectory()) {
throw new IOException("callbackUrl file not found in root directory");
}
// 2. 逐行读取文件内容
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
// 跳过空行和注释行(以#开头)
if (line.isEmpty() || line.startsWith("#")) continue;
// 3. 解析 url 属性
if (line.startsWith("url=")) {
String value = line.substring(4).trim();
// 去除值两侧的引号(支持单/双引号)
if (value.length() >= 2 &&
( (value.startsWith("\"") && value.endsWith("\"")) ||
(value.startsWith("'") && value.endsWith("'")) )) {
return value.substring(1, value.length() - 1);
}
return value;
}
}
}
throw new IOException("url property not found in callbackUrl file");
}
public static String getSecurityServerUrl() throws IOException {
// 1. 定位项目根目录下的 callbackUrl 文件
File file = new File("callbackUrl");
if (!file.exists() || file.isDirectory()) {
throw new IOException("callbackUrl file not found in root directory");
}
// 2. 逐行读取文件内容
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
// 跳过空行和注释行(以#开头)
if (line.isEmpty() || line.startsWith("#")) continue;
// 3. 解析 url 属性
if (line.startsWith("securityServerUrl=")) {
String value = line.substring(4).trim();
// 去除值两侧的引号(支持单/双引号)
if (value.length() >= 2 &&
( (value.startsWith("\"") && value.endsWith("\"")) ||
(value.startsWith("'") && value.endsWith("'")) )) {
return value.substring(1, value.length() - 1);
}
return value;
}
}
}
throw new IOException("url property not found in callbackUrl file");
}
// 测试代码
public static void main(String[] args) {
try {
String url = CallbackUrlUtils.getCallbackUrl();
System.out.println("读取到的URL: " + url);
} catch (IOException e) {
e.printStackTrace();
}
}
}
spring.application.name=scrt-sdk
server.port = 12285
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>123123123123</div>
<h1>跳转地址:<span th:text="${jumpUrl}"></span></h1>
<h1>登录地址:<span th:text="${securityServerUrl}"></span></h1>
</body>
</html>
\ No newline at end of file
package com.yzkj.scrtsdk;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ScrtSdkApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment