/** * 快手养号第三天 参数, 标题关键字, 话术列表 * @type {string} */ var deviceNo = ecloud.getDeviceNo(); //设备编号 var unique_id = deviceNo.slice(3); //账号 var taskId = ecloud.getTaskInfo().taskId; //任务id var taskName = ecloud.getTaskInfo().taskName; //任务名称 var version = '24.11.14' // 随机获取本次执行时间 // var maxRunningTime = getRandomFutureTimestamp() const startTime = Date.now() var maxRunningCount = random(30, 50) var views = 0, like_count = 0, favorites_count = 0, message_count = 0 // messageList = ['学到了', '受教', '还有这操作?', '早知当初...'] let packageName = 'com.smile.gifmaker'; let keyWord = ecloud.getTaskInfo().valueJson['标题关键词'].split('|') let messageList = ecloud.getTaskInfo().valueJson['话术列表'].split('|') weights = { like: 15, message: 10, favorites: 5, doNothing: 70 } logd(keyWord) logd(messageList); var tenantId = '' 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 } } } logd('快手养号第三天') run() main() function main() { let messageContent; if (launch(packageName, 50 * 1000, 5) && isHome()) { // if (launch(packageName, 50 * 1000, 5) && isHome()) { sleepAndPrintLog('应用启动成功', false, '应用启动') insertTrace('应用启动', '', '', '', '', serial_num) while (true) { try { if (views >= maxRunningCount) { sleepAndPrintLog("脚本执行结束,浏览" + views + "次,点赞" + like_count + "次,评论" + message_count + "次,收藏" + favorites_count + "次", false, '脚本运行结束') insertTrace("脚本执行结束", '', '', '', '', serial_num) home() break } logd("已执行" + views + "次,共" + maxRunningCount + "次") sleepAndPrintLog("已执行" + views + "次,共" + maxRunningCount + "次", false, '') let title = getTitle() 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 = message() logd(message_content) sleepAndPrintLog('评论作品', true, '评论作品', '', title, auth) insertTrace('评论作品', title, auth, '', message_content, '') } if (option === 'favorites') { favorites() sleepAndPrintLog('收藏作品', true, '收藏作品', '', title, auth) insertTrace('收藏作品', title, auth, '', '', auth) } randomSleep() } refreshVideo() views += 1 } catch (e) { loge(e) isHome() } } } } 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() { let comment_button = id('com.smile.gifmaker:id/comment_icon').getOneNodeInfo(12000) if (comment_button) { comment_button.click() let input_ele = id('com.smile.gifmaker:id/edit_container_layout').getOneNodeInfo(12000); clickPoint(input_ele.bounds.left + random(50, 250), input_ele.bounds.bottom - random(20, 80)) input_ele = clz('android.widget.EditText').getOneNodeInfo(12000) input_ele.click() let comment_content = messageList[random(0, messageList.length - 1)] input_ele.inputText(comment_content) randomSleep(3000) desc('发送').getOneNodeInfo(12000).click() id('com.smile.gifmaker:id/tabs_panel_close').getOneNodeInfo(12000).click() return comment_content } return false } 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 browserComment() { let comment = id('com.smile.gifmaker:id/comment_icon').clz('android.view.View').getOneNodeInfo(12000) if (comment) { comment.click() randomSleep() let num = random(1, 5) logd(num) for (let i = 0; i < num; i++) { randomSleep() swipeToPoint(random(500, 600), random(1600, 1700), random(500, 600), random(500, 600), random(500, 800)); randomSleep() } back() return true } return false } // 根据权重选择选项 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; } } } function refreshVideo() { let nickname = getAuth() let title = getTitle() sleepAndPrintLog('浏览视频', false, '浏览作品') insertTrace('浏览视频', title, nickname, '', '', serial_num) logd(nickname) logd(title) swiper() randomSleep() randomSleep() } /** * 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 (title) { 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); } /** * 跳转精选页 */ function isHome() { try { const HomeActivity = { "pkg": "com.smile.gifmaker", "className": "com.yxcorp.gifshow.HomeActivity" }; if (utils.openActivity(HomeActivity)) { text("精选").getOneNodeInfo(10000).click() return true } else { loge('跳转失败') return false } } catch (e) { loge(e) } } function getAuth() { let auth = id('com.smile.gifmaker:id/user_name_text_view') .clz("android.widget.TextView") .textMatch('@.*').getOneNodeInfo(12000) if (auth) { return auth.text } else { return '' } } function getTitle() { try { let title_ele = id('com.smile.gifmaker:id/element_caption_label').getOneNodeInfo(12000) if (title_ele) { return title_ele.text } else { return false } } catch (e) { loge('获取标题发生错误====>' + e) } } /** * 记录信息 * @param info * @param isSleep * @param operate_type * @param tar_comment * @param title * @param tar_nickname */ function sleepAndPrintLog(info, isSleep, operate_type, tar_comment, title, tar_nickname) { 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": "KS", //所属平台 "operate_time": timeFormat("yyyy-MM-dd HH:mm:ss") + '', //操作时间 "log_detail": info, //日志明细 "intervals": sleepTime, //操作间隔 "tar_comment": tar_comment,//评论内容 'tar_nickname': tar_nickname, 'tar_post_name': title, "tenant_id": tenantId, "operate_type": operate_type //操作类型 } } ecloud.dynamicAdd(add); sleep(sleepTime); } /** * description 插入埋点 * @param operate_type {string} : 操作类型 * @param post_name {string} : 作品名称 * @param nickname {string} : 用户昵称 * @param keyword {string} : 搜索关键词 * @param content */ 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": "KS", //所属平台 "unique_no": unique_id, //用户唯一编号 "post_name": post_name, //作品名称 "nickname": nickname, //用户昵称 'comment': content, "keyword": keyword, //搜索关键词 "tenant_id": tenantId, "operate_type": operate_typem, //操作类型 '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); }