This commit is contained in:
Yutousama 2020-06-03 09:41:40 +08:00
parent 5d366b8bd1
commit e614cc6f34
2 changed files with 66 additions and 58 deletions

Binary file not shown.

View File

@ -13,6 +13,7 @@ import java.io.File;
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);
@ -29,7 +30,7 @@ public class BotTools {
redisTools.setex("downloadApk_" + uuid, RedisTools.TOKEN_TIMEOUT_DEFAULT, file);
redisTools.close();
RedisTools.set(1, "msg_" + System.currentTimeMillis(), "检测到上传apk请选择处理方式" +
"\n1)生成穿山甲资源包 (回复 #csj#穿山甲包名#穿山甲版本号#downloadApk_" + uuid + ")" +
"\n1)生成穿山甲资源包 回复 #csj#穿山甲包名#穿山甲版本号#downloadApk_" + uuid + "" +
"\n2)不处理 (360s后自动取消)" +
"\n$downloadApk_" + uuid);
}
@ -61,71 +62,78 @@ public class BotTools {
RedisTools.set(1, "msg_" + System.currentTimeMillis(), file + "\n已加入到队列");
return;
}
csj();
if(runThread==null){
runThread=new MyThread();
}
}
private static void csj() {
if (list.size() > 0) {
List<JSONObject> tmp = new ArrayList<>(list);
list.clear();
for (JSONObject jsonObject : tmp) {
isRun=true;
long startTime=System.currentTimeMillis();
File apk=new File(jsonObject.getString("file"));
new CsjTools(jsonObject.getString("file")
, new File("csj" + File.separator + "demo.apk").getAbsolutePath()
, jsonObject.getString("packagename")
, jsonObject.getString("version")
, new SmaliApkToolsPath() {
@Override
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 +
"\n请在十分钟内下载超时将自动删除" +
"\n耗时"+nowTime+"ms");
path = file.replace("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/", "");
isRun=false;
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
if (list.size() > 0) {
RedisTools.set(1, "msg_" + System.currentTimeMillis(), "开始下一个队列");
csj();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10 * 60 * 1000);
OSSTools.delete(path);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
private static void csj(JSONObject jsonObject) {
long startTime=System.currentTimeMillis();
File apk=new File(jsonObject.getString("file"));
new CsjTools(jsonObject.getString("file")
, new File("csj" + File.separator + "demo.apk").getAbsolutePath()
, jsonObject.getString("packagename")
, jsonObject.getString("version")
, new SmaliApkToolsPath() {
@Override
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 +
"\n请在十分钟内下载超时将自动删除" +
"\n耗时"+nowTime+"ms");
path = file.replace("https://yutou-oss-test.oss-cn-hangzhou.aliyuncs.com/", "");
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10 * 60 * 1000);
OSSTools.delete(path);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}).start();
System.gc();
}
});
}
});
}
private static class MyThread extends Thread{
public MyThread() {
if(runThread!=null){
return;
}
start();
}
@Override
public void run() {
super.run();
while (true){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(list.size()!=0){
Iterator<JSONObject> iterator=list.iterator();
list.clear();
isRun=true;
while (iterator.hasNext()){
JSONObject json=iterator.next();
}
isRun=false;
}
}
}
}
}