This commit is contained in:
Yutousama 2020-06-03 21:55:03 +08:00
parent f2ce55ba7b
commit dd0fa8eefd
5 changed files with 65 additions and 61 deletions

Binary file not shown.

Binary file not shown.

16
pom.xml
View File

@ -10,7 +10,7 @@
</parent> </parent>
<groupId>com.yutou</groupId> <groupId>com.yutou</groupId>
<artifactId>tools</artifactId> <artifactId>tools</artifactId>
<version>1.0.7.2</version> <version>1.0.7.3</version>
<name>tools</name> <name>tools</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
@ -86,20 +86,6 @@
<artifactId>aliyun-sdk-oss</artifactId> <artifactId>aliyun-sdk-oss</artifactId>
<version>3.8.0</version> <version>3.8.0</version>
</dependency> </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> </dependencies>
<build> <build>

View File

@ -1,23 +1,19 @@
package com.yutou.tools.home.nas; package com.yutou.tools.home.nas;
import com.alibaba.fastjson.JSONObject; 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.interfaces.DownloadInterface;
import com.yutou.tools.utils.OSSTools; import com.yutou.tools.utils.OSSTools;
import com.yutou.tools.utils.RedisTools; import com.yutou.tools.utils.RedisTools;
import com.yutou.tools.utils.Tools; import com.yutou.tools.utils.Tools;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import java.io.File; import java.io.*;
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(JSONObject json) {
String _json = new String(Base64.getDecoder().decode(msg));
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() {
@ -25,15 +21,7 @@ public class BotTools {
public void onDownload(String file) { public void onDownload(String file) {
super.onDownload(file); super.onDownload(file);
if (file.endsWith(".apk")) { if (file.endsWith(".apk")) {
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase(); csjAssets(file, json.getString("package"), json.getString("version"));
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);
} }
} }
@ -48,20 +36,19 @@ public class BotTools {
return "ok"; return "ok";
} }
private static Map<Long,JSONObject> map=new HashMap<>(); 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 path, String packagename, String version) {
System.out.println("data=" + data + " packagename=" + packagename + " version=" + version); System.out.println("data=" + path + " 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);
map.put(System.currentTimeMillis(),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.getName() + "\n已加入到队列");
return; return;
} }
if (runThread == null) { if (runThread == null) {
@ -72,16 +59,28 @@ public class BotTools {
private static void csj(JSONObject jsonObject) { private static void csj(JSONObject jsonObject) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
isRun = true;
File apk = new File(jsonObject.getString("file")); File apk = new File(jsonObject.getString("file"));
RedisTools.set(1, "msg_" + System.currentTimeMillis(), "开始处理:" + apk.getName()); RedisTools.set(1, "msg_" + System.currentTimeMillis(), "开始处理:" + apk.getName());
new CsjTools(jsonObject.getString("file") try {
, new File("csj" + File.separator + "demo.apk").getAbsolutePath() File csc = new File("out" + File.separator + apk.getName().replace(".", "") + File.separator + "csc");
, jsonObject.getString("packagename") csc.mkdirs();
, jsonObject.getString("version") if (csc.exists()) {
, new SmaliApkToolsPath() { csc.delete();
@Override }
public void smaliPath(String s) { System.out.println(">>" + csc.getAbsolutePath());
OSSTools.uploadFile(new File(s), new DownloadInterface() { 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; String path;
@Override @Override
@ -91,25 +90,15 @@ public class BotTools {
RedisTools.set(1, "msg_" + System.currentTimeMillis(), apk.getName() RedisTools.set(1, "msg_" + System.currentTimeMillis(), apk.getName()
+ "已处理完成,下载地址" + + "已处理完成,下载地址" +
"\n" + file + "\n" + file +
"\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() { isRun = false;
@Override
public void run() {
try {
Thread.sleep(10 * 60 * 1000);
OSSTools.delete(path);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
System.gc(); System.gc();
} }
}); });
} } catch (IOException e) {
}); e.printStackTrace();
}
} }
private static class MyThread extends Thread { private static class MyThread extends Thread {
@ -130,7 +119,7 @@ public class BotTools {
if (map.size() > 0) { if (map.size() > 0) {
isRun = true; isRun = true;
for (Long key : map.keySet()) { for (Long key : map.keySet()) {
JSONObject json=map.get(key); JSONObject json = map.get(key);
map.remove(key); map.remove(key);
csj(json); csj(json);

View File

@ -7,9 +7,11 @@ 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 redis.clients.jedis.Jedis;
import java.io.File; import java.io.File;
import java.util.Base64; import java.util.Base64;
import java.util.UUID;
@Controller @Controller
@RequestMapping("/localhome/bot") @RequestMapping("/localhome/bot")
@ -36,7 +38,30 @@ public class QQBot {
public String botMsg(String msg,String type){ public String botMsg(String msg,String type){
System.out.println(type); System.out.println(type);
if(type.trim().equals("download")){ 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~"; return "OK~";
} }
@ -46,7 +71,11 @@ public class QQBot {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { 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(); }).start();
return "ok"; return "ok";