This commit is contained in:
Yutousama 2020-06-03 17:52:18 +08:00
parent e614cc6f34
commit f2ce55ba7b
4 changed files with 38 additions and 32 deletions

View File

@ -14,6 +14,7 @@ import java.util.*;
public class BotTools { public class BotTools {
private static Thread runThread = null; private static Thread runThread = null;
protected static String download(String msg) { protected static String download(String msg) {
String _json = new String(Base64.getDecoder().decode(msg)); String _json = new String(Base64.getDecoder().decode(msg));
JSONObject json = JSONObject.parseObject(_json); JSONObject json = JSONObject.parseObject(_json);
@ -47,17 +48,18 @@ public class BotTools {
return "ok"; return "ok";
} }
private static List<JSONObject> list = new ArrayList<>(); private static Map<Long,JSONObject> map=new HashMap<>();
private static boolean isRun = false; private static boolean isRun = false;
static void csjAssets(String data, String packagename, String version) { static void csjAssets(String data, String packagename, String version) {
System.out.println("data=" + data + " packagename=" + packagename + " version=" + version);
String path = RedisTools.get(data, 1); String path = RedisTools.get(data, 1);
File file = new File(path); File file = new File(path);
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("file", file); json.put("file", file);
json.put("version", version); json.put("version", version);
json.put("packagename", packagename); json.put("packagename", packagename);
list.add(json); map.put(System.currentTimeMillis(),json);
if (isRun) { if (isRun) {
RedisTools.set(1, "msg_" + System.currentTimeMillis(), file + "\n已加入到队列"); RedisTools.set(1, "msg_" + System.currentTimeMillis(), file + "\n已加入到队列");
return; return;
@ -71,6 +73,7 @@ public class BotTools {
private static void csj(JSONObject jsonObject) { private static void csj(JSONObject jsonObject) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
File apk = new File(jsonObject.getString("file")); File apk = new File(jsonObject.getString("file"));
RedisTools.set(1, "msg_" + System.currentTimeMillis(), "开始处理:" + apk.getName());
new CsjTools(jsonObject.getString("file") new CsjTools(jsonObject.getString("file")
, new File("csj" + File.separator + "demo.apk").getAbsolutePath() , new File("csj" + File.separator + "demo.apk").getAbsolutePath()
, jsonObject.getString("packagename") , jsonObject.getString("packagename")
@ -80,6 +83,7 @@ public class BotTools {
public void smaliPath(String s) { public void smaliPath(String s) {
OSSTools.uploadFile(new File(s), new DownloadInterface() { OSSTools.uploadFile(new File(s), new DownloadInterface() {
String path; String path;
@Override @Override
public void onDownload(String file) { public void onDownload(String file) {
super.onDownload(file); super.onDownload(file);
@ -107,11 +111,10 @@ public class BotTools {
} }
}); });
} }
private static class MyThread extends Thread { private static class MyThread extends Thread {
public MyThread() { public MyThread() {
if(runThread!=null){ System.out.println("启动线程");
return;
}
start(); start();
} }
@ -120,16 +123,17 @@ public class BotTools {
super.run(); super.run();
while (true) { while (true) {
try { try {
Thread.sleep(100); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
if(list.size()!=0){ if (map.size() > 0) {
Iterator<JSONObject> iterator=list.iterator();
list.clear();
isRun = true; isRun = true;
while (iterator.hasNext()){ for (Long key : map.keySet()) {
JSONObject json=iterator.next(); JSONObject json=map.get(key);
map.remove(key);
csj(json);
} }
isRun = false; isRun = false;
} }

View File

@ -1,12 +1,15 @@
package com.yutou.tools.home.nas; package com.yutou.tools.home.nas;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.interfaces.DownloadInterface;
import com.yutou.tools.utils.OSSTools;
import com.yutou.tools.utils.RedisTools; import com.yutou.tools.utils.RedisTools;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.io.File; import java.io.File;
import java.util.Base64;
@Controller @Controller
@RequestMapping("/localhome/bot") @RequestMapping("/localhome/bot")
@ -46,8 +49,6 @@ public class QQBot {
BotTools.csjAssets(data, packagename, version); BotTools.csjAssets(data, packagename, version);
} }
}).start(); }).start();
return "ok"; return "ok";
} }
} }

View File

@ -31,6 +31,7 @@ public class OSSTools {
ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(outputStream.toByteArray())); ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(outputStream.toByteArray()));
outputStream.close(); outputStream.close();
inputStream.close(); inputStream.close();
downloadInterface.onDownload("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/"+objectName); downloadInterface.onDownload("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/"+objectName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -21,7 +21,7 @@ public class RedisTools {
//Properties properties = PropertyUtil.loadProperties("jedis.properties"); //Properties properties = PropertyUtil.loadProperties("jedis.properties");
//host = properties.getProperty("redis.host"); //host = properties.getProperty("redis.host");
//port = Integer.valueOf(properties.getProperty("redis.port")); //port = Integer.valueOf(properties.getProperty("redis.port"));
host="192.168.31.88"; host="127.0.0.1";
port=6379; port=6379;
} }
public static boolean set(int dbIndex,String key,String value){ public static boolean set(int dbIndex,String key,String value){