From 5b928afa8274468ef3d17c5f76be893ac08823aa Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 2 Jan 2022 00:14:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=A9=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/models/setu/GetSeTu.java | 21 ++++++++++++++++++- .../java/com/yutou/qqbot/utlis/HttpTools.java | 10 +++++++-- 2 files changed, 28 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 79e0240..0a43a89 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -1,5 +1,6 @@ package com.yutou.qqbot.models.setu; +import com.alibaba.fastjson.JSONObject; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.models.Model; @@ -24,7 +25,10 @@ public class GetSeTu extends Model { public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); if ("来点色图".equals(msg)||"来点涩图".equals(msg)){ - HttpTools.download(" https://api.ixiaowai.cn/api/api.php", + String ret=HttpTools.get("https://api.ixiaowai.cn/api/api.php?return=json"); + System.out.println("ret = " + ret); + JSONObject json=JSONObject.parseObject(ret); + HttpTools.download(json.getString("acgurl"), null, new DownloadInterface() { @Override public void onDownload(File file) { @@ -35,4 +39,19 @@ public class GetSeTu extends Model { }); } } + + public static void main(String[] args) { + HttpTools.download("https://api.ixiaowai.cn/api/api.php", null, new DownloadInterface() { + @Override + public void onDownload(File file) { + super.onDownload(file); + System.out.println(file.getAbsoluteFile()); + } + + @Override + public void onError(Exception e) { + e.printStackTrace(); + } + }); + } } diff --git a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java index 9e6535d..5810336 100644 --- a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java @@ -3,6 +3,7 @@ package com.yutou.qqbot.utlis; import com.alibaba.fastjson.JSONObject; import com.yutou.qqbot.interfaces.DownloadInterface; +import javax.net.ssl.HttpsURLConnection; import java.io.*; import java.net.*; import java.util.Map; @@ -156,11 +157,16 @@ public class HttpTools { savePath.mkdirs(); } Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName); - HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + URLConnection connection; + if(url.startsWith("https:")) { + connection = (HttpsURLConnection) new URL(url).openConnection(); + }else{ + connection=(HttpURLConnection)new URL(url).openConnection(); + } + connection.addRequestProperty("User-Agent", getExtUa()); // Log.i(TAG,"获取到网络请求:"+connection.getResponseCode()); - InputStream inputStream = connection.getInputStream(); jar = new File(donwloadPath + saveName + "_tmp.tmp"); jar.createNewFile();