7 Star 27 Fork 14

易玩脚本/易玩脚本

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

基于Autojs的免Root安卓脚本开发实战

一、各个脚本平台对比

1、常见的脚本平台

1.1.按键精灵 优点 :主要是图色功能 缺点:安卓机需要Root权限,ios+安卓,不能全分辨率--Lua

1.2.触动精灵 优点:主要在ios上面比较出色--ios需要越狱 安卓不如按键--Lua

1.3.基于节点开发的平台

1.3.1 Autojs --基于无障碍 适用安卓系统7.0-10 5.0-6.0不完全支持,打包即用,需要无障碍权限

1.3.2 jsdroid--支持5.0-9.0 对root的机型比较友好,缺点:目前功能还不如Autojs丰富 手机没有Root则需要激活--grovvy

1.3.3节点精灵--支持安卓7.0-9.0 基于无障碍及Lua语言,适合开发免root 游戏脚本

2、技术交流、分享、解答
Author: QQ:486675857 脚本交流群:1009722787

二、教程目录

<img alt="脚本">

三、正式课程

1.准备工作
1.1.Git ----代码 ---https://blog.csdn.net/qq_39387475/article/details/84996173
1.2.码云 --https://gitee.com/
1.3.脚本开发工具下载 ---https://code.visualstudio.com/ -vscode
1.4.代码地址:https://gitee.com/easyscript/EasyCriptsDemo.git
2、开发环境

VsCode --- 步骤: 打开Vscode carl +shirt +x 安装antojs扩展

Autojs手机端 4.1.0版本 AutojsPro 7.4.1

安装好autojs扩展后 启动服务

按 Ctrl+Shift+P 或点击"查看"->"命令面板"可调出命令面板,输入 Auto.js 可以看到几个命令:

Start Server: 启动插件服务。之后在确保手机和电脑在同一区域网的情况下,在Auto.js的侧拉菜单中使用连接电脑功能连接。
Stop Server: 停止插件服务。
Run 运行当前编辑器的脚本。如果有多个设备连接,则在所有设备运行。
Rerun 停止当前文件对应的脚本并重新运行。如果有多个设备连接,则在所有设备重新运行。
Stop 停止当前文件对应的脚本。如果有多个设备连接,则在所有设备停止。
StopAll 停止所有正在运行的脚本。如果有多个设备连接,则在所有设备运行所有脚本。
Save 保存当前文件到手机的脚本默认目录(文件名会加上前缀remote)。如果有多个设备连接,则在所有设备保存。
RunOnDevice: 弹出设备菜单并在指定设备运行脚本。
SaveToDevice: 弹出设备菜单并在指定设备保存脚本。
New Project(新建项目):选择一个空文件夹(或者在文件管理器中新建一个空文件夹),将会自动创建一个项目
Run Project(运行项目):运行一个项目,需要Auto.js 4.0.4Alpha5以上支持
Save Project(保存项目):保存一个项目,需要Auto.js 4.0.4Alpha5以上支持
以上命令一些有对应的快捷键,参照命令后面的说明即可。

Autojs安装好后 打开无障碍权限 输入ip连接服务器

查看本机ip cmd --> ipconfig IPv4 地址 . . . . . . . . . . . . : 192.168.1.108

正式开发

开发文档----https://hyb1996.github.io/AutoJs-Docs/#/

一、js基础
Autojs三种输出方式: 1.log() ,console.log(),toastLog
log(i)
console.log(字符串)
toastLog(字符串) //相当于 log(字符串) + toast(字符串)

/*log(字符串)
toast(字符串)
toastLog(字符串)
1.1 js变量定义
 var i=0;  //定义一个Number
 var 字符串=""; //字符串
 var 数组=[]; //定义数组
 var 对象={}; //定义对象
 var flaf=true; //定义一个布尔型的变量
1.2js常见的字符串函数操作~
//字符串的分割  字符串.split("以什么分割")  返回类型为数组
var 数据="123456789---qwe123"
var 分割后=数据.split("---");
console.log("账号:"+分割后[0]+"密码:"+分割后[1])
//字符串的截取 字符串.substring(起始下标,终止下标)  返回类型为字符串
var 字符串="hello AutoJs";
log("截取前:"+字符串)
var 字符串=字符串.substring(0,7)
log("截取后"+字符串)
//字符串的包含  字符串.indexOf("包含的字符串")  返回-1||0  -1代表不包含 0代表包含
var 字符串="hello AutoJs";

log(字符串.indexOf("hello"))//输出0

//字符串的替换 replace(str1,str2) 返回值 字符串类型
var 字符串="hello AutoJs";
var 替换后=字符串.replace("hello","你好")
console.log(替换后)
1.3 数组及对象
一、数组操作
//1.添加 数组.push("要添加的内容")
var 数组 = []; //定义数组  
数组.push(1)
数组.push(2)
数组.push("3")
log(数组)
//数组遍历
数组.forEach(item=>{
    log(item)
})
//循环输出
for(var i=0;i<数组.length;i++){
     log(数组[i])
}
//其他的参照博客:https://www.jianshu.com/p/22a4c0b514fa
二、对象操作
var 对象 = {}; //定义对象
var flaf = true; //定义一个布尔型的变

//Js数组操作 1.数组添加  遍历 删除  过滤  排序

var 对象数组=[];

//案例 各种手机信息的集合

for(var i=0;i<10;i++){
    var phone={};//定义一个手机  属性有: 品牌 价格 颜色  操作系统
    phone.pinpai="小米"+i;
    phone.price="3000"
    phone.color="blue";
    phone.os="android 1"+i
    对象数组.push(phone)
}
log(对象数组)
1.4常用Js流程控制
//流程控制 while for swith if
//1.for循环
for (var i = 0; i < 10; i++) {
    if (i > 5) {
        console.log(i)
        break;//跳出循环
    } else if (i % 3 == 0) {
        console.log(i)
    }
}
//while
var i = 0;
while (true) {
    i = i + 1;
    if (i > 5) {
        console.log(i)
        break;//跳出循环
    }
}
//swith
var i = 1;
switch (i) {
    case "0":
        console.log("0")
        break;
    case 1:
        console.log("1")
        break;
}

1.5常用Js函数定义、传值等

//函数的定义与调用
hello()
function hello(){
    toastLog("你好")
}
//函数传值的类型 可以为number string array obj 

//1.传数字
传值函数(1,"2")
function 传值函数(a,b){
    var b=parseInt(b)//将字符类型的变量转数字
    log(a+b)
}

//传字符
传值函数1("hello","Autojs")
function 传值函数1(a,b){
 //   var b=parseInt(b)//将字符类型的变量转数字
    log(a+"--"+b)
}
//传数组
arrSort([1,2,3])
function arrSort(array){
  array.forEach(element => {
      console.log(element)
  });  
}
//传对象
var obj={};
obj.title="传对象";
objTest(obj)
function objTest(data){
   console.log(data.title)
}
二、常用设备函数
console.log(device)
/*
Device{width=720, height=1280, buildId='LMY47I', buildDisplay='LMY47I', product='sm-g531h', board='sm-g531h', brand='samsung', device='aosp', model='sm-g531h', bootloader='unknown', hardware='android_x86', fingerprint='asus/android_x86/x86:5.1.1/LMY47I/8.3.19:user/release-keys', sdkInt=22, incremental='8.3.19', release='5.1.1', baseOS='null', securityPatch='null', serial='00dc3b3c'}
*/
console.log(device.getIMEI())//返回设备的IMEI.
console.log(device.getAndroidId())//返回设备的Android ID。
//一直保持屏幕常亮
device.keepScreenOn()
三、节点操作

​ UiSelector即选择器,用于通过各种条件选取屏幕上的控件,再对这些控件进行点击、长按等动作。这里需要先简单介绍一下控件和界面的相关知识。

一般软件的界面是由一个个控件构成的,例如图片部分是一个图片控件(ImageView),文字部分是一个文字控件(TextView);同时,通过各种布局来决定各个控件的位置,例如,线性布局(LinearLayout)里面的控件都是按水平或垂直一次叠放的,列表布局(AbsListView)则是以列表的形式显示控件。

控件有各种属性,包括文本(text), 描述(desc), 类名(className), id等等。我们通常用一个控件的属性来找到这个控件,例如,想要点击QQ聊天窗口的"发送"按钮,我们就可以通过他的文本属性为"发送"来找到这个控件并点击他,具体代

 com.stardust.automator.UiObject@800bdcff; boundsInParent: Rect(0, 0 - 288, 36); boundsInScreen: Rect(360, 1149 - 648, 1185); packageName: org.autojs.autojs; className: android.widget.TextView; text: 用户名:; contentDescription: null; viewId: org.autojs.autojs:id/value; checkable: false; checked: false; focusable: false; focused: false; selected: false; clickable: false; longClickable: false; enabled: true; password: false; scrollable: false; [ACTION_SELECT, ACTION_CLEAR_SELECTION, ACTION_ACCESSIBILITY_FOCUS, ACTION_NEXT_AT_MOVEMENT_GRANULARITY, ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, ACTION_SET_SELECTION]
1.常用组合查找控件
//控件组合查找 className + text +id +desc / //id("button4").findOne() //findOnce
var btn=className("Button").text("登录").id("button4").findOne()
if(btn){
log(btn)
}
/*控件三种点击方法
1.直接点击坐标  click(130,700)
2.通过控件属性: 要求 clickable:true
3.通过控件的bounds()取控件的范围 再取中间值
*/
var btn=className("Button").text("登录").id("button4").findOne()
if(btn){
 var point=btn.bounds();
 console.log(point)
 console.log(point.centerX(),point.centerY())
// click(point.centerX(),point.centerY()) 用在控件的clickable属性为false 但是可以点击
}
//输入框控件
var et = className("EditText").id("user_edit").findOne();
if(et){
  et.setText("486675857")
}
*/
var check=className("checkBox").id("checkBox").findOne()
if(check){
  console.log(check.checked())
}

var check=className("Switch").id("switch1").findOne()
if(check){
  console.log(check.checked())
}
2.案例模拟账号密码登入
输入用户名()
function 输入用户名() {
    var user = className("EditText").id("user_edit").findOne()
    if (user) {
        console.log("开始输入")
        user.setText("486675857");
        sleep(1000)
        输入密码()
    } else {
           
    }
}
function 输入密码() {
    var pwd = className("EditText").id("pw_edit").findOne()
    if (pwd) {
        console.log("开始输入密码")
        pwd.setText("123456");
        sleep(1000)
        选中性别()
    }
}
function 选中性别() {
    var check = classNameEndsWith("CheckBox").id("checkBox").findOne()
    if (check) {
        console.log("选中性别")
        check.click()
        sleep(1000)
        记住密码()
    }
}
function 记住密码() {
    var check = className("Switch").id("switch1").findOne()
    if (check) {
        console.log(" 记住密码")
        check.click()
        sleep(1000)
        登录()
    }
}
function 登录() {
    var btn = textContains("登").findOne()
    if (btn) {
        console.log(" deng")
        btn.click()
    }
}
四、图色篇
 //请求横屏截图
if(!requestScreenCapture()){
    toast("请求截图失败");
    exit();
}
//连续截图10张图片(间隔1秒)并保存到存储卡目录
captureScreen("/sdcard/index.png");
var img= images.read("/sdcard/index.png")

var clip = images.clip(img, 100, 100, 400, 400);
images.save(clip, "/sdcard/clip.png");
五、文件操作
1、文件读取操作
//创建一个文件
var path = "/sdcard/1.txt";
log(files.exists(path))//判断文件是否存在
if (!files.exists(path)) {
    console.log("文件不存在,开始创建")
    files.create(path);
} else {
    console.log("文件存在")
}

writeLine(path, "123456582", 2)

function readLine(path, line) {
    if (!files.exists(path)) {
        console.log(path)
        return "";
    }
    var file = files.open(path, mode = "r", encoding = "utf-8")
    var fileList = file.readlines();//获取文件数组
    //console.log(fileList)
    if (fileList.length < line) {
        log("超出了~")
        file.close();
        return "";
    }
    line = line - 1;
    file.close();
    return fileList[line]
}
function writeLine(path, text, line) {
    if (!files.exists(path)) {
        console.log(path)
        return "";
    }
    var file = files.open(path, mode = "r", encoding = "utf-8")
    var newArr = [];
    var fileList = file.readlines();//获取文件数组
    console.log(fileList)
    file.close;

    var wfile = files.open(path, mode = "w", encoding = "utf-8")
    if (fileList.length == 0) {
        wfile.writeline(text)
        wfile.close()
        return;
    }
    if (fileList.length >= line) {
        for (var i = 0; i < fileList.length; i++) {
            var str = "";
            if ((line - 1) == i) {
                str = text;
            } else {
                str = fileList[i]
            }
            newArr.push(str)
        }
        wfile.writelines(newArr)
        wfile.close()
    } else {
        for (var j = 0; j < fileList.length; j++) {
            newArr.push(fileList[j])
        }
        newArr.push(text)
        wfile.writelines(newArr)
        wfile.close()
    }

}

var file = files.open(path, mode = "r", encoding = "utf-8")
var fileList = file.readlines();//获取文件数组
console.log(fileList )
file.close()//创建一个文件
var path = "/sdcard/1.txt";
log(files.exists(path))//判断文件是否存在
if (!files.exists(path)) {
    console.log("文件不存在,开始创建")
    files.create(path);
} else {
    console.log("文件存在")
}

writeLine(path, "123456582", 2)

function readLine(path, line) {
    if (!files.exists(path)) {
        console.log(path)
        return "";
    }
    var file = files.open(path, mode = "r", encoding = "utf-8")
    var fileList = file.readlines();//获取文件数组
    //console.log(fileList)
    if (fileList.length < line) {
        log("超出了~")
        file.close();
        return "";
    }
    line = line - 1;
    file.close();
    return fileList[line]
}
function writeLine(path, text, line) {
    if (!files.exists(path)) {
        console.log(path)
        return "";
    }
    var file = files.open(path, mode = "r", encoding = "utf-8")
    var newArr = [];
    var fileList = file.readlines();//获取文件数组
    console.log(fileList)
    file.close;

    var wfile = files.open(path, mode = "w", encoding = "utf-8")
    if (fileList.length == 0) {
        wfile.writeline(text)
        wfile.close()
        return;
    }
    if (fileList.length >= line) {
        for (var i = 0; i < fileList.length; i++) {
            var str = "";
            if ((line - 1) == i) {
                str = text;
            } else {
                str = fileList[i]
            }
            newArr.push(str)
        }
        wfile.writelines(newArr)
        wfile.close()
    } else {
        for (var j = 0; j < fileList.length; j++) {
            newArr.push(fileList[j])
        }
        newArr.push(text)
        wfile.writelines(newArr)
        wfile.close()
    }

}

var file = files.open(path, mode = "r", encoding = "utf-8")
var fileList = file.readlines();//获取文件数组
console.log(fileList )
file.close()//按行读取
function readLine(path, line) {
    if (!files.exists(path)) {
        console.log(path)
        return "";
    }
    var file = files.open(path, mode = "r", encoding = "utf-8")
    var fileList = file.readlines();//获取文件数组
    if (fileList.length < line) {
        log("超出了~")
        file.close();
        return "";
    }
    line = line - 1;
    file.close();
    return fileList[line]
}
2、文件写入操作
传入参数path, text, line
function writeLine(path, text, line) {
    if (!files.exists(path)) {
        console.log(path)
        return "";
    }
    var file = files.open(path, mode = "r", encoding = "utf-8")
    var newArr = [];
    var fileList = file.readlines();//获取文件数组
    console.log(fileList)
    file.close;

    var wfile = files.open(path, mode = "w", encoding = "utf-8")
    if (fileList.length == 0) {
        wfile.writeline(text)
        wfile.close()
        return;
    }
    if (fileList.length >= line) {
        for (var i = 0; i < fileList.length; i++) {
            var str = "";
            if ((line - 1) == i) {
                str = text;
            } else {
                str = fileList[i]
            }
            newArr.push(str)
        }
        wfile.writelines(newArr)
        wfile.close()
    } else {
        for (var j = 0; j < fileList.length; j++) {
            newArr.push(fileList[j])
        }
        newArr.push(text)
        wfile.writelines(newArr)
        wfile.close()
    }
}
3、文件遍历
//遍历sd中所有的文件夹
var dirArr = [], fileArr = [];
//遍历sd中所有的文件夹
function getDirs(path) {
    var arr = files.listDir(path);
    arr.forEach(item => {
        var dir1 = path + item;
        if (files.isDir(dir1)) {
            dirArr.push(dir1 + "/")
            return getFiles(dir1 + "/")
        }
    });
}
//遍历sd卡中的所有文件
function getFiles(path) {
    //  files.isFile(path)
    var arr = files.listDir(path);
    arr.forEach(item => {
        var dir1 = path + item;
        if (files.isFile(dir1)) {
             fileArr.push(dir1)
        }
        if (files.isDir(dir1)) {
            // dirArr.push(dir1 + "/")
            return getFiles(dir1 + "/")
        }
    })
    console.log(fileArr)
}
六、ui设计
1.常用布局
"ui";
ui.layout(
    <vertical>
        <horizontal>
            <text text="手机号:" />
            <input hint="请输入手机号" w="*" id="phone" inputType="number|phone" />
        </horizontal>
        <horizontal>
            <text text="密码:" />
            <input hint="请输入密码" w="*" id="pwd" />
        </horizontal>
        <button id="btn" text="登入" />
    </vertical>
);

//按钮绑定点击事件 ui.按钮的id.click(函数)
//获取输入框的值: ui.name.getText();
ui.btn.click(function () {
    //通过getText()获取输入的内容
    // var name = ui.name.getText();
    // toast(name + "您好!");
    var phone = ui.phone.getText();
    var pwd=ui.pwd.getText()
    toastLog(phone + "---"+pwd);
});
2.案例--模拟登入
"ui";
var storage = storages.create("data");
var phone="",pwd="";
ui.layout(
    <vertical>
        <horizontal>
            <text text="手机号:" />
            <input hint="请输入手机号" w="*" id="phone" inputType="number|phone" />
        </horizontal>
        <horizontal>
            <text text="密码:" />
            <input hint="请输入密码" w="*" id="pwd" />
        </horizontal>
        <button id="btn" text="登入" />
    </vertical>
);
getData()
//按钮绑定点击事件 ui.按钮的id.click(函数)
//获取输入框的值: ui.name.getText();
ui.btn.click(function () {
    //通过getText()获取输入的内容
    // var name = ui.name.getText();
    // toast(name + "您好!");
    threads.start(function () {
        phone = ui.phone.getText().toString();
        pwd = ui.pwd.getText().toString()
        /// toastLog(phone + "---"+pwd);
        if (phone != "" && pwd != "") {
            //console.log(typeof phone)
            storage.put("user", phone + "")
            storage.put("pwd", pwd + "")
            app.launch("com.example.myapplication1")
            setTimeout(function () {

                输入用户名()
            }, 2000)
        } else {
            toastLog("请输入用户名或密码");
        }
    })
});
function getData() {
    // var storage = storages.create("data");
    if (storage.contains("user")) {
        //  console.log("用户名:"+storage.get("user"))
        ui.phone.setText(storage.get("user"))
    }
    if (storage.contains("pwd")) {
        console.log("密码:" + storage.get("pwd"))
        ui.pwd.setText(storage.get("pwd"))
    }
}

function 输入用户名() {
    var user = className("EditText").id("user_edit").findOne()
    if (user) {
        console.log("开始输入")
        user.setText(phone);
        sleep(1000)
        输入密码()
    } else {

    }
}
function 输入密码() {
    var pwd = className("EditText").id("pw_edit").findOne()
    if (pwd) {
        console.log("开始输入密码")
        pwd.setText(pwd);
        sleep(1000)
        选中性别()
    }
}
function 选中性别() {
    var check = classNameEndsWith("CheckBox").id("checkBox").findOne()
    if (check) {
        console.log("选中性别")
        check.click()
        sleep(1000)
        记住密码()
    }
}
function 记住密码() {
    var check = className("Switch").id("switch1").findOne()
    if (check) {
        console.log(" 记住密码")
        check.click()
        sleep(1000)
        登录()
    }
}
function 登录() {
    var btn = textContains("登").findOne()
    if (btn) {
        console.log(" deng")
        btn.click()
    }
}
3、ui保存与回显
创建一个本地存储并返回一个Storage对象。不同名称的本地存储的数据是隔开的,而相同名称的本地存储的数据是共享的。
"ui";
var storage = storages.create("data");
ui.layout(
    <vertical>
        <horizontal>
            <text text="手机号:" />
            <input hint="请输入手机号" w="*" id="phone" inputType="number|phone" />
        </horizontal>
        <horizontal>
            <text text="密码:" />
            <input hint="请输入密码" w="*" id="pwd" />
        </horizontal>
        <button id="btn" text="登入" />
    </vertical>
);
getData()
//按钮绑定点击事件 ui.按钮的id.click(函数)
//获取输入框的值: ui.name.getText();
ui.btn.click(function () {
    //通过getText()获取输入的内容
    // var name = ui.name.getText();
    // toast(name + "您好!");
    threads.start(function () {
        var phone = ui.phone.getText().toString();
        var pwd = ui.pwd.getText().toString()
        /// toastLog(phone + "---"+pwd);
        if (phone != "" && pwd != "") {
            //console.log(typeof phone)
            storage.put("user", phone + "")
            storage.put("pwd", pwd + "")

        } else {
            toastLog("请输入用户名或密码");
        }
    })
});
function getData() {
    // var storage = storages.create("data");
    if (storage.contains("user")) {
        //  console.log("用户名:"+storage.get("user"))
        ui.phone.setText(storage.get("user"))
    }
    if (storage.contains("pwd")) {
        console.log("密码:" + storage.get("pwd"))
        ui.pwd.setText(storage.get("pwd"))
    }
}
七、Http模块
1.get请求
//养号免费图文接口:https://api.apiopen.top/getJoke?page=2&count=50&type=image
console.show();
var r = http.get("www.baidu.com", {
    headers: {
        'Accept-Language': 'zh-cn,zh;q=0.5',
        'User-Agent': 'Mozilla/5.0(Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11'
    }
});
log("code = " + r.statusCode);
log("html = " + r.body.string());
2.post请求
var url = "https://login.taobao.com/member/login.jhtml";
var username = "你的用户名";
var password = "你的密码";
var res = http.post(url, {
    "TPL_username": username,
    "TPL_password": password
});
var html = res.body.string();
if(html.contains("页面跳转中")){
    toast("登录成功");
}else{
    toast("登录失败");
}
3.Http实战联众打码平台
联众官网:https://www.jsdati.com/docs/price
客户QQ:2181362470  6.5折
//请求横屏截图
if (!requestScreenCapture()) {
    toast("请求截图失败");
    exit();
}
//连续截图10张图片(间隔1秒)并保存到存储卡目录
captureScreen("/sdcard/index.png");
var img = images.read("/sdcard/index.png")

var clip = images.clip(img, 412, 623, 160, 80);
//images.save(clip, "/sdcard/clip.png");
/**
 * 联众图像识别函数
 * @param {string} username 联众图像识别账号 
 * @param {string} password 联众图像识别密码
 * @param {object} img 识别图片
 */

var data=getCode("qq2826334538", "", clip);
console.log("验证码为:"+data.data.res)

function getCode(username, password, img) {
    http.__okhttp__.setTimeout(3e4);
    var r = images.toBase64(img, format = "png"), i = device.release, c = device.model, s = device.buildId;
    try {
        var n = http.postJson("https://v2-api.jsdama.com/upload", {
            softwareId: 13401,
            softwareSecret: "oiBRMSZhHZnL0sJMO8tnWo07LPMXYEP9OpKOdRbz",
            username: username,
            password: password,
            captchaData: r,
            captchaType: 1001,
            captchaMinLength: 4,
            captchaMaxLength: 4,
            workerTipsId: 0
        }, {
            headers: {
                "User-Agent": "Mozilla/5.0 (Linux; Android " + i + "; " + c + " Build/" + s + "; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 Mobile Safari/537.36",
            }
        });
    } catch (e) {
        return {
            code: "-1",
            msg: "网络链接超时...",
            data: {}
        };
    }
    var d = n.body.json(), p = d.code, m = d.message;
    if ("10079009" == p) return {
        code: p,
        msg: m,
        data: {}
    };
    if ("10142006" == p) return {
        code: p,
        msg: m,
        data: {}
    };
    if ("10142004" == p) return {
        code: p,
        msg: m,
        data: {}
    };
    if ("10142005" == p) return {
        code: p,
        msg: m,
        data: {}
    };
    if ("10079006" == p) return {
        code: p,
        msg: m,
        data: {}
    };
    if ("0" == p) {
        return {
            code: p,
            msg: m,
            data: {
                res: d.data.recognition
            }
        };
    }
    return d;
}
4、JSON操作
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一个子集。
格式:
{
	"name": "John Doe",
	"age": 18,
	"address": {
		"country": "china",
		"zip-code": "10000"
	}
}
//JSON操作

var obj = {};
obj.name = "json";
obj.text = "json操作";

console.log(obj['name'])

var jsonString = JSON.stringify(obj); //将对象转json
var jsonData = JSON.parse(jsonString);//将json转json对象

//json取值
console.log(jsonData.name)
console.log(jsonData['name'])


var res = http.get("https://api.apiopen.top/getJoke?page=1&count=1&type=image")
var data = res.body.json();

console.log(data['code'])

console.log(data['message'])

//取里面的数组

var arr=data['result'];

arr.forEach(item => {
    console.log(item.text)
    console.log(item.images)
});
八、多线程操作

应用场景: 心跳检测、软件的弹窗处理等

1.多线程简单例子
var thread =threads.start(function () {
    //在新线程执行的代码
    while (true) {
        log("我是子线程");
        sleep(3000)
    }
});
for (var i = 0; i < 10; i++) {
    log("脚本主线程");
    sleep(1000)
}
thread.interrupt() //停止当前线程

var thread = threads.start(function () {
    //在新线程执行的代码
    while (true) {
        log("我是心跳线程");
        sleep(3000)
    }
});

var thread1 = threads.start(function () {
    //在新线程执行的代码
    while (true) {
        log("我是弹窗检测线程");
        sleep(3000)
    }
});
for (var i = 0; i < 20; i++) {
    log("脚本主线程");
    if (i == 10) {
        thread.interrupt();
       
    }
    sleep(1000)
}

threads.shutDownAll()
console.log(thread.isAlive())

setInterval(() => { }, 1000);//保持脚本一直运行

线程排队
var sum = 0;
//启动子线程计算1加到10000
var thread = threads.start(function () {
    for (var i = 0; i < 3; i++) {
        sum += i;
        sleep(1000)
    }
});
//等待该线程完成
thread.join();
toastLog("sum = " + sum);

九、脚本引擎(脚本启动脚本)

1.脚本引擎介绍
获取脚本所在目录:toastLog(engines.myEngine().cwd());
engines.execScript("hello world", "toast('hello world')", {
    loopTimes: 10,
    interval: 3000
});

//脚本引擎重点  用途:将UI页面与脚本操作分开
engines.execScriptFile(path[, config])

toastLog(engines.myEngine().cwd());


var path = engines.myEngine().cwd() + "/yq.js";

if (!files.exists(path)) {
    files.create(path)
}

var js = "for(var i=0;i<20;i++){sleep(1000);toastLog('脚本引擎测试'+i)}"

files.write(path, js)


var yq=engines.execScriptFile(path);
sleep(1000)
yq.getEngine().forceStop()//停止启动的脚本
//脚本引擎传值
2.脚本引擎之传值操作(两种方式)
1.通过事件
//监听say事件
events.on("say", function(words){
    toastLog(words);
});
//保持脚本运行
setInterval(()=>{}, 1000);

//发送端
//运行脚本
var e = engines.execScriptFile("./receiver.js");
//等待脚本启动
sleep(2000);
//向该脚本发送事件
e.getEngine().emit("say", "你好");


//1.通过脚本引擎传值:

var js = "events.on('say', function(words){toastLog('子脚本:'+words);});setInterval(()=>{}, 1000); "

files.write(path, js)

var yq=engines.execScriptFile(path);
sleep(2000)
yq.getEngine().emit("say", "你好");

//2.通过脚本广播传值:

var js = "events.broadcast.on('say', function(words){toastLog('子脚本:'+words);});setInterval(()=>{}, 1000); "

files.write(path, js)

var yq=engines.execScriptFile(path);
sleep(2000)
events.broadcast.emit("say", "你好");

//脚本通信传值:传obj对象
var js = "events.broadcast.on('say', function(words){toastLog('子脚本:'+JSON.parse(words).msg);});setInterval(()=>{}, 1000); "

files.write(path, js)
var data={};
data.code=200;
data.msg="succse";
var yq=engines.execScriptFile(path);
sleep(2000)
events.broadcast.emit("say", JSON.stringify(data));
九、基于Autojs的爬虫
1.使用Jsoup

文档:https://www.ibm.com/developerworks/cn/java/j-lo-jsouphtml/

// 从 URL 直接加载 HTML 文档
 Document doc = Jsoup.connect("http://www.oschina.net/").get(); 
 String title = doc.title(); 

 Document doc = Jsoup.connect("http://www.oschina.net/") 
  .data("query", "Java")   // 请求参数
  .userAgent("I ’ m jsoup") // 设置 User-Agent 
  .cookie("auth", "token") // 设置 cookie 
  .timeout(3000)           // 设置连接超时时间
  .post();                 // 使用 POST 方法访问 URL 
//java例子https://www.jianshu.com/p/69b395bee43a

/*
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
*/

runtime.loadJar("/sdcard/jsoup.jar");//加载jar包
importClass(org.jsoup.Jsoup)
importClass(org.jsoup.nodes.Document)
importClass(org.jsoup.nodes.Element)
importClass( org.jsoup.select.Elements)

//实战爬取百思不得姐
var doc = Jsoup.connect("http://www.budejie.com/hot/").userAgent("Mozilla/5.0 (Windows NT 7.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0").get();
var elements = doc.select(".j-r-list>ul>li")
var arr = []
var list = elements.toArray();
//console.log(list.length)
list.forEach(element => {
    var user = element.select(".j-list-user>.u-img>a>img");
    var avator = user.attr("src");//取头像
    var nick = user.attr("alt");
    var content = element.select(".j-r-list-c>.j-r-list-c-img>a>img")
    var img = content.attr("src")
    var title = content.attr("title");
    var dz = {};
    dz.avator = avator
    dz.nick = nick;
    dz.img = img;
    if (img != "") {
        var res = http.get(img);
        files.writeBytes("/sdcard/"+nick+".gif",res.body.bytes())
    }

    dz.title = title;
    arr.push(dz)
})
console.log(arr)
十、Autojs协议篇---攒攒后台任务
使用mitmproxy进行移动端的HTTP抓包https://www.jianshu.com/p/4d146c56294c

fillder

1.登入接口:http://zcore.zqzan.com/app/account/raw/login


空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/easyscript/EasyCriptsDemo.git
git@gitee.com:easyscript/EasyCriptsDemo.git
easyscript
EasyCriptsDemo
易玩脚本
master

搜索帮助