From f2ce55ba7b41d2e5436b771611b01aaf6f4f5eb1 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Wed, 3 Jun 2020 17:52:18 +0800 Subject: [PATCH] update --- .../com/yutou/tools/home/nas/BotTools.java | 62 ++++++++++--------- .../java/com/yutou/tools/home/nas/QQBot.java | 5 +- .../java/com/yutou/tools/utils/OSSTools.java | 1 + .../com/yutou/tools/utils/RedisTools.java | 2 +- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/yutou/tools/home/nas/BotTools.java b/src/main/java/com/yutou/tools/home/nas/BotTools.java index ecf772a..a1fcbe0 100644 --- a/src/main/java/com/yutou/tools/home/nas/BotTools.java +++ b/src/main/java/com/yutou/tools/home/nas/BotTools.java @@ -13,12 +13,13 @@ import java.io.File; import java.util.*; public class BotTools { - private static Thread runThread=null; + private static Thread runThread = null; + protected static String download(String msg) { String _json = new String(Base64.getDecoder().decode(msg)); JSONObject json = JSONObject.parseObject(_json); String url = json.getString("url"); - if(url.endsWith(".apk")){ + if (url.endsWith(".apk")) { Tools.download(url, new DownloadInterface() { @Override public void onDownload(String file) { @@ -47,30 +48,32 @@ public class BotTools { return "ok"; } - private static List list = new ArrayList<>(); + private static Map map=new HashMap<>(); private static boolean isRun = false; - static void csjAssets(String data, String packagename,String version) { - String path = RedisTools.get(data,1); + static void csjAssets(String data, String packagename, String version) { + System.out.println("data=" + data + " packagename=" + packagename + " version=" + version); + String path = RedisTools.get(data, 1); File file = new File(path); JSONObject json = new JSONObject(); json.put("file", file); json.put("version", version); json.put("packagename", packagename); - list.add(json); + map.put(System.currentTimeMillis(),json); if (isRun) { RedisTools.set(1, "msg_" + System.currentTimeMillis(), file + "\n已加入到队列"); return; } - if(runThread==null){ - runThread=new MyThread(); - } + if (runThread == null) { + runThread = new MyThread(); + } } private static void csj(JSONObject jsonObject) { - long startTime=System.currentTimeMillis(); - File apk=new File(jsonObject.getString("file")); + long startTime = System.currentTimeMillis(); + File apk = new File(jsonObject.getString("file")); + RedisTools.set(1, "msg_" + System.currentTimeMillis(), "开始处理:" + apk.getName()); new CsjTools(jsonObject.getString("file") , new File("csj" + File.separator + "demo.apk").getAbsolutePath() , jsonObject.getString("packagename") @@ -80,15 +83,16 @@ public class BotTools { public void smaliPath(String s) { OSSTools.uploadFile(new File(s), new DownloadInterface() { String path; + @Override public void onDownload(String file) { super.onDownload(file); - long nowTime=System.currentTimeMillis()-startTime; - RedisTools.set(1,"msg_"+System.currentTimeMillis(),apk.getName() - +"已处理完成,下载地址" + - "\n"+file + + long nowTime = System.currentTimeMillis() - startTime; + RedisTools.set(1, "msg_" + System.currentTimeMillis(), apk.getName() + + "已处理完成,下载地址" + + "\n" + file + "\n请在十分钟内下载,超时将自动删除" + - "\n耗时:"+nowTime+"ms"); + "\n耗时:" + nowTime + "ms"); path = file.replace("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/", ""); new Thread(new Runnable() { @Override @@ -107,31 +111,31 @@ public class BotTools { } }); } - private static class MyThread extends Thread{ + + private static class MyThread extends Thread { public MyThread() { - if(runThread!=null){ - return; - } + System.out.println("启动线程"); start(); } @Override public void run() { super.run(); - while (true){ + while (true) { try { - Thread.sleep(100); + Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } - if(list.size()!=0){ - Iterator iterator=list.iterator(); - list.clear(); - isRun=true; - while (iterator.hasNext()){ - JSONObject json=iterator.next(); + if (map.size() > 0) { + isRun = true; + for (Long key : map.keySet()) { + JSONObject json=map.get(key); + map.remove(key); + csj(json); + } - isRun=false; + isRun = false; } } } diff --git a/src/main/java/com/yutou/tools/home/nas/QQBot.java b/src/main/java/com/yutou/tools/home/nas/QQBot.java index 1216971..0dfc5c7 100644 --- a/src/main/java/com/yutou/tools/home/nas/QQBot.java +++ b/src/main/java/com/yutou/tools/home/nas/QQBot.java @@ -1,12 +1,15 @@ package com.yutou.tools.home.nas; import com.alibaba.fastjson.JSONObject; +import com.yutou.tools.interfaces.DownloadInterface; +import com.yutou.tools.utils.OSSTools; import com.yutou.tools.utils.RedisTools; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.io.File; +import java.util.Base64; @Controller @RequestMapping("/localhome/bot") @@ -46,8 +49,6 @@ public class QQBot { BotTools.csjAssets(data, packagename, version); } }).start(); - - return "ok"; } } diff --git a/src/main/java/com/yutou/tools/utils/OSSTools.java b/src/main/java/com/yutou/tools/utils/OSSTools.java index 3e2d647..b9da2b4 100644 --- a/src/main/java/com/yutou/tools/utils/OSSTools.java +++ b/src/main/java/com/yutou/tools/utils/OSSTools.java @@ -31,6 +31,7 @@ public class OSSTools { ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(outputStream.toByteArray())); outputStream.close(); inputStream.close(); + downloadInterface.onDownload("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/"+objectName); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/yutou/tools/utils/RedisTools.java b/src/main/java/com/yutou/tools/utils/RedisTools.java index 5ee5dc3..574d7d5 100644 --- a/src/main/java/com/yutou/tools/utils/RedisTools.java +++ b/src/main/java/com/yutou/tools/utils/RedisTools.java @@ -21,7 +21,7 @@ public class RedisTools { //Properties properties = PropertyUtil.loadProperties("jedis.properties"); //host = properties.getProperty("redis.host"); //port = Integer.valueOf(properties.getProperty("redis.port")); - host="192.168.31.88"; + host="127.0.0.1"; port=6379; } public static boolean set(int dbIndex,String key,String value){