/**
|
* 抖音养号第3+天
|
* @type {string}
|
*/
|
|
// 视频标题关键字
|
// let videoKeyword = ["短视频代运营", "短视频运营", "短视频运营课程", "短视频剪辑", "短视频剪辑课程"]
|
// let searchKeyWord
|
var deviceNo = ecloud.getDeviceNo(); //设备编号
|
var unique_id = deviceNo.slice(3); //账号
|
var taskId = ecloud.getTaskInfo().taskId; //任务id
|
var taskName = ecloud.getTaskInfo().taskName; //任务名称
|
var tenantId = ''
|
let keyWord = ecloud.getTaskInfo().valueJson['标题关键词'].split('|')
|
let messageList = ecloud.getTaskInfo().valueJson['话术列表'].split('|')
|
var version = '1.0'
|
var serial_num = time()
|
|
/**
|
* 获取设备信息
|
*/
|
getDevice()
|
|
function getDevice() {
|
var d = ecloud.getTaskInfo()
|
let taskId = d.taskId
|
taskId = parseInt(taskId, 10)
|
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
|
}
|
}
|
}
|
|
|
weights = {
|
like: 15,
|
message: 10,
|
favorites: 5,
|
doNothing: 70
|
}
|
|
// 随机获取本次执行时间
|
// var maxRunningTime = getRandomFutureTimestamp()
|
var maxRunningCount = random(60, 100)
|
var views = 0, like_count = 0, favorites_count = 0, message_count = 0
|
|
|
logd(keyWord)
|
|
let packageName = 'com.ss.android.ugc.aweme';
|
|
|
logd('抖音养号第三天')
|
|
run()
|
main()
|
|
function main() {
|
if (launch(packageName, 50 * 1000, 5) && isHome()) {
|
sleepAndPrintLog('应用启动成功', false, '应用启动')
|
insertTrace('应用启动', '', '', '', '','')
|
while (true) {
|
if (views >= maxRunningCount) {
|
sleepAndPrintLog("脚本执行结束,浏览" + views + "次,点赞" + like_count + "次,评论" + message_count + "次,收藏" + favorites_count + "次", false, '脚本运行结束')
|
insertTrace("脚本执行结束", '', '', '', '','')
|
home()
|
break
|
}
|
logd("已执行" + views + "次,共" + maxRunningCount + "次")
|
sleepAndPrintLog("已执行" + views + "次,共" + maxRunningCount + "次", false, '')
|
let title = getTitleOnMainActivity()
|
logd(title)
|
let auth = getAuth()
|
if (checkTitle(title)) {
|
randomSleep()
|
let option = getRandomOption(weights)
|
if (option === 'like') {
|
like()
|
sleepAndPrintLog('点赞作品', true, '点赞作品', '', title, auth)
|
insertTrace('点赞作品', title, auth, '', '')
|
}
|
if (option === 'message') {
|
let message_content = messageList[random(0, messageList.length - 1)]
|
message(message_content)
|
logd(message_content)
|
sleepAndPrintLog('评论作品', true, '评论作品', '', title, auth)
|
insertTrace('评论作品', title, auth, '', message_content)
|
}
|
if (option === 'favorites') {
|
favorites()
|
sleepAndPrintLog('收藏作品', true, '收藏作品', '', title, auth)
|
sleepAndPrintLog('收藏作品', true, '收藏作品', '', title, auth)
|
}
|
randomSleep()
|
}
|
refreshVideo()
|
views += 1
|
}
|
}
|
}
|
|
function favorites() {
|
let favorites_button = id('com.smile.gifmaker:id/collect_icon').getOneNodeInfo(12000)
|
if (favorites_button) {
|
favorites_button.click()
|
return true
|
}
|
return false
|
}
|
|
function like() {
|
let lick_button = id('com.smile.gifmaker:id/like_icon').getOneNodeInfo(12000)
|
if (lick_button) {
|
lick_button.click()
|
return true
|
}
|
return false
|
}
|
|
function message(messageContent) {
|
let comment_icon = descMatch(".*评论.*").getOneNodeInfo(5000);
|
let input;
|
let send_button;
|
if (comment_icon.click()) {
|
input = clz('android.widget.EditText').getOneNodeInfo(5000);
|
if (input.click()) {
|
randomSleep()
|
clz('android.widget.EditText').getOneNodeInfo(5000).click()
|
randomSleep()
|
if (clz('android.widget.EditText').getOneNodeInfo(5000).inputText(messageContent)) {
|
logd('输入成功');
|
}
|
randomSleep()
|
send_button = text('发送').getOneNodeInfo(3000)
|
if (send_button.click()) {
|
logd('发送评论成功')
|
randomSleep()
|
back()
|
return messageContent
|
}
|
}
|
}
|
}
|
|
|
function refreshVideo() {
|
let nickname = getAuth()
|
let title = getTitleOnMainActivity()
|
sleepAndPrintLog('浏览视频', false, '浏览作品', title)
|
insertTrace('浏览视频', title, nickname, '', '')
|
// logd(nickname)
|
// logd(title)
|
swiper()
|
randomSleep()
|
|
}
|
|
// 根据权重选择选项
|
function getRandomOption(weights) {
|
let options = Object.keys(weights);
|
let totalWeight = options.reduce((sum, option) => sum + weights[option], 0);
|
let random = Math.random() * totalWeight;
|
let cumulativeWeight = 0;
|
for (let option of options) {
|
cumulativeWeight += weights[option];
|
if (random < cumulativeWeight) {
|
logd('选择结果为' + option);
|
return option;
|
}
|
}
|
}
|
|
|
/**
|
* description 唤醒设备
|
*/
|
function run() {
|
sleepAndPrintLog('脚本开始运行,抖音养号第三天,版本:' + version, false, '脚本启动');
|
insertTrace('脚本启动', '', '', '', '脚本启动',serial_num)
|
//保持设备唤醒
|
importClass(android.os.PowerManager);
|
device.keepAwake(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP);
|
//保持屏幕唤醒
|
device.keepScreenOn();
|
sleep(1000);
|
swipeToPoint(30, 800, 30, 100, 1000); //设备上滑解锁
|
//脚本停止监听
|
setStopCallback(function () {
|
device.cancelKeepingAwake(); //取消保持唤醒状态
|
sleepAndPrintLog('脚本运行结束', false, '脚本停止');
|
insertTrace('脚本结束', '', '', '', '脚本结束',serial_num)
|
|
});
|
//脚本异常停止监听
|
setExceptionCallback(function (msg) {
|
device.cancelKeepingAwake(); //取消保持唤醒状态
|
sleepAndPrintLog('脚本异常停止消息:' + msg, false, '脚本停止');
|
insertTrace('脚本异常', '', '', '', '脚本异常',serial_num)
|
|
});
|
|
}
|
|
|
function checkTitle(title) {
|
if (!keyWord) {
|
logd('关键字为空')
|
return false
|
}
|
for (let i = 0; i < keyWord.length; i++) {
|
if (title.includes(keyWord[i])) {
|
logd('标题包含关键字:' + keyWord[i])
|
return true
|
}
|
}
|
logd('标题不含关键字')
|
return false
|
}
|
|
function randomSleep() {
|
let min = Math.ceil(3);
|
let max = Math.floor(6);
|
let time = (Math.floor(Math.random() * (max - min + 1)) + min) * 1000;
|
sleep(time);
|
}
|
|
|
/**
|
* 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;
|
}
|
|
function getAuth() {
|
try {
|
let auth = id('com.ss.android.ugc.aweme:id/title').clz('android.widget.TextView').getOneNodeInfo(12000)
|
if (auth) {
|
return auth.text
|
}
|
} catch (e) {
|
loge('获取用户名失败')
|
return '获取用户名失败'
|
}
|
}
|
|
function getTitleOnMainActivity() {
|
let title = id('com.ss.android.ugc.aweme:id/desc').clz('android.widget.TextView').getOneNodeInfo(12000)
|
if (title) {
|
return title.text
|
} else {
|
logd('未获取到标题')
|
return '未获取到标题'
|
}
|
}
|
|
/**
|
* 记录信息
|
* @param info
|
* @param isSleep
|
* @param operate_type
|
* @param title
|
*/
|
function sleepAndPrintLog(info, isSleep, operate_type, title) {
|
var sleepTime = 0;
|
if (isSleep) {
|
//随机选取3000-5000毫秒休眠时间
|
var min = Math.ceil(30);
|
var max = Math.floor(50);
|
sleepTime = (Math.floor(Math.random() * (max - min + 1)) + min) * 100;
|
}
|
var add = {
|
"tableNameEn": "device_log",
|
"columns": {
|
"task_id": taskId, //任务id
|
"task_name": taskName, //任务名称
|
"device_no": deviceNo, //设备编号
|
"unique_no": unique_id, //账号
|
"platform": "DY", //所属平台
|
"operate_time": timeFormat("yyyy-MM-dd HH:mm:ss") + '', //操作时间
|
"log_detail": info, //日志明细
|
"intervals": sleepTime, //操作间隔
|
"tenant_id": tenantId,
|
'tar_post_name': title,
|
"operate_type": operate_type //操作类型
|
}
|
}
|
ecloud.dynamicAdd(add);
|
sleep(sleepTime);
|
}
|
|
|
/**
|
* description 插入埋点
|
* @param post_name {string} : 作品名称
|
* @param nickname {string} : 用户昵称
|
* @param content
|
* @param keyword {string} : 搜索关键词
|
* @param operate_type {string} : 操作类型
|
* @param serial_num
|
*/
|
function insertTrace(operate_type, post_name, nickname, keyword, content,serial_num) {
|
let time = timeFormat("yyyy-MM-dd HH:mm:ss") + '';
|
var deviceNo = ecloud.getDeviceNo(); //设备编号
|
var unique_id = deviceNo.slice(3);
|
let add = {
|
"tableNameEn": "trace",
|
"columns": {
|
"task_id": ecloud.getTaskInfo().taskId,
|
"task_name": ecloud.getTaskInfo().taskName,
|
"device_no": deviceNo, //设备编号
|
"operate_time": time, //操作时间
|
"platform": "DY", //所属平台
|
"unique_no": unique_id, //用户唯一编号
|
"post_name": post_name, //作品名称
|
"nickname": nickname, //用户昵称
|
'comment': content,
|
"keyword": keyword, //搜索关键词
|
"operate_type": operate_type, //操作类型
|
"tenant_id": tenantId,
|
'serial_num':serial_num
|
}
|
}
|
ecloud.dynamicAdd(add);
|
}
|
|
/**
|
* 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('应用已经在前台');
|
result = true;
|
} else {
|
logd('启动应用...');
|
let alert_selectors = text("允许");
|
let num = 0;
|
//判断应用是否启动成功
|
while (num < startNum) {
|
if (getRunningPkg() === packageName) {
|
logd('启动成功');
|
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(); //应用启动后处理弹窗
|
} else {
|
toast('应用未安装');
|
exit();
|
}
|
return result;
|
}
|
|
|
/**
|
* description 异步执行线程 处理弹窗
|
* @return {boolean} : 返回是否成功
|
*/
|
function alert() {
|
thread.execAsync(function () {
|
logd('启动线程,查找弹窗');
|
let btnText = new Array(
|
"下次再说",
|
"以后再说",
|
"关闭",
|
"允许",
|
"暂不",
|
"暂时不要",
|
"我知道了",
|
"知道了",
|
"取消",
|
);
|
while (true) {
|
for (let i = 0; i < btnText.length; i++) {
|
// logd('检查弹窗...');
|
let node = text(btnText[i]).getOneNodeInfo(1000);
|
if (node) {
|
node.click();
|
logd('弹窗已处理');
|
}
|
}
|
sleep(3000);
|
}
|
});
|
return true;
|
}
|
|
|
/**
|
* description 自定义返回函数
|
* @param page {number} : 返回页数
|
*/
|
function go_back(page) {
|
let count = 0;
|
while (count < page) {
|
back();
|
count++;
|
// randomSleep("返回上一页", "返回上一页", "", "", "", "");
|
}
|
}
|
|
|
/**
|
* description 滑动视频
|
* @return {boolean} : 返回是否成功
|
*/
|
function swiper() {
|
let result = false;
|
//设定坐标 适配全分辨率
|
let x = device.getScreenWidth() * 7 / 10;
|
let y = device.getScreenHeight() * 8 / 10;
|
let x1 = device.getScreenWidth() * 7 / 10;
|
let y1 = device.getScreenHeight() * 1.5 / 10
|
|
if (rnd_Swipe(x, y, x1, y1, 100, 200, 200)) {
|
sleep(3000);
|
logd("滑动完成");
|
result = true;
|
|
}
|
return result;
|
}
|
|
|
/**
|
* description 仿真随机带曲线滑动
|
*/
|
function rnd_Swipe(qx, qy, zx, zy, time, times, timess) {
|
//qx, qy, zx, zy, time 代表起点x,起点y,终点x,终点y,times,timess =随机时间(times,timess)
|
let time1, xxy, point, dx0, dx1, dx2, dx3, xxyy
|
time1 = random(times, timess)
|
|
xxy = [];
|
point = [];
|
dx0 = {
|
"x": qx,
|
"y": qy
|
}
|
|
dx1 = {
|
"x": random(qx - 100, qx + 100),
|
"y": random(qy, qy + 50)
|
}
|
dx2 = {
|
"x": random(zx - 100, zx + 100),
|
"y": random(zy, zy + 50),
|
}
|
dx3 = {
|
"x": zx,
|
"y": zy
|
}
|
for (let i = 0; i < 4; i++) {
|
eval("point.push(dx" + i + ")");
|
}
|
for (let i = 0; i < 1; i += 0.08) {
|
xxyy = [parseInt(bezier_curves(point, i).x), parseInt(bezier_curves(point, i).y)]
|
xxy.push(xxyy);
|
}
|
gesture(xxy, time, time1);
|
|
return true;
|
}
|
|
|
/**
|
* description 贝赛尔曲线
|
*/
|
function bezier_curves(cp, t) {
|
let cx, bx, ax, cy, by, ay, tSquared, tCubed, result
|
cx = 3.0 * (cp[1].x - cp[0].x);
|
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
|
ax = cp[3].x - cp[0].x - cx - bx;
|
cy = 3.0 * (cp[1].y - cp[0].y);
|
by = 3.0 * (cp[2].y - cp[1].y) - cy;
|
ay = cp[3].y - cp[0].y - cy - by;
|
|
tSquared = t * t;
|
tCubed = tSquared * t;
|
result = {
|
"x": 0,
|
"y": 0
|
}
|
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
|
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
|
return result;
|
}
|
|
|
/**
|
* description 手势
|
*/
|
function gesture(swipeList, time, time1) {
|
let touch1, touch2, x, i
|
touch1 = [{"action": 0, "x": swipeList[0][0], "y": swipeList[0][1], "pointer": 1, "delay": time}]
|
|
for (i in swipeList) {
|
++i;
|
if (i === swipeList.length - 2) {
|
break;
|
}
|
touch1.push({"action": 1, "x": swipeList[i][0], "y": swipeList[i][1], "pointer": 1, "delay": time});
|
}
|
touch1.push({
|
"action": 2,
|
"x": swipeList[swipeList.length - 1][0],
|
"y": swipeList[swipeList.length - 1][1],
|
"pointer": 1,
|
"delay": time
|
})
|
|
x = multiTouch(touch1, null, null, time1);
|
logd('仿真滑动:' + x);
|
}
|