新增代理

This commit is contained in:
Yutousama 2023-02-27 20:48:09 +08:00
parent 0819bc58aa
commit a27d6c5a35
2 changed files with 27 additions and 15 deletions

View File

@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@UseModel @UseModel
public class GetSeTu extends Model { public class GetSeTu extends Model {
@Override @Override
@ -157,9 +158,11 @@ public class GetSeTu extends Model {
RedisTools.set("Setu_" + qq, array.toString()); RedisTools.set("Setu_" + qq, array.toString());
} }
} }
private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event) { private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event) {
return getSeTu(model, key, r18, fuzzyR18, qq, event, 3); return getSeTu(model, key, r18, fuzzyR18, qq, event, 3);
} }
private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event, int reset) { private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event, int reset) {
if (reset <= 0) { if (reset <= 0) {
QQBotManager.getInstance().sendMessage(qq, "获取失败喵~"); QQBotManager.getInstance().sendMessage(qq, "获取失败喵~");
@ -192,7 +195,7 @@ public class GetSeTu extends Model {
url = url.replace("&r18=0", "&r18=2").replace("&r18=1", "&r18=2"); url = url.replace("&r18=0", "&r18=2").replace("&r18=1", "&r18=2");
} }
System.out.println("url = " + url); System.out.println("url = " + url);
String ret = HttpTools.get(url); String ret = HttpTools.http_get(url, null, true);
JSONObject json = JSON.parseObject(ret); JSONObject json = JSON.parseObject(ret);
if (json.getJSONArray("data").size() == 0) { if (json.getJSONArray("data").size() == 0) {
return false; return false;

View File

@ -17,7 +17,7 @@ public class HttpTools {
private static final int HttpRequestIndex = 3; private static final int HttpRequestIndex = 3;
public static String get(String url) { public static String get(String url) {
return http_get(url, null); return http_get(url, null,false);
} }
public static String post(final String url, final byte[] body) { public static String post(final String url, final byte[] body) {
@ -40,10 +40,19 @@ public class HttpTools {
return null; return null;
} }
public static String http_get(String url, Map<String, String> header) { public static String http_get(String url, Map<String, String> header,boolean isProxy) {
try { try {
HttpURLConnection connection; HttpURLConnection connection;
Proxy proxy = null;
if (isProxy) {
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
}
if(proxy==null) {
connection = (HttpURLConnection) new URL(url).openConnection(); connection = (HttpURLConnection) new URL(url).openConnection();
}else{
connection = (HttpURLConnection) new URL(url).openConnection(proxy);
}
return urlConnection(header, connection); return urlConnection(header, connection);
} catch (Exception e) { } catch (Exception e) {
System.err.println("error url = " + url); System.err.println("error url = " + url);