|
@@ -1,16 +1,18 @@
|
|
|
package top.lvzhiqiang.service.impl;
|
|
package top.lvzhiqiang.service.impl;
|
|
|
|
|
|
|
|
-import com.microsoft.playwright.Locator;
|
|
|
|
|
-import com.microsoft.playwright.Response;
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
|
+
|
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Document;
|
|
|
-import org.springframework.boot.system.ApplicationHome;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.nio.file.Files;
|
|
|
|
|
-import java.nio.file.Path;
|
|
|
|
|
-import java.nio.file.Paths;
|
|
|
|
|
|
|
+import com.microsoft.playwright.Locator;
|
|
|
|
|
+import com.microsoft.playwright.Response;
|
|
|
|
|
+
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 实现 JavDB 业务类
|
|
* 实现 JavDB 业务类
|
|
@@ -107,12 +109,13 @@ public class JavdbPlaywrightServiceImpl extends AbstractPlaywrightService {
|
|
|
String captchaCode = getCode(imgBytes);
|
|
String captchaCode = getCode(imgBytes);
|
|
|
log.info("验证码识别完成,结果: {}", captchaCode);
|
|
log.info("验证码识别完成,结果: {}", captchaCode);
|
|
|
try {
|
|
try {
|
|
|
- // 1. 获取 JAR 包所在的绝对路径 (Spring Boot 专属神器)
|
|
|
|
|
- String jarPath = new ApplicationHome(getClass()).getSource().getParent();
|
|
|
|
|
|
|
+ // 1. 获取兼容的根路径
|
|
|
|
|
+ File rootDir = getAppRootPath();
|
|
|
// 2. 构造子文件夹路径 (例如: /usr/program/jav/images)
|
|
// 2. 构造子文件夹路径 (例如: /usr/program/jav/images)
|
|
|
- Path dirPath = Paths.get(jarPath, "files/playwright"); // 假设子文件夹叫 images
|
|
|
|
|
|
|
+ Path dirPath = Paths.get(rootDir.getAbsolutePath(), "files/playwright");
|
|
|
// 3. 关键一步:如果文件夹不存在,必须先创建!
|
|
// 3. 关键一步:如果文件夹不存在,必须先创建!
|
|
|
- if (!Files.exists(dirPath)) Files.createDirectories(dirPath);
|
|
|
|
|
|
|
+ if (!Files.exists(dirPath))
|
|
|
|
|
+ Files.createDirectories(dirPath);
|
|
|
// 4. 写入
|
|
// 4. 写入
|
|
|
Files.write(dirPath.resolve(captchaCode + ".png"), imgBytes);
|
|
Files.write(dirPath.resolve(captchaCode + ".png"), imgBytes);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|