/**
|
* description 抖音账号检测
|
* @type {string}
|
*/
|
let packageName = 'com.ss.android.ugc.aweme';
|
let violationType = "",
|
violationReason = "",
|
effectiveTime = "",
|
endTime = "",
|
scriptVersion = "",
|
tenantId = ""
|
dyNo = ""
|
//toast扩展参数
|
let toastExtra = {
|
"x": (device.getScreenWidth() - 800) / 2,
|
"y": (device.getScreenHeight() - 200) / 2,
|
"textColor": "#ffffff",
|
"duration": 30000,
|
"width": 800,
|
"height": 200,
|
}
|
|
run()
|
|
/**
|
* description 唤醒设备
|
*/
|
function run() {
|
if (!isAccMode()) {
|
toast('非无障碍模式,无法执行脚本', toastExtra);
|
randomSleep("非无障碍模式,无法执行脚本", "", "", "", "", "", "", "", "");
|
exit();
|
}
|
//自动化服务是否正常
|
if (!autoServiceStart(2)) {
|
toast('自动化服务启动失败,无法执行脚本', toastExtra);
|
randomSleep("自动化服务启动失败,无法执行脚本", "", "", "", "", "", "", "", "");
|
exit();
|
}
|
//脚本停止监听
|
setStopCallback(function () {
|
device.cancelKeepingAwake(); //取消保持唤醒状态
|
logd("脚本停止");
|
deviceOperaLog("脚本停止", "脚本停止", 0, "", "", "", "", "")
|
home();
|
});
|
//脚本异常停止监听
|
setExceptionCallback(function (msg) {
|
device.cancelKeepingAwake(); //取消保持唤醒状态
|
logd("脚本异常停止");
|
deviceOperaLog("脚本异常停止", "脚本异常停止", 0, "", "", "", "", "")
|
home();
|
});
|
daemonEnv(true); //守护自动化环境
|
randomSleep("脚本开始运行", "脚本启动", "", "", "", "", "", "", "");
|
//保持设备唤醒
|
importClass(android.os.PowerManager);
|
device.keepAwake(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP);
|
//保持屏幕唤醒
|
device.keepScreenOn();
|
sleep(1000);
|
//息屏设备上滑解锁
|
let lock = id("com.android.systemui:id/notification_stack_scroller").getOneNodeInfo(5000);
|
if (lock) {
|
let screenWidth = device.getScreenWidth();
|
let screenHeight = device.getScreenHeight();
|
let startX = screenWidth / 2;
|
let startY = screenHeight - 200;
|
let endX = screenWidth / 2;
|
let endY = 50;
|
let duration = 2000;
|
swipeToPoint(startX, startY, endX, endY, duration);
|
}
|
getDevice()
|
launch(packageName, 6000, 3); //打开抖音
|
}
|
|
/**
|
* description 通过包名启动应用
|
* @param packageName {string} : 应用包名
|
* @param delay {number} : 启动后等待时长(毫秒)
|
* @param startNum {number} : 重试次数
|
* @return {boolean} : 返回是否成功
|
*/
|
function launch(packageName, delay, startNum) {
|
let result = false;
|
//判断应用的包名是否存在
|
if (utils.isAppExist(packageName)) {
|
//判断应用是否在前台
|
if (getRunningPkg() == null) {
|
toast('请开启辅助功能权限');
|
exit();
|
} else if (getRunningPkg() === packageName) {
|
logd('应用已经在前台');
|
alert(); //应用启动后处理弹窗
|
toMy()
|
result = true;
|
} else {
|
logd('启动应用...');
|
let alert_selectors = text("允许");
|
let num = 0;
|
//判断应用是否启动成功
|
while (num < startNum) {
|
if (getRunningPkg() === packageName) {
|
logd('启动成功');
|
randomSleep("脚本启动成功,版本:" + scriptVersion, "脚本启动", "", "", "", "");
|
result = true;
|
break;
|
} else if (has(alert_selectors)) {
|
//初次打开应用 可能会弹出是否允许打开的弹窗
|
let node = alert_selectors.getOneNodeInfo(1000);
|
if (node) {
|
node.click();
|
}
|
} else {
|
utils.openApp(packageName);
|
sleep(delay);
|
num++;
|
}
|
}
|
}
|
alert(); //应用启动后处理弹窗
|
toMy()
|
} else {
|
toast('应用未安装');
|
exit();
|
}
|
return result;
|
}
|
|
/**
|
* description 跳转我的页面
|
*/
|
function toMy() {
|
try {
|
//定位到首页
|
execSync(function () {
|
isHome();
|
}, 1000);
|
let message_icon = clz("android.widget.TextView").getNodeInfo(randomSleep('准备点击我按钮', "", "", "", "", "", "", "", ""));
|
for (let i = message_icon.length - 1; i >= 0; i--) {
|
if (message_icon[i].text === "我") {
|
message_icon[i].click()
|
randomSleep("点击我按钮", "", "", "", "", "", "", "", "");
|
let oneNodeInfo = textMatch("抖音号:").getOneNodeInfo(2000);
|
if (oneNodeInfo) {
|
// 抖音号
|
dyNo = oneNodeInfo.text.split(":")[1]
|
}
|
let search = descMatch(".*更多.*").getOneNodeInfo(randomSleep("准备点击更多按钮", "", "", "", "", "", "", "", ""));
|
if (search) {
|
search.click()
|
randomSleep("点击更多按钮", "", "", "", "", "")
|
var creatorBtn = textMatch(".*抖音创作者中心.*").getOneNodeInfo(randomSleep("准备点击抖音创作者中心", "", "", "", "", "", "", "", ""));
|
if (creatorBtn) {
|
creatorBtn.click()
|
randomSleep("点击抖音创作者中心", "", "", "", "", "", "", "", "");
|
var checkBtn = textMatch(".*内容异常.*").getOneNodeInfo(3000);
|
var accountBtn = textMatch(".*账号异常.*").getOneNodeInfo(3000);
|
if (checkBtn) {
|
checkBtn.click()
|
randomSleep("点击违规内容异常按钮", "", "", "", "", "", "", "", "");
|
var check = clz("android.widget.TextView").getNodeInfo(3000);
|
for (let i = 0; i < check.length; i++) {
|
if (check[i].text === "违规查询") {
|
check[i].click()
|
randomSleep("点击违规查询按钮", "", "", "", "", "", "", "", "");
|
violationLog(dyNo)
|
}
|
}
|
}else if (accountBtn) {
|
accountBtn.click()
|
randomSleep("点击违规账号异常按钮", "", "", "", "", "", "", "", "");
|
var check = clz("android.widget.TextView").getNodeInfo(3000);
|
for (let i = 0; i < check.length; i++) {
|
if (check[i].text === "违规查询") {
|
check[i].click()
|
randomSleep("点击违规查询按钮", "", "", "", "", "", "", "", "");
|
violationLog(dyNo)
|
}
|
}
|
}
|
var normalBtn = textMatch(".*账号正常.*").getOneNodeInfo(3000);
|
if (normalBtn) {
|
insertDeviceCheck('', '', '', '', 1, '正常', dyNo)
|
}
|
}
|
}
|
}
|
}
|
// 定位到首页
|
isHome();
|
randomSleep("脚本运行结束", "脚本运行结束", "", "", "", "", "", "", "");
|
} catch (e) {
|
logd(e);
|
randomSleep("脚本异常", "脚本异常", "", "", "", "", "", "", "");
|
isHome()
|
}
|
}
|
|
/**
|
* 本设备账号的违规记录
|
* @param dyNo
|
*/
|
function violationLog(dyNo) {
|
let message = clz("android.webkit.WebView").getNodeInfo(2000);
|
for (let i = 0; i < message.length; i++) {
|
if (message[i].text == "账号违规记录") {
|
let mess_child = message[i].allChildren()
|
let mess_child2 = mess_child[0].allChildren()
|
let mess_child3 = mess_child2[0].allChildren()
|
let mess_child4 = mess_child3[1].allChildren()
|
let mess_child5 = mess_child4[1].allChildren()
|
for (let j = 0; j < mess_child5.length; j++) {
|
let child = mess_child5[j].allChildren()
|
if (child) {
|
for (let k = 0; k < child.length; k++) {
|
// 违规类型
|
violationType = child[0].text;
|
// 违规原因字样
|
let text2 = child[2].text;
|
// 违规原因
|
violationReason = child[3].text;
|
// 生效时间字样
|
let text4 = child[4].text;
|
// 生效时间
|
effectiveTime = child[5].text;
|
// 结束时间字样
|
let text6 = child[6].text;
|
// 结束时间
|
endTime = child[7].text;
|
}
|
insertDeviceCheck(violationType, violationReason, effectiveTime, endTime, j + 1, "异常", dyNo)
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 插入数据库
|
* @param violationType
|
* @param violationReason
|
* @param effectiveTime
|
* @param endTime
|
* @param row
|
* @param status
|
* @param dyNo
|
*/
|
function insertDeviceCheck(violationType, violationReason, effectiveTime, endTime, row, status, dyNo) {
|
let paltform = '';
|
let uniqueNo = '';
|
if ('com.ss.android.ugc.aweme'.equals(packageName)) {
|
// 斗音
|
paltform = 'DY'
|
uniqueNo = ecloud.getDeviceNo().substring(3)
|
} else if ('com.xingin.xhs'.equals(packageName)) {
|
// 小红书
|
paltform = 'XHS'
|
uniqueNo = ecloud.getDeviceNo().substring(4)
|
} else if ('com.smile.gifmaker'.equals(packageName)) {
|
// 快手
|
paltform = 'KS'
|
uniqueNo = ecloud.getDeviceNo().substring(3)
|
}
|
let query = {
|
"pageNumber": 1,
|
"pageSize": 2,
|
"fields": "",
|
"query": "",
|
"tableNameEn": "device_check",
|
"search": {
|
"unique_no": dyNo,
|
"row": row,
|
}
|
};
|
let queryr = ecloud.dynamicQuery(query)
|
queryr = JSON.parse(queryr)
|
if (queryr.result.data == null || queryr.result.data == "" || queryr.result.data == {}) {
|
let add = {
|
"tableNameEn": "device_check",
|
"columns": {
|
"device_no": ecloud.getDeviceNo(),
|
"task_id": ecloud.getTaskInfo().taskId,
|
"task_name": ecloud.getTaskInfo().taskName,
|
"platform": paltform,
|
"unique_no": dyNo,
|
"violation_type": violationType,
|
"violation_reason": violationReason,
|
"effective_time": effectiveTime,
|
"end_time": endTime,
|
"status": status,
|
"row_no": row,
|
"check_time": getDate(),
|
"tenant_id": tenantId,
|
}
|
}
|
ecloud.dynamicAdd(add)
|
randomSleep("数据新增成功", "", "", "", "", "", "", "", "")
|
} else {
|
let update = {
|
"tableNameEn": "device_check",
|
"columns": {
|
"device_no": ecloud.getDeviceNo(),
|
"task_id": ecloud.getTaskInfo().taskId,
|
"task_name": ecloud.getTaskInfo().taskName,
|
"platform": paltform,
|
"unique_no": dyNo,
|
"violation_type": violationType,
|
"violation_reason": violationReason,
|
"effective_time": effectiveTime,
|
"end_time": endTime,
|
"status": status,
|
"row": row,
|
"check_time": getDate(),
|
"tenant_id": tenantId,
|
},
|
"query": "",
|
"search": {
|
"unique_no": dyNo,
|
"row": row
|
}
|
}
|
ecloud.dynamicUpdate(update)
|
randomSleep("数据更新成功", "", "", "", "", "", "", "", "")
|
}
|
}
|
|
/**
|
* description 异步执行线程 处理弹窗
|
* @return {boolean} : 返回是否成功
|
*/
|
function alert() {
|
thread.execAsync(function () {
|
logd('启动线程,查找弹窗');
|
let btnText = ["下次再说",
|
"以后再说",
|
"关闭",
|
"允许",
|
"暂不",
|
"暂时不要",
|
"我知道了",
|
"知道了",
|
"取消",
|
"以后再说"];
|
while (true) {
|
for (let i = 0; i < btnText.length; i++) {
|
let node = text(btnText[i]).getOneNodeInfo(1000);
|
if (node) {
|
node.click();
|
logd('弹窗已处理');
|
randomSleep("弹窗处理完毕", "", "", "", "", "", "", "", "")
|
}
|
}
|
}
|
});
|
return true;
|
}
|
|
/**
|
* description 随机暂停时间
|
*/
|
function randomSleep(log, opeType, tarPostName, tarUniqueNo, tarComment, tarNickname) {
|
let min = Math.ceil(30);
|
let max = Math.floor(60);
|
let times = (Math.floor(Math.random() * (max - min + 1)) + min) * 100;
|
logd(log + ",停留" + times + "ms");
|
// 记录设备操作日志
|
if (opeType === "脚本启动" || opeType === "脚本运行结束") {
|
let serialNum = time()
|
deviceOperaLog(opeType, log + ",停留" + times + "ms", times, tarPostName, tarUniqueNo, tarComment, tarNickname, serialNum)
|
} else {
|
deviceOperaLog(opeType, log + ",停留" + times + "ms", times, tarPostName, tarUniqueNo, tarComment, tarNickname, null)
|
}
|
sleep(times);
|
return times;
|
}
|
|
/**
|
* 记录设备操作记录日志
|
*/
|
function deviceOperaLog(operateType, logDetail, intervals, tarPostName, tarUniqueNo, tarComment, tarNickname, keyWord, commUniqueNo, commNickname, time) {
|
let paltform = '';
|
let uniqueNo = '';
|
if ('com.ss.android.ugc.aweme'.equals(packageName)) {
|
// 斗音
|
paltform = 'DY'
|
uniqueNo = ecloud.getDeviceNo().substring(3)
|
} else if ('com.xingin.xhs'.equals(packageName)) {
|
// 小红书
|
paltform = 'XHS'
|
uniqueNo = ecloud.getDeviceNo().substring(4)
|
} else if ('com.smile.gifmaker'.equals(packageName)) {
|
// 快手
|
paltform = 'KS'
|
uniqueNo = ecloud.getDeviceNo().substring(3)
|
}
|
let add = {
|
"tableNameEn": "device_log",
|
"columns": {
|
"unique_no": uniqueNo,
|
"platform": paltform,
|
"device_no": ecloud.getDeviceNo(),
|
"task_name": ecloud.getTaskInfo().taskName,
|
"log_detail": logDetail,
|
"operate_type": operateType,
|
"intervals": intervals + "ms",
|
"operate_time": getDate(),
|
"tar_post_name": tarPostName,
|
"tar_unique_no": tarUniqueNo,
|
"tar_comment": tarComment,
|
"tar_nickname": tarNickname,
|
"task_id": ecloud.getTaskInfo().taskId,
|
"keyword": keyWord,
|
"comm_unique_no": commUniqueNo,
|
"comm_nickname": commNickname,
|
"tenant_id": tenantId,
|
"serial_num": time
|
}
|
}
|
ecloud.dynamicAdd(add)
|
}
|
|
/**
|
* description 定位到首页
|
* @return {boolean} : 返回是否成功
|
*/
|
function isHome() {
|
let result = false;
|
while (true) {
|
var home_selectors = text("首页").getOneNodeInfo(3000); //首页按钮
|
var message_selectors = text("消息").getOneNodeInfo(3000); //消息按钮
|
//判断是否在首页
|
if (home_selectors && message_selectors) {
|
var follow_selectors = text("关注"); //关注按钮
|
var recommend_selectors = text("推荐"); //推荐按钮
|
if (has(follow_selectors) && has(recommend_selectors)) {
|
toast('已定位首页');
|
randomSleep("已定位到首页", "", "", "", "", "", "", "", "");
|
result = true;
|
break;
|
} else {
|
home_selectors.click();
|
sleep(3000);
|
}
|
} else {
|
toast('返回首页...');
|
//返回上一页
|
go_back(1);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* description 获取当前时间
|
* @return {string} : 返回时间
|
*/
|
function getDate() {
|
let date = new Date();
|
let sign2 = ":";
|
let year = date.getFullYear() // 年
|
let month = date.getMonth() + 1; // 月
|
let day = date.getDate(); // 日
|
let hour = date.getHours(); // 时
|
let minutes = date.getMinutes(); // 分
|
let seconds = date.getSeconds() //秒
|
let weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
|
let week = weekArr[date.getDay()];
|
// 给一位数的数据前面加 “0”
|
if (month >= 1 && month <= 9) {
|
month = "0" + month;
|
}
|
if (day >= 0 && day <= 9) {
|
day = "0" + day;
|
}
|
if (hour >= 0 && hour <= 9) {
|
hour = "0" + hour;
|
}
|
if (minutes >= 0 && minutes <= 9) {
|
minutes = "0" + minutes;
|
}
|
if (seconds >= 0 && seconds <= 9) {
|
seconds = "0" + seconds;
|
}
|
return year + "-" + month + "-" + day + " " + hour + sign2 + minutes + sign2 + seconds;
|
}
|
|
/**
|
* description 自定义返回函数
|
* @param page {number} : 返回页数
|
*/
|
function go_back(page) {
|
let count = 0;
|
while (count < page) {
|
back();
|
count++;
|
randomSleep("返回上一页", "", "", "", "", "", "", "", "");
|
}
|
}
|
|
/**
|
* 获取设备信息
|
*/
|
function getDevice() {
|
var d = ecloud.getTaskInfo()
|
let taskId = d.taskId
|
taskId = parseInt(taskId, 10)
|
scriptVersion = d.scriptVersion
|
var url = "http://47.120.7.97:8098/openapi/getTask";
|
var pa = {
|
"dataSecret": "test123"
|
};
|
var x = http.postJSON(url, pa, 10 * 1000);
|
x = JSON.parse(x)
|
for (let i = 0; i < x.length; i++) {
|
if (x[i].taskId === taskId) {
|
tenantId = x[i].tenantId
|
}
|
}
|
}
|
|
/**
|
* description 启动自动化
|
* @return {boolean} : 返回自动化服务结果
|
*/
|
function autoServiceStart(time) {
|
for (let i = 0; i < time; i++) {
|
if (isServiceOk()) {
|
return true;
|
}
|
let started = startEnv();
|
randomSleep("第' + (i + 1) + '次启动服务结果: " + started, "", "", "", "", "", "", "", "");
|
if (isServiceOk()) {
|
return true;
|
}
|
}
|
return isServiceOk();
|
}
|