update
This commit is contained in:
parent
f2ce55ba7b
commit
dd0fa8eefd
Binary file not shown.
Binary file not shown.
16
pom.xml
16
pom.xml
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>com.yutou</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.0.7.2</version>
|
||||
<version>1.0.7.3</version>
|
||||
<name>tools</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
@ -86,20 +86,6 @@
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>android_sdk_tools</groupId>
|
||||
<artifactId>android_sdk_tools</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/libs/android_sdk_tools.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>apktool</groupId>
|
||||
<artifactId>apktool</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/libs/apktool_2.4.1.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,23 +1,19 @@
|
||||
package com.yutou.tools.home.nas;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qy.Interfaces.SmaliApkToolsPath;
|
||||
import com.qy.utils.CsjTools;
|
||||
import com.yutou.tools.interfaces.DownloadInterface;
|
||||
import com.yutou.tools.utils.OSSTools;
|
||||
import com.yutou.tools.utils.RedisTools;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
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);
|
||||
protected static String download(JSONObject json) {
|
||||
String url = json.getString("url");
|
||||
if (url.endsWith(".apk")) {
|
||||
Tools.download(url, new DownloadInterface() {
|
||||
@ -25,15 +21,7 @@ public class BotTools {
|
||||
public void onDownload(String file) {
|
||||
super.onDownload(file);
|
||||
if (file.endsWith(".apk")) {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
Jedis redisTools = RedisTools.getRedis();
|
||||
redisTools.select(1);
|
||||
redisTools.setex("downloadApk_" + uuid, RedisTools.TOKEN_TIMEOUT_DEFAULT, file);
|
||||
redisTools.close();
|
||||
RedisTools.set(1, "msg_" + System.currentTimeMillis(), "检测到上传apk,请选择处理方式:" +
|
||||
"\n1)生成穿山甲资源包 回复 #csj#穿山甲包名#穿山甲版本号#downloadApk_" + uuid + "" +
|
||||
"\n2)不处理 (360s后自动取消)" +
|
||||
"\n$downloadApk_" + uuid);
|
||||
csjAssets(file, json.getString("package"), json.getString("version"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,9 +39,8 @@ public class BotTools {
|
||||
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);
|
||||
static void csjAssets(String path, String packagename, String version) {
|
||||
System.out.println("data=" + path + " packagename=" + packagename + " version=" + version);
|
||||
File file = new File(path);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("file", file);
|
||||
@ -61,7 +48,7 @@ public class BotTools {
|
||||
json.put("packagename", packagename);
|
||||
map.put(System.currentTimeMillis(), json);
|
||||
if (isRun) {
|
||||
RedisTools.set(1, "msg_" + System.currentTimeMillis(), file + "\n已加入到队列");
|
||||
RedisTools.set(1, "msg_" + System.currentTimeMillis(), file.getName() + "\n已加入到队列");
|
||||
return;
|
||||
}
|
||||
if (runThread == null) {
|
||||
@ -72,16 +59,28 @@ public class BotTools {
|
||||
|
||||
private static void csj(JSONObject jsonObject) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
isRun = true;
|
||||
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")
|
||||
, jsonObject.getString("version")
|
||||
, new SmaliApkToolsPath() {
|
||||
@Override
|
||||
public void smaliPath(String s) {
|
||||
OSSTools.uploadFile(new File(s), new DownloadInterface() {
|
||||
try {
|
||||
File csc = new File("out" + File.separator + apk.getName().replace(".", "") + File.separator + "csc");
|
||||
csc.mkdirs();
|
||||
if (csc.exists()) {
|
||||
csc.delete();
|
||||
}
|
||||
System.out.println(">>" + csc.getAbsolutePath());
|
||||
Process process = Runtime.getRuntime().exec(String.format("java -jar android_sdk_tools.jar -package=%s -version=%s -apk=%s -csj=%s -csc=%s"
|
||||
, jsonObject.getString("packagename"), jsonObject.getString("version"), apk.getAbsoluteFile()
|
||||
, new File("csj" + File.separator + "demo.apk"), csc.getAbsoluteFile()));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String tmp;
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
System.out.println(tmp);
|
||||
}
|
||||
reader.close();
|
||||
process.destroy();
|
||||
if (csc.exists())
|
||||
OSSTools.uploadFile(csc, new DownloadInterface() {
|
||||
String path;
|
||||
|
||||
@Override
|
||||
@ -91,25 +90,15 @@ public class BotTools {
|
||||
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();
|
||||
isRun = false;
|
||||
System.gc();
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class MyThread extends Thread {
|
||||
|
@ -7,9 +7,11 @@ 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 redis.clients.jedis.Jedis;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/localhome/bot")
|
||||
@ -36,7 +38,30 @@ public class QQBot {
|
||||
public String botMsg(String msg,String type){
|
||||
System.out.println(type);
|
||||
if(type.trim().equals("download")){
|
||||
BotTools.download(msg);
|
||||
JSONObject json=JSONObject.parseObject(new String(Base64.getDecoder().decode(msg)));
|
||||
String url=json.getString("url");
|
||||
if(url.endsWith(".apk")){
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
Jedis redisTools = RedisTools.getRedis();
|
||||
redisTools.select(1);
|
||||
redisTools.setex("downloadApk_" + uuid, RedisTools.TOKEN_TIMEOUT_DEFAULT, msg);
|
||||
redisTools.close();
|
||||
String packageName=null;
|
||||
String version=null;
|
||||
packageName=RedisTools.get("csj_packageName",1);
|
||||
version=RedisTools.get("csj_version",1);
|
||||
if(packageName==null){
|
||||
packageName="穿山甲包名";
|
||||
}
|
||||
if(version==null){
|
||||
version="穿山甲版本号";
|
||||
}
|
||||
RedisTools.set(1, "msg_" + System.currentTimeMillis(), "检测到上传apk,请选择处理方式:" +
|
||||
"\n1)生成穿山甲资源包 回复 #csj#"+packageName+"#"+version+"#downloadApk_" + uuid + "" +
|
||||
"\n2)不处理 (360s后自动取消)" +
|
||||
"\n输入 *set csj_packageName XXX 可设置默认包名" +
|
||||
"\n输入 *set csj_version XXX 可设置默认版本号");
|
||||
}
|
||||
}
|
||||
return "OK~";
|
||||
}
|
||||
@ -46,7 +71,11 @@ public class QQBot {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BotTools.csjAssets(data, packagename, version);
|
||||
String msg = RedisTools.get(data, 1);
|
||||
JSONObject json=JSONObject.parseObject(new String(Base64.getDecoder().decode(msg)));
|
||||
json.put("package",packagename);
|
||||
json.put("version",version);
|
||||
BotTools.download(json);
|
||||
}
|
||||
}).start();
|
||||
return "ok";
|
||||
|
Loading…
Reference in New Issue
Block a user