update
This commit is contained in:
parent
e614cc6f34
commit
f2ce55ba7b
@ -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<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) {
|
||||
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<JSONObject> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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){
|
||||
|
Loading…
Reference in New Issue
Block a user