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 {
private static Thread runThread = null;
protected static String download(String msg) {
String _json = new String(Base64.getDecoder().decode(msg));
JSONObject json = JSONObject.parseObject(_json);
@ -47,17 +48,18 @@ public class BotTools {
return "ok";
}
private static List<JSONObject> list = new ArrayList<>();
private static Map<Long,JSONObject> map=new HashMap<>();
private static boolean isRun = false;
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;
@ -71,6 +73,7 @@ public class BotTools {
private static void csj(JSONObject jsonObject) {
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,6 +83,7 @@ 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);
@ -107,11 +111,10 @@ public class BotTools {
}
});
}
private static class MyThread extends Thread {
public MyThread() {
if(runThread!=null){
return;
}
System.out.println("启动线程");
start();
}
@ -120,16 +123,17 @@ public class BotTools {
super.run();
while (true) {
try {
Thread.sleep(100);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(list.size()!=0){
Iterator<JSONObject> iterator=list.iterator();
list.clear();
if (map.size() > 0) {
isRun = true;
while (iterator.hasNext()){
JSONObject json=iterator.next();
for (Long key : map.keySet()) {
JSONObject json=map.get(key);
map.remove(key);
csj(json);
}
isRun = false;
}

View File

@ -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";
}
}

View File

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

View File

@ -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){