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());