1、JDK升至17,2、更新图片数据源,3、忽略SSL校验
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>icu.namophice</groupId>
|
||||
<artifactId>ink-photo-album</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-RELEASE</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
@@ -27,4 +27,33 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>
|
||||
icu.namophice.inkphotoalbum.Main
|
||||
</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -17,9 +17,6 @@ public class Main {
|
||||
// 初始化配置
|
||||
DefaultConfig.initConfig();
|
||||
|
||||
// 从cache文件获取imageIndex
|
||||
DefaultConfig.initImageIndexWithCache();
|
||||
|
||||
// 进入主流程
|
||||
MasterService.master();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -5,15 +5,16 @@ import icu.namophice.inkphotoalbum.driver.EPaper;
|
||||
import icu.namophice.inkphotoalbum.utils.CommonUtil;
|
||||
import icu.namophice.inkphotoalbum.utils.ImageUtil;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Namophice
|
||||
@@ -21,19 +22,19 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class MasterService {
|
||||
|
||||
public static void master() throws IOException, InterruptedException {
|
||||
public static void master() throws Exception {
|
||||
CommonUtil.printLogToConsole("The master program is running ...");
|
||||
|
||||
final EPaper ePaper = EPaper.getInstance();
|
||||
ePaper.init();
|
||||
|
||||
// 从cache文件获取imageIndex
|
||||
DefaultConfig.initImageIndexWithCache();
|
||||
if (DefaultConfig.imageIndex < 0) {
|
||||
DefaultConfig.imageIndex = 0;
|
||||
}
|
||||
|
||||
EPaper ePaper = EPaper.getInstance();
|
||||
ePaper.init();
|
||||
|
||||
if (DefaultConfig.imageIndex == 0) {
|
||||
BufferedImage defaultImage = ImageUtil.getImageToScreen();
|
||||
|
||||
CommonUtil.printLogToConsole("Print images to screen ...");
|
||||
ePaper.drawImage(defaultImage);
|
||||
}
|
||||
@@ -44,7 +45,7 @@ public class MasterService {
|
||||
CommonUtil.printLogToConsole("Enabled local images mode ...");
|
||||
|
||||
CommonUtil.printLogToConsole("Find images directory ...");
|
||||
File imagesDir = new File(CommonUtil.rootPath + "/" + DefaultConfig.imagePath);
|
||||
final File imagesDir = new File(CommonUtil.rootPath + "/" + DefaultConfig.imagePath);
|
||||
|
||||
if (imagesDir.exists()) {
|
||||
if (imagesDir.isDirectory()) {
|
||||
@@ -52,7 +53,6 @@ public class MasterService {
|
||||
|
||||
CommonUtil.printLogToConsole("Find images files ...");
|
||||
File[] imageList = imagesDir.listFiles();
|
||||
imagesDir = null;
|
||||
|
||||
if (imageList == null || imageList.length < 1) {
|
||||
DefaultConfig.imageIndex = 0;
|
||||
@@ -84,71 +84,57 @@ public class MasterService {
|
||||
DefaultConfig.imageIndex = 0;
|
||||
}
|
||||
|
||||
StringBuffer htmlStr = new StringBuffer();
|
||||
|
||||
InputStream inputStream = null;
|
||||
InputStreamReader inputStreamReader = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
|
||||
final StringBuilder imageUrlStr = new StringBuilder();
|
||||
try {
|
||||
URL url = new URL("https://wall.alphacoders.com/popular.php?page=" + (DefaultConfig.imageIndex + 1));
|
||||
inputStream = url.openStream();
|
||||
inputStreamReader = new InputStreamReader(inputStream, "utf-8");
|
||||
bufferedReader = new BufferedReader(inputStreamReader);
|
||||
final URL url = new URL(DefaultConfig.imageUrlArr[new Random().nextInt(DefaultConfig.imageUrlArr.length)]);
|
||||
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
htmlStr.append(line).append("\n");
|
||||
}
|
||||
trustAllHttpsCertificates();
|
||||
HostnameVerifier hv = (urlHostName, session) -> {
|
||||
System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
|
||||
return true;
|
||||
};
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
||||
|
||||
bufferedReader.close();
|
||||
final HttpURLConnection conn = (HttpURLConnection) (url.openConnection());
|
||||
final URL imageUrl = conn.getURL();
|
||||
imageUrlStr.append(imageUrl.getProtocol()).append("://").append(imageUrl.getHost()).append(imageUrl.getPath());
|
||||
} catch (IOException e) {
|
||||
DefaultConfig.imageIndex = 0;
|
||||
throw e;
|
||||
}finally {
|
||||
try {
|
||||
if(bufferedReader!=null){
|
||||
bufferedReader.close();
|
||||
bufferedReader=null;
|
||||
}
|
||||
if(inputStreamReader!=null){
|
||||
inputStreamReader.close();
|
||||
inputStreamReader=null;
|
||||
}
|
||||
if(inputStream!=null){
|
||||
inputStream.close();
|
||||
inputStream=null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (htmlStr.length() > 0) {
|
||||
final List<String> imageUrlList = new ArrayList<>();
|
||||
|
||||
final String IMGURL_REG = "(https://images(.*)thumbbig-(\\d*).jpg)";
|
||||
Matcher matcher = Pattern.compile(IMGURL_REG).matcher(htmlStr);
|
||||
while (matcher.find()){
|
||||
imageUrlList.add(matcher.group());
|
||||
}
|
||||
|
||||
if (imageUrlList.size() < 1) {
|
||||
DefaultConfig.imageIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
String imageUrl = imageUrlList.get(new Random().nextInt(imageUrlList.size()));
|
||||
imageUrl = imageUrl.replace("/thumbbig-", "/");
|
||||
|
||||
BufferedImage targetImage = ImageUtil.getImageToScreen(imageUrl, true);
|
||||
if (imageUrlStr.length() > 0) {
|
||||
BufferedImage targetImage = ImageUtil.getImageToScreen(imageUrlStr.toString(), true);
|
||||
|
||||
CommonUtil.printLogToConsole("Print images to screen ...");
|
||||
ePaper.drawImage(targetImage);
|
||||
|
||||
DefaultConfig.imageIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳过SSL证书验证
|
||||
* @throws Exception
|
||||
*/
|
||||
private static void trustAllHttpsCertificates() throws Exception {
|
||||
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
|
||||
javax.net.ssl.TrustManager tm = new miTM();
|
||||
trustAllCerts[0] = tm;
|
||||
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
sc.init(null, trustAllCerts, null);
|
||||
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
private static class miTM implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package icu.namophice.inkphotoalbum.config;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import icu.namophice.inkphotoalbum.utils.CommonUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
/**
|
||||
* @author Namophice
|
||||
@@ -11,6 +13,15 @@ import java.io.*;
|
||||
*/
|
||||
public class DefaultConfig {
|
||||
|
||||
public static final String[] imageUrlArr = {
|
||||
"https://api.ixiaowai.cn/api/api.php",
|
||||
"https://api.ixiaowai.cn/api/api2.php",
|
||||
"https://api.ixiaowai.cn/mcapi/mcapi.php",
|
||||
"https://api.ixiaowai.cn/mcapi/mcapi2.php",
|
||||
"https://api.ixiaowai.cn/gqapi/gqapi.php",
|
||||
"https://api.ixiaowai.cn/gqapi/gqapi2.php"
|
||||
};
|
||||
|
||||
public static final String configFileName = "conf.json";
|
||||
public static final String cacheFileName = "cache";
|
||||
|
||||
@@ -27,7 +38,7 @@ public class DefaultConfig {
|
||||
* 是否开启图片填充
|
||||
*/
|
||||
private static boolean enable_image_fill = false;
|
||||
public static final boolean enable_image_fill() {
|
||||
public static boolean enable_image_fill() {
|
||||
return enable_image_fill;
|
||||
}
|
||||
|
||||
@@ -96,9 +107,8 @@ public class DefaultConfig {
|
||||
|
||||
/**
|
||||
* 从cache文件获取imageIndex
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void initImageIndexWithCache() throws IOException {
|
||||
public static void initImageIndexWithCache() {
|
||||
CommonUtil.printLogToConsole("Init image index with cache ...");
|
||||
|
||||
DefaultConfig.imageIndex = 0;
|
||||
@@ -126,7 +136,7 @@ public class DefaultConfig {
|
||||
}
|
||||
}
|
||||
|
||||
if (lineStr.length() > 0) {
|
||||
if (lineStr != null && lineStr.length() > 0) {
|
||||
DefaultConfig.imageIndex = Integer.parseInt(lineStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,16 +22,14 @@ public class EPaper {
|
||||
|
||||
private EPaper() {}
|
||||
|
||||
private static EPaper ePaper;
|
||||
|
||||
public static EPaper getInstance() {
|
||||
return ePaper = new EPaper();
|
||||
return new EPaper();
|
||||
}
|
||||
|
||||
private static GpioPinDigitalOutput CS;
|
||||
private static GpioPinDigitalOutput DC;
|
||||
private static GpioPinDigitalOutput RST;
|
||||
private static GpioPinDigitalInput BUSY;
|
||||
private static final GpioPinDigitalOutput CS;
|
||||
private static final GpioPinDigitalOutput DC;
|
||||
private static final GpioPinDigitalOutput RST;
|
||||
private static final GpioPinDigitalInput BUSY;
|
||||
|
||||
public static SpiDevice spiDevice;
|
||||
|
||||
@@ -271,7 +269,7 @@ public class EPaper {
|
||||
temp |= 0;
|
||||
}else if (grayNum < GRAY_SCALE_OF_4[2]) {
|
||||
temp |= 1;
|
||||
} else if(grayNum <= GRAY_SCALE_OF_4[3]){
|
||||
} else {
|
||||
temp |= 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user