Realization of Taobao Lingmao coin and ant forest energy automation based on AutoJs

Keywords: github Mobile Javascript Android

outline

Once a year, double 11 is here again. Let's have a party. Taobao needs all kinds of check-in, shopping and collecting meow coins. One shop needs 15S, and after receiving all meow coins, they will be gone in at least ten to twenty minutes. As a programmer, it's time to free your hands.

1. Technical background

1.1,AutoJs

GitHub: https://github.com/hyb1996/Auto.js

Introduction to AutoJs (excerpt from GitHub)

  • A JavaScript IDE on Android platform supporting barrier free services, with the development goals of jbox and Workflow.
  • At the same time, the VS Code plug-in can provide basic functions of desktop development.
  • A simple and easy-to-use automation function implemented by accessibility services.
  • Auto.js aims at automation and workflow.
  • Auto.js does not need root permission to perform most tasks. Only the functions that need precise coordinate click and slide need root permission.

1.2 other preparations

  • Development tool: VsCode, in fact, text editor can, but VsCode can be online debugging;
  • Download the VsCode plug-in: Auto.js-VSCodeExt, Debugger for Chrome, Chinese (Simplified) Language Pack for Visual Studio Code.

2. Script writing

Please refer to the official website for detailed API, which will not be covered in this article.
It's not complicated to do a simple thing. I spent the whole afternoon to finish my study and to do Taobao Lingmao script and ant forest energy collection script.

2.1 script of Taobao Lingmao currency

   if you can't find the "go to browse" button, you will be prompted "today's browsing shop has reached the collection of meow coins". It may be that the Internet speed is too slow, which leads to a long loading time. You can set the waiting time a little longer, or start the Taobao APP in advance to run it in the background.

var height = device.height;
var width = device.width;
goScan(1);
// Browse
function goScan(k) {
    toastLog("Build By @zxiaofan,If you have any questions, please go to the subscription number[ zxiaofan]Leaving a message.");
    toastLog("Open Taobao");
    launch("com.taobao.taobao");
    sleep(4000);
    toastLog("Open Taobao ing...");
    sleep(4000);
    scrollUp();
    // Enter the home page of collecting meow coins
    click(800, 1650);
    sleep(4000);
    toastLog("Start collecting meow coins");
    getMiaoBi();
    sleep(1000);
    click("Mew coin");
    sleep(2000);
    var count = 0;
    toastLog("Go to the shop");
    while (count < 100) {
        sleep(1000);
        var Browse = text("Browse").findOnce();
        // log("[browse]:" + browse);
        if (Browse != null) {
            count++;
            toastLog("[Browse:]" + count);
            click("Browse");
            sleep(1000);
            scrollDown();
            sleep(5000);
            toastLog("[Wait for 15 seconds to collect meow coin ing...]");
            sleep(15000);
            var home page = text("home page").findOnce();
            if (null == home page) {
                back();
            } else {
                click("home page");
                goScan(1);
            }
        } else {
            sleep(1000);
            scrollUp();
            toastLog("You have reached the maximum limit of collecting meow coins by browsing the shop today");
            break;
        }
    }
    sleep(1000);
    // Sign in
    var Sign in = text("Sign in").findOnce();
    if (Sign in != null) {
        toastLog("[Sign in ing...]");
        click("Sign in");
        sleep(4000);
        back();
    }
    var To sign in = text("To sign in").findOnce();
    if (To sign in != null) {
        toastLog("[To sign in ing...]");
        click("To sign in");
        sleep(4000);
        // var to complete = text("to complete"). findOnce();
        // click("go to finish");
        // sleep(4000);
        toastLog("[Sign in at the farm ]");
        // Don't know how to operate, click the screen one by one
        // If (textcontains. exists()){
        //     //Judge the current interface
        //     sleep(1000);
        // textContains("to complete"). waitFor();
        // sleep(1000);
        // textContains("to finish"). findOne().click();

        // text("check in"). waitFor();
        // var i = text("check in"). findOne().bounds();
        // click(i.centerX(), i.centerY());;
        toastLog("Check in manually on the farm");
        // click(width / 13 * 8.5, height / 7 * 4);

        sleep(4000);
        back();
        back();
        // }
        toastLog("[END]");
        // back();
    }
    toastLog("Build By @zxiaofan,If you have any questions, please go to the subscription number[ zxiaofan]Leaving a message.");
    sleep(2000);
    exit();
}
function getMiaoBi() {
    sleep(1000);
    toastLog("[Collect the existing meow coin]");
    // Online 1 = desc("online 1").findOnce();
    // Go online 1.parent().click();
    // click("TB1wUKChoD1gK0jSZFGXXbd3FXa-133-18.png_270x270Q50s50.jpg_");
    // 354,1267,734,1372
    scrollUp();
    click(500, 1300);
}

2.2. Energy collection script of ant forest

var height = device.height;
var width = device.width;
var countmax = 100;

ant(1);
// Browse
function ant(k) {
    toast("Start collecting energy from ant forest");
    toastLog("Build By @zxiaofan,If you have any questions, please go to the subscription number[ zxiaofan]Leaving a message.");

    click("Ant forest");
    //Press to exit script monitoring at registered volume
    registEvent();
    sleep(3000);

    // First of all, put your energy away
    // Exclusion area: 2504208301608
    toast("Collect your own ant forest energy");
    getEnergy(1);
    // toast("view screenshot permission");
    toastLog("View screenshot permission");
    var reqScreen = requestScreenCapture();
    log("reqScreen:" + reqScreen);
    if (!reqScreen) {
        sleep(1000);
        toast("Failed to request screenshot");
        log("Failed to request screenshot");
        exit();
    }
    sleep(3000);
    toastLog("Slide downward");
    scrollDown();
    var screen = captureScreen();
    if (screen == null) {
        toastLog("Screenshots failed");
        exit();
    }
    toastLog("Successful screenshots");
    sleep(500);
    var shou = images.load("/sdcard/antshou.jpg");
    var love = images.load("/sdcard/antshou.jpg");
    if (null == shou) {
        shou = images.load("http://tc.zxiaofan.com/tc/a/icon/anthand.jpg");
    }
    sleep(1000);
    if (null == love) {
        love = images.load("http://tc.zxiaofan.com/tc/a/icon/antlove.jpg");
    }
    sleep(1000);

    images.save(shou, "/sdcard/antshou.jpg");
    images.save(love, "/sdcard/antlove.jpg");
    if (shou == null || love == null) {
        toastLog("Failed to load picture");
        exit();
    }

    var count = 0;
    toastLog("[Screen resolution]width:" + width + ";height:" + height);
    while (count < countmax) {
        count++;
        screen = captureScreen();
        var point = findImage(screen, shou, {
            region: [width - 200, 200, 200, height - 200],
            threshold: 0.7
        });
        sleep(500);
        if (!point) {
            point = findImage(screen, love, {
                region: [width - 200, 200, 200, height - 200],
                threshold: 0.7
            });
        }
        if (point) {
            toastLog("Find energy to collect:" + point);
            click(point.x - 10, point.y + 10);

            getEnergy(2);      //Energy recovery
            sleep(500);
            back();
            sleep(1000);
        } else {
            toastLog("No energy found:" + count);
            sleep(1000);
            scrollDown();
            toastLog("See more friends");
            click("See more friends");
            sleep(1000);
            var No more = text("No more").findOnce();
            if (No more != null) {
                toastLog("All friends' ant forest has been viewed");
                sleep(1000);
                count = countmax;
            }
        }
    }
    toastLog("End of script run");
    toastLog("Build By @zxiaofan,If you have any questions, please go to the subscription number[ zxiaofan]Leaving a message.");

    exit();
}

function getEnergy(k) {
    sleep(3000);

    //Watering sleep(3000);
    /*
     if (text("Watering "). Exists()) {& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; / / judge whether there is watering
         var Water = text("Water "). Findone (600). Borders();
         click(Water.centerX(), Water.centerY());
         sleep(1000);
     }
    */
    // if (textStartsWith("collect energy"). exists()) {/ / judge whether there is an energy ball
    //     Textstartswith (collect energy). find().forEach(function (e){
    //         Var POS = e.bounds(); & nbsp; & nbsp; / / energy sphere coordinate range
    //         Click (pos.centerx() - 70); / / click the center point of the energy sphere coordinate range
    //         sleep(500);
    //     })
    // }  else {
    //     toast("no energy to collect");
    // }
    //Click all the areas where the energy ball exists, and the interval is the radius of the energy ball
    var countmax = 900;
    var rowmax = 900;
    if (k == 1) {
        countmax = 750;
        rowmax = 750;
    }
    for (var row = 640; row < rowmax; row += 100) {
        for (var col = 140; col < countmax; col += 100) {
            click(col, row);
            sleep(50);
        }
    }
}


/**
 * Set the key to listen when the script is executed, press the volume decrease to exit the script
 */
function registEvent() {
    //Enable key listening
    events.observeKey();
    //Monitor volume up key press
    events.onKeyDown("KEYCODE_VOLUME_DOWN", function (event) {
        toastLog("Script manual exit");
        exit();
    });
}

3, finished products

                   ;
If you need a ready APP student (directly installed), please go to the public address [zxiaofan] message automatically "meow coin", the background will automatically reply to APP download address. Reply to "ant forest energy", the background automatically replies to the latest script file.

4. Precautions

  • AutoJs needs to obtain permission: "obtain mobile phone number, IMEI, IMSI permission", "read / write mobile phone storage", "display suspension window";
  • If the permission is not provided, the APP cannot be started directly;
  • AutoJs author's explanation is used to display start page ads;
  • You must turn on the accessibility service permission to use AutoJs.

5, postscript

Actually, AutoJs has a large imagination space, such as various mattress wool and APP automatic testing.
                 
The key point is not to waste precious time on the coins.

>Good luck!
Life is all about choices!
In the future, you will be grateful for yourself!
[CSDN][GitHub][OSCHINA][Nuggets][WeChat public address]

Posted by Dave2711 on Sun, 03 Nov 2019 01:27:38 -0700