文章目錄
- 前言
- 一、auto.js優缺點及下載地址
- 二、代碼
- 使用
- 說明
- 總結
前言
本文不是用python寫的,而是用auto.js,python的話,一是學藝不精,二是我并沒有找到打卡網址,如果還想深入研究一下,可以看這個 鏈接.
一、auto.js優缺點及下載地址
Auto.js是利用安卓系統的“輔助功能”實作類似于按鍵精靈一樣,可以通過代碼模擬一系列界面動作的輔助作業,
缺點還是要先說明一下,就是每次都要開啟這個app,首先要打開無障礙功能才行
下載鏈接(注意:進去后選擇第二個下載): 下載地址.
二、代碼
150行左右
廢話就不多說了,直接看代碼:
auto.waitFor();
var phone = "110";
var province = "xxx";
var shi = "xxx";
/*詳細地址*/
var detailAddress = "xxx";
/*如果不需要在qq群中簽到,就要刪掉下面兩個方法*/
var qqqun = "xxx";
launchApp("微信");/*啟動微信*/
sleep(1000);
/*找到搜索框 微信8.0搜索框的id*/
var object = className('android.widget.ImageView').id("he6").findOne();
let b = object.bounds();
click(b.centerX(), b.centerY());
sleep(2000);
/*搜索的文字*/
setText('學生健康打卡');
sleep(200);
/*點擊內容*/
className("RelativeLayout").depth(10).drawingOrder(3).findOne().click();
text("健康打卡").findOne().parent().parent().click();
sleep(3000);
text("健康打卡").findOne().click();
sleep(3000);
var a = text("+ 今日打卡").findOne().bounds();
click(a.centerX(), a.centerY());
sleep(3000);
if (className("android.view.View").text("今日已打卡,明天再來!").exists()) {
toast("今日已打卡");
goBack();
} else {
toast("開始打卡");
sleep(1000);
swipe(500, 1500, 500, 500, 1000);
/*電話*/
directlyWriteInfo(4, phone);
/*當前所在地*/
writeAddress();
/*詳細地址*/
directlyWriteInfo(7, detailAddress);
/*租住在學校附近*/
findView(8);
writeInfo("否");
/*體溫*/
directlyWriteInfo(9, "36.5");
/*是否到過武漢*/
findView(10);
writeInfo("否");
/*是否接觸確診人員*/
findView(11);
writeInfo("無接觸");
/*目前狀況*/
findView(12);
writeInfo("正常");
/*家屬狀況*/
findView(13);
writeInfo("正常");
/*出現的癥狀*/
indexInParent(15).depth(21).row(-1).findOne().child(0).click();
/*今日外出行程*/
setText([6], "無");
/*提交*/
indexInParent(17).depth(21).row(-1).findOne().child(0).click();
/*確認提交*/
text("確認提交").findOne().click();
sleep(500);
toast("成功打卡");
goBack();
/*qq群*/
goto(qqqun);
sendMessage();
exit();
}
function findView(index) {
indexInParent(index).depth(21).row(-1).findOne().child(1).child(0).click();
sleep(500);
}
function writeInfo(message) {
var info = text(message).findOne().bounds();
click(info.centerX(), info.centerY());
sleep(500);
}
function directlyWriteInfo(index, message) {
indexInParent(index).depth(21).row(-1).findOne().child(1).child(0).setText(message);
sleep(500);
}
function goBack() {
for (let i = 0; i < 4; i++) {
back();
sleep(500);
}
}
function goto(qqqun) {
app.startActivity({
action: "android.intent.action.VIEW",
data: "mqqapi://card/show_pslcard?src_type=internal&version=1&card_type=group&uin=" + qqqun,
packageName: "com.tencent.mobileqq",
});
text("發訊息").findOne().click();
}
function sendMessage() {
id("input").findOne().setText("1");
id("fun_btn").findOne().click();
toast("簽到成功");
sleep(500);
back();
home();
}
function writeAddress() {
findView(6);
/*省份*/
var i = 0;
var j = 0;
var rect = className("LinearLayout").depth(5).drawingOrder(1).findOne().bounds();
var exist1 = className("TextView").depth(7).text(province).exists();
while (i < 10 && exist1) {
/*為什么放里面,因為我每次都要重繪這個bounds*/
var c = className("TextView").depth(7).text(province).findOne().bounds();
print(rect.bottom + "--- " + rect.top + "----" + c);
if (c.bottom < rect.bottom && c.top > rect.top) {
click(c.centerX(), c.centerY());
break;
} else {
swipe(rect.centerX(), rect.centerY(), rect.centerX(), rect.top + 20, 1000);
}
i++;
}
if (i == 10 || !exist1) {
toast("請檢查你輸入的省份,并重新執行程式");
exit();
}
/*市*/
indexInParent(6).depth(21).row(-1).findOne().child(1).child(1).click();
sleep(500);
var exist2 = className("TextView").depth(7).text(shi).exists();
while (j < 10 && exist2) {
var l_shi = className("TextView").depth(7).text(shi).findOne().bounds();
if (l_shi.bottom < rect.bottom && l_shi.top > rect.top) {
click(l_shi.centerX(), l_shi.centerY());
break;
} else {
swipe(rect.centerX(), rect.centerY(), rect.centerX(), rect.top + 20, 1000);
}
j++;
}
if (j == 10 || !exist2) {
toast("請檢查你輸入的市,并重新執行程式");
exit();
}
}
使用
- 我對代碼進行了封裝,只需在代碼開頭的幾行修改成你自己的資訊 你的電話,省份,市,詳細地址,要簽到的qq群,代碼對各個手機都是適配的,每個手機應該都是可以自動化的
- 如果js代碼總是顯示在一行,那么就要格式化代碼
步驟:進入某一個檔案 —> 編輯 —> 格式化代碼 - 要注意一點,打開app后,第一時間要打開無障礙功能,可能要多試幾次
- 然后就可以自動打卡了
說明
- 點擊之后不可能快速反應過來,所以代碼多處用了sleep
- 我直接是launchApp(“微信”),所以進入微信后一定要是主界面才行,不然找不到控制元件,就不能進行接下來的點擊事件了
總結
有不懂的話,可以加我qq(3620841688)聊聊,這個不常看
可能會有不足,歡迎指出,勿噴
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/253511.html
標籤:其他
