From f6c9748f48b9c21eaea1a027a708ece1431eb7c2 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 17 Apr 2022 01:06:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=94=AF=E6=8C=81=E4=BB=A3?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/models/setu/GetSeTu.java | 4 +++- .../java/com/yutou/qqbot/utlis/HttpTools.java | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index 9e5dee3..bea11b8 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -33,7 +33,9 @@ public class GetSeTu extends Model { String ret = HttpTools.get("https://api.lolicon.app/setu/v2?r18=2"); JSONObject json = JSONObject.parseObject(ret); HttpTools.download(json.getJSONArray("data").getJSONObject(0).getJSONObject("urls").getString("original"), - System.currentTimeMillis()+"_setu.jpg", new DownloadInterface() { + System.currentTimeMillis()+"_setu.jpg", + true + , new DownloadInterface() { @Override public void onDownload(File file) { super.onDownload(file); diff --git a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java index 4646855..63488e7 100644 --- a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java @@ -164,21 +164,36 @@ public class HttpTools { private static String donwloadPath = "tmp" + File.separator; public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) { + download(url,saveName,false,downloadInterface); + } + public synchronized static void download(final String url, final String saveName,boolean isProxy, final DownloadInterface downloadInterface) { new Thread(new Runnable() { @Override public void run() { File jar = null; try { File savePath = new File(donwloadPath); + Proxy proxy=null; if (!savePath.exists()) { savePath.mkdirs(); } Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName); + if (isProxy){ + proxy=new Proxy(Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1",7890)); + } URLConnection connection; if(url.startsWith("https:")) { - connection = (HttpsURLConnection) new URL(url).openConnection(); + if(isProxy) { + connection = (HttpsURLConnection) new URL(url).openConnection(proxy); + }else{ + connection = (HttpsURLConnection) new URL(url).openConnection(); + } }else{ - connection=(HttpURLConnection)new URL(url).openConnection(); + if(isProxy) { + connection = (HttpURLConnection) new URL(url).openConnection(proxy); + }else{ + connection = (HttpURLConnection) new URL(url).openConnection(); + } } connection.addRequestProperty("User-Agent", getExtUa());