Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit d3645d2

Browse files
committed
remove validate code and ocr module
1 parent 0741cab commit d3645d2

File tree

17 files changed

+23
-1433
lines changed

17 files changed

+23
-1433
lines changed

.github/workflows/schedule.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
branches: [ main ]
88

99
schedule:
10-
# 东八区09:00,9:20,9:40尝试三次,触发不完全准时,可能延时半个到一个小时等。
11-
- cron: '0/20 1 * * *'
10+
# UTC 01:00 和 UTC 04:00
11+
- cron: '0 1,4 * * *'
1212

1313
# 当star当前仓库时立即执行
1414
watch:
@@ -43,9 +43,6 @@ jobs:
4343
java-version: '11'
4444
cache: "maven"
4545

46-
- name: "Setup tesseract-ocr"
47-
run: "sudo apt install tesseract-ocr -y"
48-
4946
- name: "Build with maven"
5047
run: "mvn clean package spring-boot:repackage"
5148

config/application.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@
2828
],
2929
"formvalidation": true,
3030
"enablepreview": false,
31-
"testmode": false,
32-
"ocr": "d4_ocr"
31+
"testmode": false
3332
}

pom.xml

+2-22
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
<groupId>top.gcszhn</groupId>
66
<artifactId>autocard</artifactId>
7-
<version>1.4.9</version>
7+
<version>1.4.10</version>
88
<packaging>jar</packaging>
99

10-
<name>Auto Heathy Report for Zhejiang University</name>
10+
<name>Automatically Healthy Report for Zhejiang University</name>
1111

1212
<parent>
1313
<groupId>org.springframework.boot</groupId>
@@ -107,26 +107,6 @@
107107
<artifactId>mail</artifactId>
108108
<version>1.4.7</version>
109109
</dependency>
110-
111-
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
112-
<dependency>
113-
<groupId>net.java.dev.jna</groupId>
114-
<artifactId>jna</artifactId>
115-
<version>5.10.0</version>
116-
</dependency>
117-
118-
<!-- https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j -->
119-
<dependency>
120-
<groupId>net.sourceforge.tess4j</groupId>
121-
<artifactId>tess4j</artifactId>
122-
<version>5.1.0</version>
123-
</dependency>
124-
<!-- https://mvnrepository.com/artifact/com.microsoft.onnxruntime/onnxruntime -->
125-
<dependency>
126-
<groupId>com.microsoft.onnxruntime</groupId>
127-
<artifactId>onnxruntime</artifactId>
128-
<version>1.11.0</version>
129-
</dependency>
130110
<!--lombok插件-->
131111
<dependency>
132112
<groupId>org.projectlombok</groupId>

src/main/java/top/gcszhn/autocard/AppConfig.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import lombok.Getter;
3636
import top.gcszhn.autocard.service.MailService;
3737
import top.gcszhn.autocard.utils.LogUtils;
38-
import top.gcszhn.autocard.utils.ocr.EngineType;
3938

4039

4140
/**
@@ -47,6 +46,7 @@
4746
public class AppConfig implements EnvironmentAware {
4847
/**默认字符集 */
4948
public static final Charset APP_CHARSET = StandardCharsets.UTF_8;
49+
/** 创建APP临时目录*/
5050
public static final File TMP_DIR = new File(System.getProperty("java.io.tmpdir") , "autocard");
5151
static {
5252
try {
@@ -66,8 +66,7 @@ public class AppConfig implements EnvironmentAware {
6666
private @Getter boolean testMode = false;
6767
/**是否启用预览特性 */
6868
private @Getter boolean enablePreview = false;
69-
/**默认OCR引擎 */
70-
private @Getter EngineType ocrEngine = EngineType.D4_OCR;
69+
/** 加载APP配置文件*/
7170
public AppConfig() {
7271
try (FileInputStream fis = new FileInputStream(APP_CACHE)) {
7372
appCache = JSON.parseObject(new String(fis.readAllBytes(), APP_CHARSET));
@@ -86,12 +85,6 @@ public void setEnvironment(Environment env) {
8685
loadJSONConfig(env.getProperty("app.autoCard.config"));
8786
testMode = appConfig.getBooleanValue("testmode");
8887
enablePreview = appConfig.getBooleanValue("enablepreview");
89-
try {
90-
ocrEngine = EngineType.valueOf(appConfig.getString("ocr").toUpperCase());
91-
LogUtils.printMessage("OCR引擎为" + ocrEngine);
92-
} catch (Exception e) {
93-
LogUtils.printMessage("未配置有效的OCR引擎,使用默认OCR引擎" + ocrEngine);
94-
}
9588

9689
// 通过系统环境变量添加单个打卡用户
9790

src/main/java/top/gcszhn/autocard/service/AutoCardService.java

+16-98
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package top.gcszhn.autocard.service;
1717

18-
import java.awt.image.BufferedImage;
19-
import java.io.IOException;
2018
import java.text.SimpleDateFormat;
2119
import java.util.ArrayList;
2220
import java.util.Date;
@@ -29,10 +27,8 @@
2927
import lombok.Getter;
3028
import top.gcszhn.autocard.AppConfig;
3129
import top.gcszhn.autocard.utils.DigestUtils;
32-
import top.gcszhn.autocard.utils.HttpDataPair;
3330
import top.gcszhn.autocard.utils.ImageUtils;
3431
import top.gcszhn.autocard.utils.LogUtils;
35-
import top.gcszhn.autocard.utils.ocr.OCRUtils;
3632
import top.gcszhn.autocard.utils.StatusCode;
3733

3834
import org.apache.http.NameValuePair;
@@ -45,8 +41,6 @@
4541
import org.springframework.context.annotation.Scope;
4642
import org.springframework.stereotype.Service;
4743

48-
import javax.imageio.ImageIO;
49-
5044
/**
5145
* 健康打卡实现类
5246
* @author Zhang.H.N
@@ -65,8 +59,7 @@ public class AutoCardService implements AppService {
6559
private String reportUrl;
6660
@Value("${app.autoCard.submitUrl}")
6761
private String submitUrl;
68-
@Value("${app.autoCard.codeUrl}")
69-
private String codeUrl;
62+
7063
/**浙大通行证客户端 */
7164
@Autowired
7265
private ZJUClientService client;
@@ -201,55 +194,7 @@ public ArrayList<NameValuePair> getOldInfo(String page) {
201194
}
202195
return res;
203196
}
204-
public BufferedImage getCodeImage() {
205-
if (isOnline()) {
206-
LogUtils.printMessage("获取验证码", LogUtils.Level.INFO);
207-
return Optional.ofNullable(client.doGet(codeUrl + "?_t=" + Math.random())).map((HttpDataPair pair)-> {
208-
try {
209-
if (pair.getResponse() != null && pair.getResponse().getEntity() != null) {
210-
BufferedImage image = ImageIO.read(pair.getResponse().getEntity().getContent());
211-
return image;
212197

213-
}
214-
} catch (IOException e) {
215-
LogUtils.printMessage(null, e, LogUtils.Level.ERROR);
216-
} finally {
217-
try {
218-
pair.close();
219-
} catch (IOException e) {
220-
e.printStackTrace();
221-
}
222-
}
223-
return null;
224-
}).orElse(null);
225-
} else {
226-
LogUtils.printMessage("用户未登录", LogUtils.Level.ERROR);
227-
}
228-
return null;
229-
}
230-
public String getCode(BufferedImage codeImage) {
231-
Optional<String> code = Optional.ofNullable(codeImage).map((BufferedImage image)->{
232-
try {
233-
LogUtils.printMessage("识别验证码", LogUtils.Level.INFO);
234-
String value = OCRUtils.instance(appConfig.getOcrEngine()).recognize(image);
235-
if (value != null) {
236-
value = value.strip().toUpperCase();
237-
value.replaceAll("1", "I");
238-
if (value.length() != 4) {
239-
value = null;
240-
}
241-
}
242-
return value;
243-
} catch (Exception e) {
244-
LogUtils.printMessage("验证码识别异常", e, LogUtils.Level.ERROR);
245-
return null;
246-
}
247-
});
248-
return code.isPresent() ? code.get(): null;
249-
}
250-
public String getCode() {
251-
return getCode(getCodeImage());
252-
}
253198
/**
254199
* 用于提交打卡信息
255200
* @param username 用户名
@@ -278,13 +223,9 @@ public StatusCode submit(String username, String password) {
278223
LogUtils.printMessage(statusCode.getMessage(), LogUtils.Level.ERROR);
279224
return statusCode;
280225
}
281-
int validCodeMaxTrial = 20;
282-
JSONObject resp = null;
283-
LogUtils.Level level = null;
284-
int status = 3;
285-
NameValuePair codePair = null;
226+
JSONObject resp;
227+
LogUtils.Level level;
286228
String area = null;
287-
288229
ArrayList<NameValuePair> info = getOldInfo(page);
289230
if (info==null) {
290231
LogUtils.printMessage("打卡信息获取失败", LogUtils.Level.ERROR);
@@ -299,45 +240,22 @@ public StatusCode submit(String username, String password) {
299240
break;
300241
}
301242
}
302-
SAVE: while (validCodeMaxTrial > 0) {
303-
304-
while (validCodeMaxTrial > 0) {
305-
validCodeMaxTrial --;
306-
String code = getCode();
307-
if (code != null) {
308-
if (codePair != null) info.remove(codePair);
309-
codePair = new BasicNameValuePair("verifyCode", code);
310-
info.add(codePair);
311-
break;
312-
} else {
313-
LogUtils.printMessage("验证码识别错误,剩余机会:" + validCodeMaxTrial, LogUtils.Level.ERROR);
314-
}
315-
}
316243

317-
try {
318-
LogUtils.printMessage("准备提交打卡 " + username);
319-
resp = JSONObject.parseObject(client.doPostText(submitUrl, info));
320-
} catch (Exception e) {
321-
resp = new JSONObject();
322-
resp.put("e", 3);
323-
resp.put("m", "打卡提交失败");
324-
}
244+
try {
245+
LogUtils.printMessage("准备提交打卡 " + username);
246+
resp = JSONObject.parseObject(client.doPostText(submitUrl, info));
247+
} catch (Exception e) {
248+
resp = new JSONObject();
249+
resp.put("e", 3);
250+
resp.put("m", "打卡提交失败");
251+
}
325252

326-
status = resp.getIntValue("e");
327-
switch(status) {
328-
case 0:{level= LogUtils.Level.INFO;break;}
329-
case 1:{
330-
if (validCodeMaxTrial > 0 && resp.getString("m").equals("验证码错误")) {
331-
LogUtils.printMessage("验证码识别错误,剩余机会:" + validCodeMaxTrial, LogUtils.Level.ERROR);
332-
Thread.sleep(2000);
333-
continue SAVE;
334-
}
335-
}
336-
default: {
337-
level = LogUtils.Level.ERROR;
338-
}
253+
int status = resp.getIntValue("e");
254+
switch(status) {
255+
case 0:{level= LogUtils.Level.INFO;break;}
256+
default: {
257+
level = LogUtils.Level.ERROR;
339258
}
340-
break;
341259
}
342260

343261
String message = String.format("%s,你好,今日自动健康打卡状态:%s,打卡地区为:%s(如若区域不符,请次日手动打卡更改地址)",

src/main/java/top/gcszhn/autocard/utils/ONNXRuntimeUtils.java

-86
This file was deleted.

0 commit comments

Comments
 (0)