diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 3a8c9dd..ba82918 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -207,6 +207,7 @@ public class QQBotManager { } public String sendMessage(List imgs,Long qq, String text) { + System.out.println("imgs.size() = " + imgs.size()); if (bot != null) { MessageChainBuilder builder = new MessageChainBuilder(); for (File img : imgs) { diff --git a/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java b/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java index cc85463..3a0482c 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java @@ -83,21 +83,9 @@ public class Bangumi extends Model { return; } for (String img : imgs) { - HttpTools.download(img,key+".png", new DownloadInterface() { - @Override - public void onDownload(File file) { - super.onDownload(file); - files.add(file); - send(imgs.size(),qq, text); - } - - @Override - public void onError(Exception e) { - super.onError(e); - index++; - send(imgs.size(),qq, text); - } - }); + File file = HttpTools.syncDownload(img.replace("http://","https://"), key + ".jpg"); + files.add(file); + send(imgs.size(),qq, text); } } diff --git a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java index ec63cf0..4646855 100644 --- a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java @@ -156,25 +156,9 @@ public class HttpTools { } public static void main(String[] args) { - JSONObject json = new JSONObject(); - json.put("pid", "102"); - json.put("gid", "100584"); - json.put("gameKey", "0gha58u1c9FjZkeAsEmYIzTvp"); - json.put("access_token", "659c-S1gV0DwMXdYjPDlSrSLNYOvA8qUoCSvmdFEHvZugKgNX4Z2BCwF18A7W2gRdG7WiWfKsbZgF6YssZHhaozksI9RBn2QQFTXzmAHtbMd4ginEEtwdKmPCM4JbJGg1ollqoNE0PcGENpa4F3e7EdSOa_JFyE6XyUQN1iurJU3F8MZfLlTIcTR9USYoHX15vsAkCht_0mrapZblkeY1_8HFrmK8rlenbZLxccy7PrMz5eZ9uPPDJL5OYiEahyrtLENB8SVmlGofJfQw8wUjN8_XVZSfLMujdwz24"); - String url = "http://192.168.1.156:9020/Faxing/reg?" + - "&tpyeCode=dimai" + - "®ParamJson=" + json.toJSONString(); - /* ExecutorService service= Executors.newCachedThreadPool(); - for (int i = 0; i < 3000; i++) { - service.submit(new Runnable() { - @Override - public void run() { - get(url); - } - }); - }*/ - Log.i(url); - //String str=get(url); + File file = syncDownload("https://lain.bgm.tv/pic/cover/l/6c/2a/302128_qQIjG.jpg", "12345.jpg"); + System.out.println("file.length() = " + file.length()); + } private static String donwloadPath = "tmp" + File.separator; @@ -257,14 +241,13 @@ public class HttpTools { connection.addRequestProperty("User-Agent", getExtUa()); // Log.i(TAG,"获取到网络请求:"+connection.getResponseCode()); - + connection.addRequestProperty("Content-type","image/jpeg"); InputStream inputStream = connection.getInputStream(); jar = new File(donwloadPath + saveName + "_tmp.tmp"); jar.createNewFile(); Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath()); OutputStream outputStream = new FileOutputStream(jar); byte[] bytes = new byte[1024]; - double size = connection.getContentLength(); double downSize = 0; int len; while ((len = inputStream.read(bytes)) > 0) {