一年一度雙11又到了,一塊兒來湊個熱鬧。淘寶須要各類簽到、逛店鋪領喵幣,一個店鋪15S,領完全部喵幣,至少十幾二十分鐘就沒了,做爲一名程序員,是時候解放雙手了。git
GitHub:github.com/hyb1996/Aut…程序員
AutoJs簡介(如下內容摘錄至GitHub)github
詳細的API參見官網,本文就不贅述了。
作個簡單的東西並不複雜,我就花了一下午的時間,完成學習以及作了淘寶領喵幣腳本、螞蟻森林收能量腳本。微信
若是找不到「去瀏覽」按鈕,就會提示「今日瀏覽店鋪領取喵幣已達上」,多是網速太慢致使加載時間較長,能夠把等待時間設置長一點,或者提早先啓動淘寶APP,讓其在後臺運行。編輯器
var height = device.height;
var width = device.width;
goScan(1);
// 去瀏覽
function goScan(k) {
toastLog("Build By @zxiaofan,有問題請前往訂閱號【zxiaofan】留言");
toastLog("打開淘寶");
launch("com.taobao.taobao");
sleep(4000);
toastLog("打開淘寶ing...");
sleep(4000);
scrollUp();
// 進入領取喵幣主頁
click(800, 1650);
sleep(4000);
toastLog("開始領喵幣");
getMiaoBi();
sleep(1000);
click("領喵幣");
sleep(2000);
var count = 0;
toastLog("去瀏覽 店鋪");
while (count < 100) {
sleep(1000);
var 去瀏覽 = text("去瀏覽").findOnce();
// log("[去瀏覽]:" + 去瀏覽);
if (去瀏覽 != null) {
count++;
toastLog("[去瀏覽:]" + count);
click("去瀏覽");
sleep(1000);
scrollDown();
sleep(5000);
toastLog("[等待滑動15秒領取喵幣 ing...]");
sleep(15000);
var 首頁 = text("首頁").findOnce();
if (null == 首頁) {
back();
} else {
click("首頁");
goScan(1);
}
} else {
sleep(1000);
scrollUp();
toastLog("今日瀏覽店鋪領取喵幣已達上限");
break;
}
}
sleep(1000);
// 簽到
var 簽到 = text("簽到").findOnce();
if (簽到 != null) {
toastLog("[簽到 ing...]");
click("簽到");
sleep(4000);
back();
}
var 去簽到 = text("去簽到").findOnce();
if (去簽到 != null) {
toastLog("[去簽到 ing...]");
click("去簽到");
sleep(4000);
// var 去完成 = text("去完成").findOnce();
// click("去完成");
// sleep(4000);
toastLog("[農場簽到啦啦 ]");
// 不知道怎麼操做,把屏幕挨個點擊一遍
// if (textContains("的農場").exists()) {
// //判斷當前界面
// sleep(1000);
// textContains("去完成").waitFor();
// sleep(1000);
// textContains("去完成").findOne().click();
// text("簽到").waitFor();
// var i = text("簽到").findOne().bounds();
// click(i.centerX(), i.centerY());;
toastLog("農場手動簽到吧");
// click(width / 13 * 8.5, height / 7 * 4);
sleep(4000);
back();
back();
// }
toastLog("[END]");
// back();
}
toastLog("Build By @zxiaofan,有問題請前往訂閱號【zxiaofan】留言");
sleep(2000);
exit();
}
function getMiaoBi() {
sleep(1000);
toastLog("[領取已有喵幣]");
// 上線1 = desc("上線1").findOnce();
// 上線1.parent().click();
// click("TB1wUKChoD1gK0jSZFGXXbd3FXa-133-18.png_270x270Q50s50.jpg_");
// 354,1267,734,1372
scrollUp();
click(500, 1300);
}
複製代碼
var height = device.height;
var width = device.width;
var countmax = 100;
ant(1);
// 去瀏覽
function ant(k) {
toast("開始收取螞蟻森林能量");
toastLog("Build By @zxiaofan,有問題請前往訂閱號【zxiaofan】留言");
click("螞蟻森林");
//註冊音量下按下退出腳本監聽
registEvent();
sleep(3000);
// 先把本身的能量收了
// 排除區域:250,420,830,1608
toast("收取本身的螞蟻森林能量");
getEnergy(1);
// toast("查看截圖權限");
toastLog("查看截圖權限");
var reqScreen = requestScreenCapture();
log("reqScreen:" + reqScreen);
if (!reqScreen) {
sleep(1000);
toast("請求截圖失敗");
log("請求截圖失敗");
exit();
}
sleep(3000);
toastLog("下滑");
scrollDown();
var screen = captureScreen();
if (screen == null) {
toastLog("截圖失敗");
exit();
}
toastLog("截圖成功");
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("加載圖片失敗");
exit();
}
var count = 0;
toastLog("[屏幕分辨率]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("找到可收取能量:" + point);
click(point.x - 10, point.y + 10);
getEnergy(2); //收能量
sleep(500);
back();
sleep(1000);
} else {
toastLog("沒有找到能量:" + count);
sleep(1000);
scrollDown();
toastLog("查看更多好友");
click("查看更多好友");
sleep(1000);
var 沒有更多了 = text("沒有更多了").findOnce();
if (沒有更多了 != null) {
toastLog("全部好友的螞蟻森林均已查看完畢");
sleep(1000);
count = countmax;
}
}
}
toastLog("腳本運行結束");
toastLog("Build By @zxiaofan,有問題請前往訂閱號【zxiaofan】留言");
exit();
}
function getEnergy(k) {
sleep(3000);
//澆水 sleep(3000);
/* if (text("澆水").exists()) { //判斷有沒有澆水 var Water = text("澆水").findOne(600).bounds(); click(Water.centerX(), Water.centerY()); sleep(1000); } */
// if (textStartsWith("收集能量").exists()) {//判斷是否存在能量球
// textStartsWith("收集能量").find().forEach(function (e) {
// var pos = e.bounds(); //能量球座標範圍
// click(pos.centerX(), pos.centerY() - 70);//點擊能量球座標範圍中心點
// sleep(500);
// })
// } else {
// toast("沒有可收集的能量");
// }
//將能量球存在的區域都點一遍,間隔是能量球的半徑
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);
}
}
}
/** * 設置按鍵監聽 當腳本執行時候按音量減 退出腳本 */
function registEvent() {
//啓用按鍵監聽
events.observeKey();
//監聽音量上鍵按下
events.onKeyDown("KEYCODE_VOLUME_DOWN", function (event) {
toastLog("腳本手動退出");
exit();
});
}
複製代碼
有能力的同窗能夠自行使用上面的腳本完成自動化操做;
若是須要現成的APP的同窗(直接安裝可用),請前往公衆號【zxiaofan】留言「自動領喵幣」,後臺將自動回覆APP下載地址。回覆「螞蟻森林能量」,後臺自動回覆最新腳本文件。函數
其實AutoJs想象空間很大,好比各類褥羊毛、APP自動化測試。
固然,對於爾等程序猿而言:
領喵幣不是重點,重點是不能浪費寶貴的時間在領喵幣上。工具
祝君好運!
Life is all about choices!
未來的你必定會感激如今拼命的本身!
【CSDN】【GitHub】【OSCHINA】【掘金】【微信公衆號】
學習