""" 微信视频号随机浏览 """ import random import time from func.action_func import del_key_vague from scene.oprator.atom_data import single_click_by_control, single_click_by_text, many_click_by_position, click_pic, \ stop_app, start_app from task.task_job import callback_task from tools import loggerKit, redis_client from tools.pic_base64_util import pic_to_base64 def weixin_watch_video(task_id, device_id, data): loggerKit.info('请求信息:{0}'.format(data)) device_id = data.get("deviceID") perform_action_id = data.get("performActionId") result = data.get("result") inner_data = data.get("data") loggerKit.info("inner_data:{0}, keyword:{1}", inner_data, inner_data.get("resourceName")) if result is not None: """ 非首个指令 """ perform_action_result = result.get("performActionResult") if perform_action_result is None: return_dict = { "data": "", "code": -2, "message": "fail, performActionResult is null" } # 回调任务中心 del_key_vague(device_id) callback_task(500, '指令执行失败', task_id, device_id, 0, None) return return_dict # 指令执行失败 if perform_action_result == "failure": # 回调任务中心 return_dict = { "data": "", "code": -2, "message": "fail, performActionResult is null" } del_key_vague(device_id) callback_task(500, '指令执行失败', task_id, device_id, 0, None) return return_dict # 终止指令 if perform_action_result == "stop": # 回调任务中心 return_dict = { "data": "", "code": -2, "message": "指令被用户终止" } del_key_vague(device_id) callback_task(500, '指令被用户终止', task_id, device_id, 0, None) return return_dict # 终止指令 if perform_action_result == "eleNotFound": # 回调任务中心 return_dict = { "data": "", "code": -2, "message": "未找到签到指示" } del_key_vague(device_id) callback_task(500, '未找到签到指示,该账号当天可能已经签到过', task_id, device_id, 0, None) return return_dict # 元素未找到 if perform_action_result == "invalid operation": # 回调任务中心 return_dict = { "data": "", "code": -2, "message": "fail, performActionResult is not success" } del_key_vague(device_id) callback_task(500, '任务执行失败,元素未找到', task_id, device_id, 0, None) return return_dict """ 每次操作完成后会将对应的操作唯一id存储到redis 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作 """ last_action_id = redis_client.get(device_id + "operate") step0 = redis_client.get(f"{device_id}_step0") if (step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id) and perform_action_result == "success"): action1_id = int(round(time.time() * 1000)) """ 发送第1条指令 点击:发现(菜单) """ action1_dict = single_click_by_control(action1_id, target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm", control_id="com.tencent.mm:id/icon_tv") redis_client.set(device_id + "operate", action1_id) redis_client.set(f"{device_id}_step1", "1") redis_client.delete(f"{device_id}_step0") loggerKit.info("taskId:{0}, action1_id:{1}", task_id, action1_id) return action1_dict step1 = redis_client.get(f"{device_id}_step1") if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action2_id = int(round(time.time() * 1000)) """ 发送第2条指令 点击:视频号 """ action2_dict = single_click_by_text(action2_id, text="视频号", target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") redis_client.set(device_id + "operate", action2_id) redis_client.set(f"{device_id}_step2", "1") redis_client.delete(f"{device_id}_step1") loggerKit.info("taskId:{0}, action2_id:{1}", task_id, action2_id) return action2_dict step2 = redis_client.get(f"{device_id}_step2") if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action3_id = int(round(time.time() * 1000)) """ 发送第3条指令 点击:人像 """ action3_dict = single_click_by_control(action3_id, control_id="com.tencent.mm:id/ktr", control_ids="com.tencent.mm:id/ktr", target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") redis_client.set(device_id + "operate", action3_id) redis_client.set(f"{device_id}_step3", "1") redis_client.delete(f"{device_id}_step2") loggerKit.info("taskId:{0}, action3_id:{1}", task_id, action3_id) return action3_dict step3 = redis_client.get(f"{device_id}_step3") if step3 is not None and int(step3) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action4_id = int(round(time.time() * 1000)) """ 发送第4条指令 点击: 关注 """ action4_dict = single_click_by_text(action4_id, text="关注", target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") redis_client.set(device_id + "operate", action4_id) redis_client.set(f"{device_id}_step4", "1") redis_client.delete(f"{device_id}_step3") return action4_dict step4 = redis_client.get(f"{device_id}_step4") if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action5_id = int(round(time.time() * 1000)) """ 发送第5条指令 点击: 荣威ROEWE """ action5_dict = single_click_by_text(action5_id, text="荣威ROEWE", target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") redis_client.set(device_id + "operate", action5_id) redis_client.set(f"{device_id}_step5", "1") redis_client.delete(f"{device_id}_step4") return action5_dict step5 = redis_client.get(f"{device_id}_step5") if step5 is not None and int(step5) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action6_id = int(round(time.time() * 1000)) """ 发送第6条指令 点击:视频 """ action6_dict = single_click_by_control(action6_id, control_id="com.tencent.mm:id/nuw", control_ids="com.tencent.mm:id/nuw", item_index=1, target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") redis_client.set(device_id + "operate", action6_id) redis_client.set(f"{device_id}_step6", "1") redis_client.delete(f"{device_id}_step5") return action6_dict step6 = redis_client.get(f"{device_id}_step6") if step6 is not None and int(step6) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action7_id = int(round(time.time() * 1000)) """ 发送第7条指令 随机点击某个视频 """ random_index = random.randint(1, 5) action7_dict = single_click_by_control(action7_id, control_id="com.xingin.xhs:id/aki", control_ids="com.xingin.xhs:id/aki", target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm", item_index=random_index) redis_client.set(device_id + "operate", action7_id) redis_client.set(f"{device_id}_step7", "1") redis_client.delete(f"{device_id}_step6") return action7_dict # 视频点赞 step7 = redis_client.get(f"{device_id}_step7") if step7 is not None and int(step7) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action8_id = int(round(time.time() * 1000)) """ 发送第8条指令 视频点赞 """ action8_dict = many_click_by_position(action8_id, target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") redis_client.set(device_id + "operate", action8_id) redis_client.set(f"{device_id}_step8", "1") redis_client.delete(f"{device_id}_step7") return action8_dict # 视频收藏 step8 = redis_client.get(f"{device_id}_step8") if step8 is not None and int(step8) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action9_id = int(round(time.time() * 1000)) """ 发送第9条指令 视频收藏->判断视频是否已经收藏了 """ no_collected_base64 = pic_to_base64("weixin/screen/no_collected.png") action9_dict = click_pic(action9_id, target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm", pic_base64=no_collected_base64) redis_client.set(device_id + "operate", action9_id) redis_client.set(f"{device_id}_step9", "1") redis_client.delete(f"{device_id}_step8") loggerKit.info("设备:{0}, action7_id:{1}", device_id, action9_id) return action9_dict """ 停止app """ step9 = redis_client.get(f"{device_id}_step9") if step9 is not None and int(step9) == 1 and last_action_id is not None and int(perform_action_id) == int( last_action_id): loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id)) action10_id = int(round(time.time() * 1000)) """ 停止指令 停止app """ action10_dict = stop_app(action10_id, target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") del_key_vague(device_id) loggerKit.info("设备:{0}, action10_id:{1}", device_id, action10_id) callback_task(None, None, task_id, device_id, 1, None) return action10_dict else: action0_id = int(round(time.time() * 1000)) """ 启动指令 启动app """ action0_dict = start_app(action0_id, target_app="weixin", target_version="8.0.47", package_name="com.tencent.mm") redis_client.set(device_id + "operate", action0_id) redis_client.set(f"{device_id}_step0", "1") redis_client.delete(f"{device_id}_step11") loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id) return action0_dict