其他分享
首页 > 其他分享> > 基于OppoR9sk的58本地转今日头疼新闻的代码

基于OppoR9sk的58本地转今日头疼新闻的代码

作者:互联网

基于OppoR9sk的58本地转今日头疼新闻的代码

关键点

1、首先要定位是本地的城市,我在大连所以就是大连

2、今日头疼很多地方是三无的所以只能点击坐标

3、每次转载只能重新开始要不然容易宕掉,所以使用了stopapp的方法

auto.waitFor();//判断和等待开启无障碍
let cityName = "大连"
let executeCount = 50
for (let i = 0; i < executeCount; i++) {
    toastLog("58同城本地版第"+i+"次转载正在执行...")
    stopApp("抖音");
    stopApp("今日头条极速版");
    launchApp("今日头条极速版");
    cutDownBySleep(8)//启动App时候等待时间
    adolescentWindows();//关闭青少年窗口
    let areaBounds = bounds(219, 96, 291, 168) //R9SK特殊的地方点击搜索
    if (areaBounds.exists()) {
        clickControlBounds(areaBounds);
    }
    input(cityName)
    setText(cityName)
    clickControlBounds(text("搜索"));
    sleepRandom1()
    clickControlBounds(text("资讯"));
    sleepRandom1()
    
    if (i % 15 != 0 && i<15) {
        silderScreen(i) //正常滑动屏幕次数
        toastInfo("点第一个")
        click(device.width*0.5,device.height*0.2)
    }else if (i % 15 != 0 && i>15 && i<30)  {
        silderScreen(i-15) //滑动屏幕
        toastInfo("点第二个")
        click(device.width*0.5,device.height*0.51)
    }else if(i % 15 != 0 && i>30){
        silderScreen(i-15*2) //滑动屏幕
        toastInfo("点第三个")
        click(device.width*0.5,device.height*0.9)

    }else{
        if(i==0)
            click(device.width*0.5,device.height*0.2)
        if(i==15)
            click(device.width*0.5,device.height*0.5)
        if(i==30)
            click(device.width*0.5,device.height*0.9)
    }
    sleepRandom1()
    sleepRandom0() //保障一下
    let shareButton = bounds(969, 84, 1041, 156) //R9SK特殊的地方点击分享按钮
    if (shareButton.exists()) {
        shareButton.clickable().click()
        swipe(780, 1169, 119, 1169, 300); //特殊的地方右滑
        if (text("复制链接").exists()) {
            if (clickControlBounds(text("复制链接"))) {
                toastLog("剪贴板内容为:" + getClip());
                try {
                stopApp("58本地版")
                launchApp("58本地版")
                cutDownBySleep(12)//启动App时候等待时间
                closeSplashAD()
                clickControlBounds(text("我的"))
                sleepRandom1()
                let reprintButton=text("去转载").findOnce();
                if(reprintButton!=null){
                    clickBounds(reprintButton.bounds())
                }else{
                    swipe(303, 1328, 335, 171, 300);
                    reprintButton=text("去转载").findOnce();
                    clickBounds(reprintButton.bounds())
                }
                sleepRandom5()
                clickControlBounds(text("转载"))
                sleepRandom5()
            } catch (error) {
            }
            }
        } else {
            toastError("居然失败了")
        }
    }
}

function closeSplashAD(){
    if(id("wbu_home_red_package_close").exists()){
        clickControlBounds(id("wbu_home_red_package_close"));
    }
}

function silderScreen(total) {
    if(total<0){return}
    for (let i = 0; i < total; i++) {
        swipe(303, 1328, 335, 171, 300);
        sleepRandom0()
    }
    
}
function closeSplashAD() {
    if (id("img_close").exists()) {
        clickControlBounds(id("img_close"));
    }
}


function closeAD() {
    if (id("img_close").exists()) {
        clickControlBounds(id("img_close"));
    }
    clickControlBounds(text("我知道了"));

}
function autoCashOut() {
    try {
        if (clickControl(text("我的"))) {
            if (clickControl(text("提现"))) {
                sleepRandom9()
                sleepRandom9()
                toastInfo("18")
                swipe(303, 1328, 335, 171, 300);
                sleepRandom0()
                if (text("无门槛").exists()) {
                    clickControlBounds(text("无门槛"))
                    sleepRandom1()
                    if (text("去完成").exists()) {
                        clickControlBounds(text("去完成"))
                        sleep(60000)
                        sleepRandom1()
                        clickControlBounds(id("tt_video_ad_close"))
                        sleepRandom3()
                        clickControlBounds(text("下一步"))
                        sleepRandom3()
                        clickControlBounds(text("提交"))
                        sleepRandom3()
                        clickControlBounds(text("确定"))
                        sleepRandom3()
                        clickControlBounds(text("不再提醒"))
                        sleepRandom1()
                        back()
                    }
                }
            }
        }
    } catch (error) {
        toastError(error);
    }
}
function autoSign() {
    if (clickControl(text("赚金币"))) {
        sleep(4000)
        clickControl(text("立即签到"))
        clickControl(id("img_close"))
    }
    clickControl(id("img_close"))
    clickVideoMenu()
}
function autoClearCache() {
    try {
        if (clickControl(text("我的"))) {
            if (clickControl(id("imgSetting"))) {
                if (clickControl(text("清理缓存"))) {
                    back()
                }
            }
        }
        clickVideoMenu()
    } catch (error) {
        toastError("清理缓存出现错误" + error);
    }
}
//id = txt_coin_close

/**
 * 强制停止app
 * @param {应用名称} appName 
 */
function stopApp(appName) {
    try {
        openAppSetting(getPackageName(appName));
        sleep(3000);
        if (className("android.widget.Button").text("强行停止").exists()) {
            className("android.widget.Button").text("强行停止").findOnce().click();
        } else {
            if (text("强行停止").exists()) {
                text("强行停止").findOnce().click();
            }
        }
        sleep(3000);
        if (className("android.widget.Button").text("确定").exists()) {
            className("android.widget.Button").text("确定").findOnce().click();
            toastLog(appName + "已经停止!");
        }
        else {
            if (text("强行停止").exists()) {
                text("强行停止").findOnce().click();
                toastLog(appName + "已经停止!");
            } else {
                if (text("结束运行").exists()) {
                    text("结束运行").findOnce().click();
                    sleep(500);
                    if (text("确定").exists()) {
                        text("确定").findOnce().click();
                        toastLog("MIUI9 Android7" + appName + "已经停止!");
                    }
                }
            }

        }
    } catch (e) {
        toastLog(e);
    }
}
/**
 * 倒计时方法适用于脚本
 * @param {倒计时时间} lasterTime 
 */
function cutDownBySleep(lasterTime) {
    for (let i = lasterTime; i => 0; i--) {
        console.info("剩余" + i + "秒...")
        sleep(1000)
        if (i == 1) {
            return
        }
    }
}
/**
 * 点击屏幕上的坐标
 * @param {坐标} b 
 */
function clickBounds(b) {
    return clickResult = click(b.centerX(), b.centerY());
}
/**
 * 点击屏幕上的坐标
 * @param {坐标} b 
 */
function clickControlBounds(element) {
    let clickResult = false;
    if (element == null) {
        return false;
    }
    try {
        if (element.exists()) {
            toastLog("准备click:" + element);
            let b = element.findOnce().bounds();
            clickResult = click(b.centerX(), b.centerY());
            sleep(random(2000, 3200));
        } else {

        }
        return clickResult;
    } catch (error) {
        toastError("clickControlBounds方法出现错误:" + error)
        return false;
    }
}
/**
 * 点击UI上的控件
 * @param {UI上的元素} element 
 */
function clickControl(element) {
    let clickResult = false;
    try {
        if (element.exists()) {
            toastLog("准备click:" + element.findOnce().getText());
            let clickable = element.findOnce().clickable();//是否可以点击
            if (clickable) {
                clickResult = element.findOnce().click();
                sleep(random(1000, 1200));
            } else {
                let b = element.findOnce().bounds();
                clickResult = click(b.centerX(), b.centerY());
                sleep(random(1000, 1200));
            }
        }
        return clickResult;
    } catch (error) {
        toastError(error)
        return false;
    }

}
/**
 * 元素对象
 * @param {ID或name} obj 
 */
function uiSelector(obj) {
    let element = null;
    try {
        if (text("" + obj + "").exists()) {
            element = text("" + obj + "");
            return element;
        }
        if (desc("" + obj + "").exists()) {
            element = desc("" + obj + "");
            return element;
        }
        if (id("" + obj + "").exists()) {
            element = id("" + obj + "");
            return element;
        }
    } catch (error) {
        return null;
    }
}
/**
 * 随机点赞
 * @param {点赞ID}} view_id 
 */
function randomHeart(view_id, probability) {
    index = random(1, parseInt(probability));
    if (index == 1) {
        var target = id(view_id).findOnce();
        if (target == null) {
            return;
        } else {
            target.click();
            sleep(1000);
        }
    }
}
/**
 * 随机关注
 * @param {控件ID} follow_view_id 
 * @param {概率} probability 
 */
function randomFollow(follow_view_id, probability) {
    index = random(1, parseInt(probability));
    if (index == 1) {
        var target = id(follow_view_id).findOnce();
        if (target == null) {
            return;
        } else {
            target.click();
            sleep(1000);
        }
    }
}
function clickCancle() {
    if (text("取消").exists()) {
        text("取消").findOnce().click();
    }
}
/**
 * 青少年窗口
 */
function adolescentWindows() {
    if (text("我知道了").exists()) {
        text("我知道了").findOnce().click();
    }
    if (text("知道了").exists()) {
        text("知道了").findOnce().click();
    }
}
/**
 * 直接无视
 */
function closeUpgrageTip() {
    if (text("直接无视").exists()) {
        text("直接无视").findOnce().click();
    }
    if (text("刷新重试").exists()) {
        text("刷新重试").findOnce().click();
    }
}
/**随机点赞并休息一秒 */
function randomHeart() {
    index = random(1, 10);
    if (index == 1) {
        var target = id('ic_like').findOnce();
        if (target == null) {
            return;
        } else {
            target.click();
            sleep(1000);
        }
    }
}
/**
 * 贝塞尔曲线
 * @param {坐标点} ScreenPoint 
 * @param {偏移量} Offset 
 */
function bezier_curves(ScreenPoint, Offset) {
    cx = 3.0 * (ScreenPoint[1].x - ScreenPoint[0].x);
    bx = 3.0 * (ScreenPoint[2].x - ScreenPoint[1].x) - cx;
    ax = ScreenPoint[3].x - ScreenPoint[0].x - cx - bx;
    cy = 3.0 * (ScreenPoint[1].y - ScreenPoint[0].y);
    by = 3.0 * (ScreenPoint[2].y - ScreenPoint[1].y) - cy;
    ay = ScreenPoint[3].y - ScreenPoint[0].y - cy - by;
    tSquared = Offset * Offset;
    tCubed = tSquared * Offset;
    result = {
        "x": 0,
        "y": 0
    };
    result.x = (ax * tCubed) + (bx * tSquared) + (cx * Offset) + ScreenPoint[0].x;
    result.y = (ay * tCubed) + (by * tSquared) + (cy * Offset) + ScreenPoint[0].y;
    return result;
}
/**
 * 滑动(默认概率是百分之三十)
 * @param {*} qx 
 * @param {*} qy 
 * @param {*} zx 
 * @param {*} zy 
 * @param {*} time 
 * @param {*} timesInterval 
 */
function slideScreenDown(qx, qy, zx, zy, time, timesInterval, CurveBrushScreen) {
    if (CurveBrushScreen) {
        curveDown(qx, qy, zx, zy, time, timesInterval); //曲线概率
    } else {
        lineDown(qx, qy, zx, zy, time, timesInterval); //直线概率
    }
}
/**
 * 概率0-9 大于3的时候采用曲线概率 小于3的时候直线概率
 */
function randomFunction() {
    return Math.floor(Math.random() * 10);
}
function curveDown(qx, qy, zx, zy, time, timesInterval) {
    toastInfo("曲线滑动");
    var xxy = [time];
    var point = [];
    var dx0 = {
        "x": qx,
        "y": qy
    };
    var dx1 = {
        "x": random(qx - 100, qx + 100),
        "y": random(qy, qy + 50)
    };
    var dx2 = {
        "x": random(zx - 100, zx + 100),
        "y": random(zy, zy + 50),
    };
    var dx3 = {
        "x": zx,
        "y": zy
    };
    for (var i = 0; i < 4; i++) {
        eval("point.push(dx" + i + ")");
    };
    for (let i = 0; i < 1; i += 0.08) {
        let newPoint = bezier_curves(point, i);
        xxyy = [parseInt(newPoint.x), parseInt(newPoint.y)]
        xxy.push(xxyy);
    }
    gesture.apply(null, xxy);

    let randomMin = timesInterval * 1000;
    let randomMax = (parseInt(timesInterval) + 2) * 1000;
    let delayTime = random(randomMin, randomMax);
    sleep(delayTime);
}
/**
 * 屏幕向下滑动并延迟8至12秒
 */
function lineDown(startX, startY, endX, endY, pressTime, timesInterval) {
    toastInfo("屏幕向下滑动");
    swipe(startX, startY, endX, endY, pressTime);
    let randomMin = timesInterval * 1000;
    let randomMax = (parseInt(timesInterval) + 2) * 1000;
    let delayTime = random(randomMin, randomMax);
    sleep(delayTime);
}
/**
 * 按照指定概率随机上滑
 * @param {*} startX 
 * @param {*} startY 
 * @param {*} endX 
 * @param {*} endY 
 * @param {*} pressTime 
 * @param {*} probability 
 */
function randomUpSildeScreen(startX, startY, endX, endY, pressTime, probability) {
    let randomIndex = random(1, parseInt(probability));
    if (randomIndex == 1) {
        swipe(startX, startY, endX, endY, pressTime);
        delayTime = random(12000, 15000);
        sleep(delayTime);
    }
}
/**
 * 连续下滑对上一个无兴趣
 * 其实得和上滑做个排他,既然无兴趣不要在上滑
 */
function randomDownSildeScreen(startX, startY, endX, endY, pressTime, timesInterval, probability) {
    let randomIndex = random(1, parseInt(probability));
    if (randomIndex == 1) {
        swipe(startX, startY, endX, endY, pressTime);
        sleep(2000);
        swipe(startX, startY, endX, endY, pressTime);
        sleep(timesInterval);
    }
}
/**
 *点击一下屏幕
 */
function clickScreen() {
    var x = device.width - device.width * 0.2;
    var y = device.height - device.height * 0.2;
    toastLog("点击屏幕" + x + ":" + y);
    let clickResult = click(x, y);
    toastLog(clickResult);
}
/**
 * 输出Tosat和Info日志
 * @param {日志消息} messagge 
 */
function toastInfo(message) {
    toast(message)
    console.info(message)
}
/**
 * 输出Tosat和Error日志
 * @param {日志消息} messagge 
 */
function toastError(message) {
    toast(message)
    console.error(message)
}
function toastLog(message) {
    toast(message)
    console.log(message)
}
function toastWarn(message) {
    toast(message)
    console.warn(message)
}

/**
 * 休眠随机0.1秒至0.5秒
 */
function sleepRandom0() {
    sleep(random(100, 500));
}

/**
 * 休眠随机1秒至3秒
 */
function sleepRandom1() {
    sleep(random(1000, 3000));
}
/**
 * 休眠随机3秒至5秒
 */
function sleepRandom3() {
    sleep(random(3000, 5000));
}
/**
 * 休眠随机5秒至7秒
 */
function sleepRandom5() {
    sleep(random(5000, 7000));
}
/**
 * 休眠随机7秒至9秒
 */
function sleepRandom7() {
    sleep(random(7000, 9000));
}
/**
 * 休眠随机11秒至9秒
 */
function sleepRandom9() {
    sleep(random(9000, 11000));
}/**
 * 显示控件的坐标
 * @param {要查找的元素} element 
 * @index {点击的顺序} index 
 */
function clickControlList(element, index) {
    try {
        let controlArray = element.find();
        if (controlArray != null) {
            let controlLength = controlArray.length;
            for (let i = 0; i < controlLength; i++) {
                toastLog(controlArray[i].bounds())
            }
            let b = controlArray[index].bounds()
            return clickBounds(b)
        } else {
            return false
        }
    } catch (error) {
        return false
    }
}

 

标签:function,头疼,58,text,random,param,element,let,OppoR9sk
来源: https://blog.csdn.net/zy0412326/article/details/112316001