|
|
@@ -0,0 +1,224 @@
|
|
|
+// 获取任务
|
|
|
+const server = "http://xjf.lianyou.fun:8095/v1";
|
|
|
+const computer = "hema2";//hema 4005 yunshouji 9991
|
|
|
+const index = 1;
|
|
|
+const game_id = 4008;
|
|
|
+
|
|
|
+const StatusModifyDevice = 2;//獲取賬號
|
|
|
+const StatusGetStartButtonOfSpirit = 6; //获取按键小精灵开始脚本按钮
|
|
|
+const StatusStartSpirit = 7; //开始脚本
|
|
|
+const StatusPushSuperUserFile = 8; //推送root权限文件
|
|
|
+
|
|
|
+var NET_TIMEOUT_START_TIME_MINUTE=0;//统计网络失败的开始时间是第几分钟
|
|
|
+var SIMULATOR_NAME = "";
|
|
|
+var ACCOUNT = "";
|
|
|
+var URL_GET_TASK = util.format("%s/task/get_task?computer_name=%s&game_id=%d", server, computer, game_id);
|
|
|
+var URL_GET_ACCOUNT = util.format("%s/task/get_account?computer_name=%s&game_id=%d", server, computer, game_id);
|
|
|
+var URL_GET_RUN_STATUS = util.format("%s/pc_simulator/get_status?game_id=%d&simulator_name=", server, game_id);
|
|
|
+var URL_SET_RUN_STATUS = util.format("%s/pc_simulator/set_status", server);
|
|
|
+var URL_ADD_SIMULATOR = util.format("%s/pc_simulator/add", server);
|
|
|
+var URL_LOG = util.format("%s/device/setAccountLog?game_id=%d", server, game_id);
|
|
|
+
|
|
|
+function Task() {
|
|
|
+
|
|
|
+ let packageNameSpirit;
|
|
|
+ let deviceAccount;
|
|
|
+ let simulator_name;
|
|
|
+ let urlGetRunningStatus
|
|
|
+ this.main = function () {
|
|
|
+ if (this.checkRunning()) {//正在執行
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.getTask()) {//獲取任務
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.getDeviceAccount()) {//獲取賬號
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.stopPackage(this.packageNameSpirit);
|
|
|
+ this.home();//
|
|
|
+
|
|
|
+ this.addSimulator();
|
|
|
+ this.pushAccount();//推送模擬器名稱到硬盤
|
|
|
+ this.luanchSpirit();//啟動按鍵精靈app
|
|
|
+
|
|
|
+ sleep(1000 * 50)
|
|
|
+ this.startSpirit();//點擊音量小
|
|
|
+ }
|
|
|
+
|
|
|
+ this.getTask = function GetTask() {
|
|
|
+ let task = this.httpGet(URL_GET_TASK);
|
|
|
+ if (!task) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (task.Status == "stop") {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ toastLog(task.Status + task.PackageNameSpirit);
|
|
|
+
|
|
|
+ this.packageNameSpirit = task.PackageNameSpirit;
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ this.getDeviceAccount = function () {
|
|
|
+ let deviceAccount = this.httpGet(URL_GET_ACCOUNT);
|
|
|
+ if (!deviceAccount) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ this.simulator_name = util.format("%s_%d_%d_%s", computer, index, game_id, deviceAccount.account);
|
|
|
+ this.urlGetRunningStatus = URL_GET_RUN_STATUS + this.simulator_name
|
|
|
+ SIMULATOR_NAME = this.simulator_name
|
|
|
+ ACCOUNT = deviceAccount.account
|
|
|
+
|
|
|
+ this.setRunningStatus(StatusModifyDevice);
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ this.checkRunning = function () {
|
|
|
+ this.log("check_running", "");
|
|
|
+ this.urlGetRunningStatus = URL_GET_RUN_STATUS + SIMULATOR_NAME
|
|
|
+ let runStatus = this.httpGet(this.urlGetRunningStatus)
|
|
|
+ if (!runStatus) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (runStatus.Status == "stop") {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (runStatus.Status == "") {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setRunningStatus = function (status) {
|
|
|
+ let url = util.format("%s?status=%d&simulator_name=%s", URL_SET_RUN_STATUS, status, SIMULATOR_NAME);
|
|
|
+ this.httpGet(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.addSimulator = function () {
|
|
|
+ let url = util.format("%s?simulator_name=%s", URL_ADD_SIMULATOR, SIMULATOR_NAME);
|
|
|
+ this.httpGet(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.log = function (action, action_result) {
|
|
|
+ let url = util.format("%s&account=%s&action=%s&action_result=%s", URL_LOG, ACCOUNT, action, action_result);
|
|
|
+ this.httpGet(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.pushAccount = function () {
|
|
|
+ files.write("/sdcard/simulator_uuid.txt", this.simulator_name);
|
|
|
+ this.setRunningStatus(StatusPushSuperUserFile);
|
|
|
+ this.log("push_account", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.luanchSpirit = function () {
|
|
|
+ app.launchPackage(this.packageNameSpirit)
|
|
|
+ this.setRunningStatus(StatusGetStartButtonOfSpirit);
|
|
|
+ this.log("spirit_launch", "");
|
|
|
+ }
|
|
|
+ this.startSpirit = function () {
|
|
|
+ // shell("input keyevent KEYCODE_VOLUME_DOWN", true);
|
|
|
+ this.tap(349, 1214);//启动 349,1214
|
|
|
+ sleep(3000)
|
|
|
+ this.tap(712, 399);//旁边 712,399
|
|
|
+ sleep(1000)
|
|
|
+ this.tap(273, 405);//伸出来 273,405
|
|
|
+ this.setRunningStatus(StatusStartSpirit);
|
|
|
+ this.log("spirit_start", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.tap = function (x, y) {
|
|
|
+ let cmd = util.format("input tap %d %d", x, y);
|
|
|
+ shell(cmd, true);
|
|
|
+ }
|
|
|
+ this.stopPackage = function (package) {
|
|
|
+ let cmd = util.format("am force-stop %s", package);
|
|
|
+ shell(cmd, true);
|
|
|
+ this.log("spirit_stop", "");
|
|
|
+ }
|
|
|
+ this.home = function () {
|
|
|
+ shell("input keyevent KEYCODE_HOME", true);
|
|
|
+ this.log("home", "");
|
|
|
+ }
|
|
|
+ this.changeDevice = function () {
|
|
|
+ this.exec()
|
|
|
+ sleep(10000)
|
|
|
+ }
|
|
|
+ this.changeIP = function () {
|
|
|
+ this.exec()
|
|
|
+ sleep(10000)
|
|
|
+ }
|
|
|
+ /*-------公共使用函数--------*/
|
|
|
+ this.httpGet = function (url) {
|
|
|
+ console.info(url);
|
|
|
+ let obj;//
|
|
|
+ let res;
|
|
|
+
|
|
|
+ try{
|
|
|
+ res = http.get(url);
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ if (this.checkIfChangeVPN()){
|
|
|
+ console.info("要切换VPN");
|
|
|
+ this.changeVPN();
|
|
|
+ NET_TIMEOUT_START_TIME_MINUTE=0;
|
|
|
+ }else{
|
|
|
+ console.info("还不需要切换VPN");
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ NET_TIMEOUT_START_TIME_MINUTE=0;
|
|
|
+ try {
|
|
|
+ if (res.statusCode != 200) {
|
|
|
+ toast("请求失败: " + res.statusCode + " " + res.statusMessage);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ obj = res.body.json();
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(obj);
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+ this.checkIfChangeVPN=function(){
|
|
|
+ let minute=new Date().getMinutes();
|
|
|
+ console.info("检测是否切换VPN");
|
|
|
+ console.info(minute);
|
|
|
+ console.info(NET_TIMEOUT_START_TIME_MINUTE);
|
|
|
+
|
|
|
+ if (NET_TIMEOUT_START_TIME_MINUTE==0){
|
|
|
+ NET_TIMEOUT_START_TIME_MINUTE=minute
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (minute-NET_TIMEOUT_START_TIME_MINUTE<4){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.changeVPN=function(){
|
|
|
+ shell("ipclient 2a521e4f7bf54ffb9dad5368c48dd783 0", true);
|
|
|
+ console.info("关闭VPN");
|
|
|
+ sleep(3000);
|
|
|
+
|
|
|
+ shell("ipclient 2a521e4f7bf54ffb9dad5368c48dd783 1", true);
|
|
|
+ console.info("切换VPN");
|
|
|
+ sleep(2000);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.exec = function (cmd) {
|
|
|
+ var result = shell(cmd, true);
|
|
|
+ log(result);
|
|
|
+ console.show();
|
|
|
+ if (result.code == 0) {
|
|
|
+ toast("执行成功");
|
|
|
+ } else {
|
|
|
+ toast("执行失败!请到控制台查看错误信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+module.exports = Task
|