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

@ -13,12 +13,13 @@ import java.io.File;
import java.util.*; 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);
String url = json.getString("url"); String url = json.getString("url");
if(url.endsWith(".apk")){ if (url.endsWith(".apk")) {
Tools.download(url, new DownloadInterface() { Tools.download(url, new DownloadInterface() {
@Override @Override
public void onDownload(String file) { public void onDownload(String file) {
@ -47,30 +48,32 @@ 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) {
String path = RedisTools.get(data,1); System.out.println("data=" + data + " packagename=" + packagename + " version=" + version);
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;
} }
if(runThread==null){ if (runThread == null) {
runThread=new MyThread(); runThread = new MyThread();
} }
} }
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,15 +83,16 @@ 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);
long nowTime=System.currentTimeMillis()-startTime; long nowTime = System.currentTimeMillis() - startTime;
RedisTools.set(1,"msg_"+System.currentTimeMillis(),apk.getName() RedisTools.set(1, "msg_" + System.currentTimeMillis(), apk.getName()
+"已处理完成,下载地址" + + "已处理完成,下载地址" +
"\n"+file + "\n" + file +
"\n请在十分钟内下载超时将自动删除" + "\n请在十分钟内下载超时将自动删除" +
"\n耗时"+nowTime+"ms"); "\n耗时" + nowTime + "ms");
path = file.replace("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/", ""); path = file.replace("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/", "");
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
@ -107,31 +111,31 @@ 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();
} }
@Override @Override
public void run() { public void run() {
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(); isRun = true;
list.clear(); for (Long key : map.keySet()) {
isRun=true; JSONObject json=map.get(key);
while (iterator.hasNext()){ map.remove(key);
JSONObject json=iterator.next(); 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){