新增B站漫画签到
This commit is contained in:
@@ -11,6 +11,7 @@ public class ConfigTools {
|
||||
public static final String CONFIG = "config.json";
|
||||
public static final String DATA = "data.json";
|
||||
public static final String SQLITE = "sqlite.json";
|
||||
public static final String BiliBili = "bilibili.cookie";
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -104,7 +105,7 @@ public class ConfigTools {
|
||||
String tmp;
|
||||
StringBuilder str = new StringBuilder();
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
str.append(tmp).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
return str.toString();
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -89,11 +91,13 @@ public class HttpTools {
|
||||
//connection.addRequestProperty("User-Agent", getExtUa());
|
||||
//connection.addRequestProperty("content-type", "application/json");
|
||||
connection.addRequestProperty("charset", "UTF-8");
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
//System.out.println(new String(body));
|
||||
outputStream.write(body);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
if(body!=null) {
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
//System.out.println(new String(body));
|
||||
outputStream.write(body);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
@@ -124,11 +128,11 @@ public class HttpTools {
|
||||
Set<String> keys = json.keySet();
|
||||
for (String key : keys) {
|
||||
try {
|
||||
string.append("&").append(key).append("=").append(URLEncoder.encode(json.getString(key), "UTF-8"));
|
||||
string.append("&").append(key).append("=").append(URLEncoder.encode(json.getString(key), StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
string.append("&").append(URLEncoder.encode(key, "UTF-8")).append("=");
|
||||
string.append("&").append(URLEncoder.encode(key, StandardCharsets.UTF_8)).append("=");
|
||||
// string += "&" + key + "=";
|
||||
} catch (Exception e1) {
|
||||
string.append("&").append(key).append("=");
|
||||
@@ -139,6 +143,17 @@ public class HttpTools {
|
||||
string = new StringBuilder(string.substring(1, string.length()).replaceAll(" ", ""));
|
||||
return string.toString();
|
||||
}
|
||||
public static Map<String,String> getUrlParams(String url){
|
||||
Map<String,String> map=new HashMap<>();
|
||||
if(url.contains("?")){
|
||||
String param=url.split("\\?")[1];
|
||||
String[] params=param.split("&");
|
||||
for (String par : params) {
|
||||
map.put(par.split("=")[0],par.split("=")[1]);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
58
src/main/java/com/yutou/qqbot/utlis/QRCodeUtils.java
Normal file
58
src/main/java/com/yutou/qqbot/utlis/QRCodeUtils.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.yutou.qqbot.utlis;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class QRCodeUtils {
|
||||
private static final int BLACK = 0xFF000000;
|
||||
private static final int WHITE = 0xFFFFFFFF;
|
||||
|
||||
|
||||
public static File createQRCode(String codeName,String value){
|
||||
try {
|
||||
String imageType = "jpg";// 图片类型
|
||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
||||
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
||||
BitMatrix bitMatrix = multiFormatWriter.encode(value, BarcodeFormat.QR_CODE, 400, 400, hints);
|
||||
if(!new File("QRCode").exists()){
|
||||
boolean mkdirs = new File(("QRCode")).mkdirs();
|
||||
System.out.println("create QRCode dir is = "+mkdirs);
|
||||
}
|
||||
File file1 = new File("QRCode"+File.separator+ codeName + "." + imageType);
|
||||
writeToFile(bitMatrix, imageType, file1);
|
||||
return file1;
|
||||
} catch (WriterException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private static BufferedImage toBufferedImage(BitMatrix matrix) {
|
||||
int width = matrix.getWidth();
|
||||
int height = matrix.getHeight();
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
private static void writeToFile(BitMatrix matrix, String format, File file) throws IOException {
|
||||
BufferedImage image = toBufferedImage(matrix);
|
||||
if (!ImageIO.write(image, format, file)) {
|
||||
throw new IOException("Could not write an image of format " + format + " to " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,21 +49,24 @@ public class WebClient {
|
||||
json.getString("domain"),
|
||||
json.getString("path"),
|
||||
containsDate ? new Date(t) : new Date(),
|
||||
json.getBoolean("secure"),
|
||||
json.getBoolean("httpOnly")
|
||||
json.containsKey("secure")?json.getBoolean("secure"):false,
|
||||
json.containsKey("httpOnly")?json.getBoolean("httpOnly"):false
|
||||
|
||||
);
|
||||
list.add(cookie);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static boolean headless=false;
|
||||
public static void setHeadless(boolean headless){
|
||||
WebClient.headless=headless;
|
||||
}
|
||||
public static ChromeOptions getOptions() {
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
// options.addArguments("--disable-gpu");
|
||||
// options.addArguments("blink-settings=imagesEnabled=false");
|
||||
String headless = RedisTools.get("headless");
|
||||
if("true".equals(headless)) {
|
||||
if("true".equals(headless)||WebClient.headless) {
|
||||
options.addArguments("--headless");
|
||||
}
|
||||
options.addArguments("--no-sandbox");
|
||||
|
||||
Reference in New Issue
Block a user