Procházet zdrojové kódy

已完成全部功能

dongguoliang@kuaifazs.com před 4 roky
revize
00f6a2db0d

+ 224 - 0
common/task.js

@@ -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

+ 20 - 0
main.js

@@ -0,0 +1,20 @@
+var Task=require("./common/task.js")
+var VERSION="1.0.7";
+toastLog('version:' + VERSION);
+var task=new Task();
+
+if (!$power_manager.isIgnoringBatteryOptimizations()) {
+    console.log("未开启忽略电池优化");
+    $power_manager.requestIgnoreBatteryOptimizations();
+}
+
+setInterval(function(){
+    task.main();
+},1000*30);
+
+/*
+2*1000*60
+task.getTask();
+task.getDeviceAccount();
+task.checkRunning();
+*/

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 9570 - 0
node_modules/@autojs/types-pro8/index.d.ts


+ 46 - 0
node_modules/@autojs/types-pro8/package.json

@@ -0,0 +1,46 @@
+{
+  "_from": "@autojs/types-pro8",
+  "_id": "@autojs/types-pro8@8.8.0",
+  "_inBundle": false,
+  "_integrity": "sha512-qV5vUUrXI8C1SKGVbMiSA8Bmd/oe8Xpd2Ipz3RqAc0iNaalKOBddYzNMKR1Nn7hDmetrITcvOn3W+i515ydMqg==",
+  "_location": "/@autojs/types-pro8",
+  "_phantomChildren": {},
+  "_requested": {
+    "type": "tag",
+    "registry": true,
+    "raw": "@autojs/types-pro8",
+    "name": "@autojs/types-pro8",
+    "escapedName": "@autojs%2ftypes-pro8",
+    "scope": "@autojs",
+    "rawSpec": "",
+    "saveSpec": null,
+    "fetchSpec": "latest"
+  },
+  "_requiredBy": [
+    "#DEV:/",
+    "#USER"
+  ],
+  "_resolved": "https://registry.npmjs.org/@autojs/types-pro8/-/types-pro8-8.8.0.tgz",
+  "_shasum": "bb488691b4b6b11f9c218e5bb672741487ae7126",
+  "_spec": "@autojs/types-pro8",
+  "_where": "/Volumes/T7/Projects/autojs/autojspro-ext/assets/project-templates/v8-default",
+  "bugs": {
+    "url": "https://github.com/hyb1996/Auto.js/issues"
+  },
+  "bundleDependencies": false,
+  "dependencies": {},
+  "deprecated": false,
+  "description": "TypeScript definitions for Auto.js Pro V8 APIs",
+  "homepage": "https://g.pro.autojs.org/docs",
+  "license": "UNLICENSED",
+  "main": "",
+  "name": "@autojs/types-pro8",
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/hyb1996/Auto.js.git"
+  },
+  "scripts": {},
+  "typeScriptVersion": "3.7",
+  "typings": "index.d.ts",
+  "version": "8.8.0"
+}

+ 15 - 0
package.json

@@ -0,0 +1,15 @@
+{
+  "name": "mobilephone_master",
+  "version": "1.0.4",
+  "description": "",
+  "main": "main.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "keywords": [],
+  "author": "",
+  "license": "ISC",
+  "devDependencies": {
+    "@autojs/types-pro8": "^8.8.0"
+  }
+}

+ 22 - 0
project.json

@@ -0,0 +1,22 @@
+{
+    "assets": [],
+    "encryptLevel": 0,
+    "useFeatures": [],
+    "launchConfig": {
+      "displaySplash": true,
+      "hideLogs": false,
+      "splashText": "master",
+      "stableMode": false
+    },
+    "main": "main.js",
+    "name": "云手机master",
+    "optimization": {
+      "removeOpenCv": false,
+      "unusedResources": false
+    },
+    "packageName": "org.example.master",
+    "scripts": {},
+    "versionCode": 7,
+    "versionName": "1.0.7",
+    "ignore": ["build", "node_modules"]
+  }