├── README.md ├── antForest.py ├── automator.py ├── main.py ├── requirements.txt ├── taoBaoTo2019.py ├── util.py ├── zhiFuBaoGainPoints.py └── zhiFuBaoTo2019.py /README.md: -------------------------------------------------------------------------------- 1 | # unHurtHand-Automator 2 | 3 | 文章目录 4 | ================= 5 | 6 | * [unHurtHand-Automator](#unhurthand-automator) 7 | * [背景介绍](#背景介绍) 8 | * [实现功能](#实现功能) 9 | * [日常任务(即常年存在的活动)](#日常任务即常年存在的活动) 10 | * [临时任务(即有开始和结束时间的任务,比如双11等电商活动)](#临时任务即有开始和结束时间的任务比如双11等电商活动) 11 | * [安装与运行](#安装与运行) 12 | * [pc端](#pc端) 13 | * [安卓端](#安卓端) 14 | * [说明](#说明) 15 | * [必改参数](#必改参数) 16 | * [可选参数](#可选参数) 17 | * [待完成任务](#待完成任务) 18 | * [Discussing](#discussing) 19 | 20 | 21 | ## 背景介绍 22 | 23 | 自娱自乐学习python的副产品,不伤手自动任务系列,自动有风险,入坑需谨慎。 24 | 25 | **PS1:据说阿里有风控的,99 划算节养章鱼用脚本的最后满级分到 1 分或者 1 毛,so只适用于个人偷懒,交流学习** 26 | 27 | **PS2:本project的诞生离不开 UIAutomator2 ,一个 Python 封装的安卓自动化测试库,比原生 adb shell 命令强大得多,方便得多,一个强大的轮子。** 28 | 29 | **PS3:本项目仅在分辨率为 1080X1920 的 9:16 的设备下测试过,其他设备不保证** 30 | 31 | **PS4:感兴趣的朋友提issue,分享还有哪些互动可以做自动任务的,技术上可以实现的会尽快实现出来** 32 | 33 | **PS5:本项目针对的是最新的或者说当前正在进行的各大厂的活动** 34 | 35 | ## 实现功能 36 | ### 日常任务(即常年存在的活动) 37 | 1. 蚂蚁森林,支持支付宝版本:10.1.85.7000,如果不能自动收集好友,建议重启手机试试 38 | - 收集自己的能量 39 | - 收集好友的能量 40 | 2. 2019双11支付宝app上的全民开喵铺 41 | - 自动收取喵币 42 | - 自动升级领红包 43 | - 自动签到 44 | - 对以下任务自动操作 45 | - <去浇水>任务 46 | - <去浏览>任务 47 | - <去完成>任务 48 | 3. 2019双11淘宝app上的全民开喵铺 49 | - 自动收取喵币 50 | - 自动升级领红包 51 | - 自动签到 52 | - 对以下任务自动操作 53 | - <去浏览>任务 54 | - <去签到>任务 55 | - <去查看>任务 56 | - 自动拆红包 57 | 4. 支付宝-领积分 58 | - 自动领积分 59 | 5. 支付宝-分亿元红包活动 60 | - 自动长按获得翻倍豆等 61 | ### 临时任务(即有开始和结束时间的任务,比如双11等电商活动) 62 | 63 | ## 安装与运行 64 | 65 | ### pc端 66 | 67 | - 如果你没有安装 Python,请先安装 [Python3.*](https://www.python.org/downloads/) 以上版本 68 | 69 | - 如果你没有安装 adb,请先安装,以下是adb官方介绍 70 | - Android 调试桥 (adb),https://developer.android.google.cn/studio/command-line/adb 71 | - 官方下载地址,[adb下载](https://developer.android.google.cn/studio/releases/platform-tools.html),下载后,把解压后的文件夹的路径添加到环境变量的 `Path` 中,方便全局调用 72 | 73 | - 以上都安装后,下载本项目代码到本地,进入根目录,打开 `CMD` 或者 `Powershell` 或是其他任何终端,执行以下命令,安装python依赖: 74 | 75 | ```python 76 | # 打开终端 77 | # 以下是一整行 78 | python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ 79 | ``` 80 | 81 | - adb调试有2种连接安卓手机的方式,一种usb直连,一种pc和安卓手机处于同一wifi局域网的条件下用wifi连接。具体的操作可参考,[官方介绍](https://developer.android.google.cn/studio/command-line/adb) 82 | 83 | - adb连接成功后,获取 device 名称,并填写至 main.py: 84 | 85 | ```powershell 86 | # 终端上执行以下命令,获取device值 87 | adb devices 88 | ``` 89 | 90 | - adb 连接后,执行以下命令在手机安装 ATX 应用,包含httprpc服务的apk到手机,`atx-agent, minicap, minitouch`,具体介绍可以看,[uiautomator2项目](https://github.com/openatx/uiautomator2),安装之前打开手机的开发者选项、 91 | USB调试、USB安装等功能 92 | 93 | ```python 94 | python3 -m uiautomator2 init 95 | ``` 96 | 97 | - 在手机上打开 ATX ,点击 `启动 UIAutomator` 选项,确保 UIAutomator 是运行的。 98 | 99 | - 如何运行这个脚本: 100 | 101 | ```python 102 | # 在该项目的文件夹根目录打开 103 | python main.py 104 | ``` 105 | 106 | - 能动就说明能成功运行,接下来你可以退出脚本(`Ctrl`+`C` 或者 关掉终端窗口),在 `main.py` 中修改你的配置。 107 | 108 | ### 安卓端 109 | 110 | 待续,在试验用哪个app比较方便运行python脚本,目前收集有,qpython3L,termux,Pydroid 3,目前只成功在termux上运行,不过比较复杂。 111 | 112 | ## 说明 113 | 114 | ### 必改参数 115 | 116 | - device 117 | 118 | 在pc上通过`adb devices`来获得 119 | 120 | 在安卓上写死:`http://0.0.0.0:7912` 121 | 122 | - 选择运行的任务,true表示运行,一次跑一个任务 123 | - is_ant_forest_on 124 | - is_zhi_fu_bao_to_2019_on 125 | - is_tao_bao_to_2019_on 126 | - is_zhi_fu_bao_gain_points_on 127 | 128 | ### 可选参数 129 | 130 | - is_app_lock 131 | 132 | 是否有app九宫格锁,true有 133 | 134 | - lock_points 135 | 136 | 如果有app九宫格锁,填入解锁的点坐标,可通过weditor来获得,具体介绍看,[weditor项目](https://github.com/openatx/weditor) 137 | 138 | 139 | 140 | ## 待完成任务 141 | 142 | - 代码优化 143 | - 安卓端自动运行python脚本,如有哪位大神知道怎么在安卓端运行python脚本,麻烦推荐一下,谢谢! 144 | - Q-Q 145 | 146 | 147 | ## Discussing 148 | - [在github上提问](https://github.com/scoful/unHurtHand-Automator/issues/new "在github上提问") 149 | 150 | - wechat:scoful 151 | 152 | - QQ:1269717999 153 | 154 | - email:1269717999@qq.com 155 | -------------------------------------------------------------------------------- /antForest.py: -------------------------------------------------------------------------------- 1 | from util import * 2 | 3 | 4 | def ant_forest(self): 5 | # 打开支付宝 6 | self.d.app_start("com.eg.android.AlipayGphone", wait=True) 7 | # 开app九宫锁 8 | if self.isAppLock: 9 | self.d.swipe_points(self.lockPoints, 0.2) 10 | short_wait() 11 | time.sleep(20) 12 | # 先点击去首页 13 | if self.d.xpath('//*[@text="首页"]').exists: 14 | self.d.xpath('//*[@text="首页"]').click() 15 | short_wait() 16 | # 搜索框点击 17 | if self.d.xpath('//*[@resource-id="com.alipay.mobile.base.commonbiz:id/home_title_search_button"]').exists: 18 | self.d.xpath('//*[@resource-id="com.alipay.mobile.base.commonbiz:id/home_title_search_button"]').click() 19 | short_wait() 20 | else: 21 | logging.error("搜索框定位不到") 22 | return 23 | # 输入《蚂蚁森林》搜索 24 | self.d.xpath('//*[@resource-id="com.alipay.mobile.antui:id/search_bg"]').set_text("蚂蚁森林") 25 | short_wait() 26 | # 点击搜索按钮 27 | if self.d.xpath('//*[@text="搜索"]').exists: 28 | self.d.xpath('//*[@text="搜索"]').click() 29 | short_wait() 30 | else: 31 | logging.error("搜索按钮定位不到") 32 | return 33 | # 进入搜索结果 34 | if self.d.xpath('//*[@text="进入"]').exists: 35 | short_wait() 36 | self.d.xpath('//*[@text="进入"]').click() 37 | else: 38 | logging.error("蚂蚁森林搜索结果的进入字样定位不到") 39 | return 40 | # 收集自己的能量 41 | # 循环3次,保证多余的能量也能收集到 42 | for i in range(3): 43 | collect_energy(self) 44 | # 收集完滚动到底部,点击查看更多好友,进入 45 | self.d(scrollable=True).scroll.to(description="查看更多好友") 46 | if self.d.xpath("//*[contains(@text, '查看更多好友')]").exists: 47 | self.d.xpath("//*[contains(@text, '查看更多好友')]").click() 48 | else: 49 | logging.error("《查看更多好友》定位不到") 50 | return 51 | # 进入所有好友收集能量 52 | in_my_friends(self) 53 | 54 | # 结束关闭支付宝 55 | self.d.app_stop("com.eg.android.AlipayGphone") 56 | 57 | 58 | def collect_energy(self): 59 | self.d.xpath('//*[@resource-id="J_barrier_free"]/android.widget.Button').wait(20) 60 | # 获取能量收集页面上所有可以点的按钮 61 | for elem in self.d.xpath('//*[@resource-id="J_barrier_free"]/android.widget.Button').all(): 62 | # 以下按钮都不点 63 | if elem.text == "成就" or elem.text == "发消息" or elem.text == "弹幕" or \ 64 | elem.text == "浇水" or elem.text == "公益林" or elem.text == "背包" \ 65 | or elem.text == "通知" or elem.text == "任务" or elem.text == "攻略": 66 | continue 67 | else: 68 | # 点击收集能量 69 | elem.click() 70 | time.sleep(3) 71 | # 新活动入口,硬编码关闭 72 | if self.d.xpath('//*[@text="亲爱的scoful,距离你回家还有"]').exists: 73 | short_wait() 74 | self.d.click(0.928, 0.207) 75 | short_wait() 76 | if self.d(text="明日再来").exists: 77 | self.d.press("back") 78 | if self.d.xpath('//*[@text="抽取上上签"]').exists: 79 | self.d.xpath('//*[@text="抽取上上签"]').click() 80 | time.sleep(3) 81 | self.d.press("back") 82 | 83 | 84 | 85 | def in_my_friends(self): 86 | # 先滚到最下,获取最多的好友集 87 | self.d(scrollable=True).scroll.to(description="没有更多了") 88 | # 再回到顶部,从上往下走 89 | self.d(scrollable=True).scroll.toBeginning() 90 | a = 1 91 | while self.d.xpath( 92 | '//*[@resource-id="__react-content"]/android.view.View[1]/android.view.View[2]/android.view.View[' + str( 93 | a) + ']').exists: 94 | short_wait() 95 | logging.info(f"第{a}个") 96 | # 依次点进好友页面 97 | if self.d.xpath( 98 | '//*[@resource-id="__react-content"]/android.view.View[1]/android.view.View[2]/android.view.View[' + str( 99 | a) + ']').exists: 100 | self.d.xpath( 101 | '//*[@resource-id="__react-content"]/android.view.View[1]/android.view.View[2]/android.view.View[' + str( 102 | a) + ']').click() 103 | else: 104 | # TODO 时不时就报定位不到,需要调试 105 | logging.error(f"能量收集页面上的第{a}个好友定位不到") 106 | continue 107 | self.d.xpath('//*[@resource-id="J_barrier_free"]/android.widget.Button').wait(5) 108 | # 收集好友能量 109 | if self.d.xpath('//*[@resource-id="J_barrier_free"]/android.widget.Button').exists: 110 | collect_energy(self) 111 | short_wait() 112 | self.d.press("back") 113 | a = a + 1 114 | self.d.swipe_ext("up", scale=0.1) 115 | time.sleep(3) 116 | 117 | logging.info(f"{a}个好友收集完毕") 118 | -------------------------------------------------------------------------------- /automator.py: -------------------------------------------------------------------------------- 1 | import uiautomator2 as u2 2 | 3 | from antForest import * 4 | from taoBaoTo2019 import * 5 | from zhiFuBaoGainPoints import * 6 | from zhiFuBaoTo2019 import * 7 | 8 | 9 | class Automator: 10 | def __init__(self, device: str, is_app_lock: False, lock_points: [], is_ant_forest_on: False, 11 | is_zhi_fu_bao_to_2019_on: False, is_tao_bao_to_2019_on: False, is_zhi_fu_bao_gain_points_on: False): 12 | self.d = u2.connect(device) 13 | self.dWidth, self.dHeight = self.d.window_size() 14 | self.isAppLock = is_app_lock 15 | self.lockPoints = lock_points 16 | logging.info(f'屏幕分辨率: {self.dWidth}, {self.dHeight}') 17 | self.isAntForestOn = is_ant_forest_on 18 | self.isZhiFuBaoT2019On = is_zhi_fu_bao_to_2019_on 19 | self.isTaoBaoT2019On = is_tao_bao_to_2019_on 20 | self.isZhiFuBaoGainPointsOn = is_zhi_fu_bao_gain_points_on 21 | 22 | def start(self): 23 | """ 24 | 启动脚本 25 | """ 26 | start_time = datetime.datetime.now() 27 | try: 28 | if self.isZhiFuBaoGainPointsOn: 29 | gain_points(self) 30 | if self.isAntForestOn: 31 | ant_forest(self) 32 | if self.isZhiFuBaoT2019On: 33 | zhi_fu_bao_platform(self) 34 | if self.isTaoBaoT2019On: 35 | tao_bao_platform(self) 36 | except Exception as result: 37 | logging.error(f"未知错误!{result}") 38 | return 39 | # 结束关闭支付宝 40 | self.d.app_stop("com.eg.android.AlipayGphone") 41 | # 结束关闭淘宝 42 | self.d.app_stop("com.taobao.taobao") 43 | end_time = datetime.datetime.now() 44 | time_cost = end_time - start_time 45 | logging.info(f"结束,总耗时:{time_cost}") 46 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from automator import Automator 2 | import sys 3 | import logging 4 | 5 | logger = logging.getLogger() 6 | logger.setLevel(logging.INFO) 7 | 8 | handler = logging.StreamHandler(sys.stdout) 9 | handler.setLevel(logging.DEBUG) 10 | formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 11 | handler.setFormatter(formatter) 12 | logger.addHandler(handler) 13 | 14 | if __name__ == '__main__': 15 | # 安卓本地运行 16 | # device = 'http://0.0.0.0:7912' 17 | # pc运行,adb devices 命令后得出的结果 18 | device = '53aac21b' 19 | 20 | # 是否有app九宫锁 21 | is_app_lock = False 22 | # 九宫锁解锁的点的坐标,可以通过Weditor来获取每个点的相对坐标 23 | lock_points = [(0.235, 0.575), (0.494, 0.571), (0.756, 0.859), (0.243, 0.863)] 24 | # 是否开启蚂蚁森林自动收能量任务 25 | is_ant_forest_on = True 26 | # 是否开启支付宝app领积分自动任务 27 | is_zhi_fu_bao_gain_points_on = True 28 | # 是否开启支付宝app2019双11活动自动任务 29 | is_zhi_fu_bao_to_2019_on = False 30 | # 是否开启淘宝app2019双11活动自动任务 31 | is_tao_bao_to_2019_on = False 32 | 33 | instance = Automator(device, is_app_lock, lock_points, is_ant_forest_on, is_zhi_fu_bao_to_2019_on, 34 | is_tao_bao_to_2019_on, is_zhi_fu_bao_gain_points_on) 35 | # 启动脚本。 36 | instance.start() 37 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | uiautomator2 -------------------------------------------------------------------------------- /taoBaoTo2019.py: -------------------------------------------------------------------------------- 1 | from util import * 2 | 3 | 4 | def tao_bao_platform(self): 5 | # 打开淘宝 6 | self.d.app_start("com.taobao.taobao", wait=True) 7 | time.sleep(20) 8 | 9 | open_red_pack(self) 10 | 11 | # 更新最新版淘宝app,定位首页右上角的入口 12 | if self.d.xpath( 13 | '//*[@resource-id="com.taobao.taobao:id/sv_search_view"]/android.widget.FrameLayout[' 14 | '1]/android.widget.FrameLayout[1]/android.widget.ImageView[2]').exists: 15 | self.d.xpath( 16 | '//*[@resource-id="com.taobao.taobao:id/sv_search_view"]/android.widget.FrameLayout[' 17 | '1]/android.widget.FrameLayout[1]/android.widget.ImageView[2]').click() 18 | else: 19 | logging.error("页面上找不到双11淘宝活动入口!") 20 | return 21 | 22 | # 等待界面出现完整 23 | self.d.xpath('//*[@text="双11合伙人,全民开喵铺,瓜分20亿红包"]').wait(20) 24 | if self.d.xpath('//*[@text="双11合伙人,全民开喵铺,瓜分20亿红包"]').exists: 25 | while True: 26 | # 收喵币和升级 27 | tao_bao_cat_coins(self) 28 | # 做任务 29 | tao_bao_cat_tasks(self) 30 | else: 31 | logging.error("双11淘宝活动页面打不开!") 32 | return 33 | 34 | 35 | def open_red_pack(self): 36 | # 先拆每日红包 37 | # 搜索框点击 38 | if self.d.xpath('//*[@content-desc="搜索"]').exists: 39 | self.d.xpath('//*[@content-desc="搜索"]').click() 40 | short_wait() 41 | else: 42 | logging.error("搜索框定位不到") 43 | return 44 | # 输入《https://s.click.taobao.com/i8ds4yv》搜索 45 | self.d.xpath('//*[@resource-id="com.taobao.taobao:id/searchEdit"]').set_text("https://s.click.taobao.com/i8ds4yv") 46 | short_wait() 47 | # 点击搜索按钮 48 | if self.d.xpath('//*[@text="搜索"]').exists: 49 | self.d.xpath('//*[@text="搜索"]').click() 50 | short_wait() 51 | else: 52 | logging.error("搜索按钮定位不到") 53 | return 54 | time.sleep(6) 55 | while not self.d.xpath('//*[@text="分享邀好友,继续开宝箱"]').exists: 56 | if self.d.xpath('//*[@text="拆今日红包"]').exists: 57 | self.d.xpath('//*[@text="拆今日红包"]').click() 58 | short_wait() 59 | if self.d.xpath('//*[@text="再拆一次"]').exists: 60 | self.d.xpath('//*[@text="再拆一次"]').click() 61 | short_wait() 62 | self.d.xpath('//*[@content-desc="转到上一层级"]').click() 63 | short_wait() 64 | self.d.press("back") 65 | short_wait() 66 | self.d.xpath('//*[@resource-id="com.taobao.taobao:id/btn_go_back"]').click() 67 | 68 | 69 | def tao_bao_cat_coins(self): 70 | if self.d.xpath( 71 | '//*[@resource-id="com.taobao.taobao:id/layermanager_penetrate_webview_container_id"]/android.widget' 72 | '.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[' 73 | '1]/android.widget.FrameLayout[3]/android.widget.FrameLayout[1]').exists: 74 | self.d.xpath( 75 | '//*[@resource-id="com.taobao.taobao:id/layermanager_penetrate_webview_container_id"]/android.widget' 76 | '.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[' 77 | '1]/android.widget.FrameLayout[3]/android.widget.FrameLayout[1]').click() 78 | time.sleep(1) 79 | # 收喵币 80 | self.d.click(0.498, 0.682) 81 | short_wait() 82 | if self.d.xpath('//*[@text="直接收下"]').exists: 83 | self.d.xpath('//*[@text="直接收下"]').click() 84 | time.sleep(1) 85 | # 升级领红包 86 | if self.d.xpath('//*[@text="升级领红包"]').exists: 87 | self.d.xpath('//*[@text="升级领红包"]').click() 88 | time.sleep(5) 89 | else: 90 | logging.error("升级领红包的位置定位不到") 91 | return 92 | # 关闭升级页面 93 | if self.d.xpath('//*[@text="关闭"]').exists: 94 | self.d.xpath('//*[@text="关闭"]').click() 95 | 96 | 97 | def tao_bao_cat_tasks(self): 98 | # 点击领喵币 99 | if self.d.xpath('//*[@text="领喵币"]').exists: 100 | self.d.xpath('//*[@text="领喵币"]').click() 101 | time.sleep(2) 102 | else: 103 | logging.error("领喵币的位置定位不到") 104 | return 105 | # 签到 106 | if self.d.xpath('//*[@text="签到"]').exists: 107 | self.d.xpath('//*[@text="签到"]').click() 108 | time.sleep(2) 109 | self.d.swipe(self.dWidth / 2, self.dHeight / 2, self.dWidth / 2, 0, 1) 110 | if self.d.xpath('//*[@text="去浏览"]').exists: 111 | self.d.xpath('//*[@text="去浏览"]').click() 112 | time.sleep(25) 113 | if self.d.xpath('//*[@content-desc="捉猫猫"]').exists: 114 | self.d.xpath('//*[@content-desc="捉猫猫"]').click() 115 | time.sleep(10) 116 | else: 117 | self.d.press("back") 118 | time.sleep(1) 119 | if self.d.xpath('//*[@text="正在前往会场"]').exists: 120 | self.d.press("back") 121 | time.sleep(1) 122 | if self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').exists: 123 | self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').click() 124 | elif self.d.xpath('//*[@text="去签到"]').exists: 125 | self.d.xpath('//*[@text="去签到"]').click() 126 | time.sleep(10) 127 | 128 | if self.d.xpath('//*[@resource-id="content"]/android.view.View[8]/android.view.View[7]/android.view.View[1]') \ 129 | .exists: 130 | self.d.xpath('//*[@resource-id="content"]/android.view.View[8]/android.view.View[7]/android.view.View[1]') \ 131 | .click() 132 | short_wait() 133 | if self.d.xpath('//*[@resource-id="app"]/android.view.View[1]/android.view.View[2]/android.view.View[4]') \ 134 | .exists: 135 | self.d.xpath('//*[@resource-id="app"]/android.view.View[1]/android.view.View[2]/android.view.View[4]') \ 136 | .click() 137 | elif self.d.xpath('//*[@resource-id="app"]/android.view.View[1]/android.view.View[1]').exists: 138 | self.d.xpath('//*[@resource-id="app"]/android.view.View[1]/android.view.View[1]').click() 139 | short_wait() 140 | if self.d.xpath('//*[@text="签到"]').exists: 141 | self.d.xpath('//*[@text="签到"]').click() 142 | time.sleep(1) 143 | self.d.press("back") 144 | time.sleep(1) 145 | if self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').exists: 146 | self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').click() 147 | elif self.d.xpath('//*[@text="去查看"]').exists: 148 | short_wait() 149 | self.d.press("back") 150 | short_wait() 151 | if self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').exists: 152 | self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').click() 153 | else: 154 | time.sleep(1) 155 | if self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').exists: 156 | self.d.xpath('//*[@resource-id="taskBottomSheet"]/android.widget.Button[1]').click() 157 | -------------------------------------------------------------------------------- /util.py: -------------------------------------------------------------------------------- 1 | import time 2 | import datetime 3 | import logging 4 | 5 | 6 | def short_wait(): 7 | time.sleep(1) 8 | -------------------------------------------------------------------------------- /zhiFuBaoGainPoints.py: -------------------------------------------------------------------------------- 1 | from util import * 2 | 3 | 4 | def gain_points(self): 5 | # 打开支付宝 6 | self.d.app_start("com.eg.android.AlipayGphone", wait=True) 7 | # 开app九宫锁 8 | if self.isAppLock: 9 | self.d.swipe_points(self.lockPoints, 0.2) 10 | short_wait() 11 | time.sleep(20) 12 | # 先点击去首页 13 | if self.d.xpath('//*[@text="首页"]').exists: 14 | self.d.xpath('//*[@text="首页"]').click() 15 | short_wait() 16 | # 搜索框点击 17 | if self.d.xpath('//*[@resource-id="com.alipay.mobile.base.commonbiz:id/home_title_search_button"]').exists: 18 | self.d.xpath('//*[@resource-id="com.alipay.mobile.base.commonbiz:id/home_title_search_button"]').click() 19 | short_wait() 20 | else: 21 | logging.error("搜索框定位不到") 22 | return 23 | # 输入《领积分》搜索 24 | self.d.xpath('//*[@resource-id="com.alipay.mobile.antui:id/search_bg"]').set_text("领积分") 25 | short_wait() 26 | # 点击搜索按钮 27 | if self.d.xpath('//*[@text="搜索"]').exists: 28 | self.d.xpath('//*[@text="搜索"]').click() 29 | short_wait() 30 | else: 31 | logging.error("搜索按钮定位不到") 32 | return 33 | # 进入搜索结果 34 | if self.d.xpath('//*[@text="支付宝会员"]').exists: 35 | short_wait() 36 | self.d.xpath('//*[@text="支付宝会员"]').click() 37 | else: 38 | logging.error("领积分搜索结果的进入字样定位不到") 39 | return 40 | time.sleep(15) 41 | if self.d.xpath('//*[@text="领积分"]').exists: 42 | short_wait() 43 | self.d.xpath('//*[@text="领积分"]').click() 44 | time.sleep(5) 45 | else: 46 | logging.error("领积分按钮定位不到") 47 | return 48 | while self.d.xpath('//*[@text="点击领取"]').exists: 49 | short_wait() 50 | self.d.xpath('//*[@text="点击领取"]').click() 51 | short_wait() 52 | 53 | # 结束关闭支付宝 54 | self.d.app_stop("com.eg.android.AlipayGphone") -------------------------------------------------------------------------------- /zhiFuBaoTo2019.py: -------------------------------------------------------------------------------- 1 | from util import * 2 | 3 | 4 | def zhi_fu_bao_platform(self): 5 | # 打开支付宝 6 | self.d.app_start("com.eg.android.AlipayGphone", wait=True) 7 | # 开app九宫锁 8 | if self.isAppLock: 9 | self.d.swipe_points(self.lockPoints, 0.2) 10 | short_wait() 11 | time.sleep(20) 12 | # 先点击去首页 13 | if self.d.xpath('//*[@text="首页"]').exists: 14 | self.d.xpath('//*[@text="首页"]').click() 15 | short_wait() 16 | if self.d.xpath('//*[@resource-id="com.alipay.android.phone.openplatform:id/home_advertisement"]').exists: 17 | self.d.xpath('//*[@resource-id="com.alipay.android.phone.openplatform:id/home_advertisement"]').click() 18 | else: 19 | logging.error("首页活动找不到入口") 20 | return 21 | # 等待界面出现完整 22 | # self.d.xpath('//*[@text="双11合伙人,全民开喵铺,瓜分20亿红包"]').wait(20) 23 | self.d(text="活动攻略").wait(20) 24 | # if self.d.xpath('//*[@text="双11合伙人,全民开喵铺,瓜分20亿红包"]').exists: 25 | if self.d(text="活动攻略").exists: 26 | while True: 27 | # 收喵币和升级 28 | # zhi_fu_bao_platform_cat_coins(self) 29 | # 做任务 30 | # zhi_fu_bao_platform_cat_tasks(self) 31 | # 长按获得翻倍豆 32 | zhi_fu_bao_platform_play_red_bag(self) 33 | else: 34 | logging.error("双11支付宝活动页面打不开!") 35 | return 36 | 37 | 38 | def zhi_fu_bao_platform_play_red_bag(self): 39 | time.sleep(5) 40 | if self.d(text="继续玩").exists: 41 | self.d(text="继续玩").click() 42 | self.d.long_click(0.5, 0.5) 43 | 44 | 45 | def zhi_fu_bao_platform_cat_coins(self): 46 | if self.d.xpath('//*[@text="关闭"]').exists: 47 | self.d.xpath('//*[@text="关闭"]').click() 48 | time.sleep(1) 49 | # 收喵币 50 | self.d.click(0.498, 0.682) 51 | time.sleep(1) 52 | # 升级领红包 53 | if self.d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.widget.Button[2]').exists: 54 | self.d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.widget.Button[2]').click() 55 | time.sleep(5) 56 | # 关闭升级页面 57 | if self.d.xpath('//*[@text="开心收下"]').exists: 58 | self.d.xpath('//*[@text="开心收下"]').click() 59 | if self.d.xpath('//*[@text="关闭"]').exists: 60 | self.d.xpath('//*[@text="关闭"]').click() 61 | else: 62 | logging.error("升级领红包的位置定位不到") 63 | return 64 | time.sleep(2) 65 | if self.d.xpath('//*[@text="关闭"]').exists: 66 | self.d.xpath('//*[@text="关闭"]').click() 67 | 68 | 69 | def zhi_fu_bao_platform_cat_tasks(self): 70 | # 点击领喵币 71 | if self.d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.widget.Button[3]').exists: 72 | self.d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.widget.Button[3]').click() 73 | else: 74 | logging.error("领喵币的位置定位不到") 75 | return 76 | time.sleep(2) 77 | # 签到 78 | if self.d.xpath('//*[@text="签到"]').exists: 79 | logging.info("还没签到") 80 | self.d.xpath('//*[@text="签到"]').click() 81 | time.sleep(2) 82 | # 关闭签到提醒页,进入支日历 83 | if self.d.xpath('//*[@text="开心收下"]').exists: 84 | self.d.xpath('//*[@text="开心收下"]').click() 85 | time.sleep(2) 86 | if self.d.xpath('//*[@resource-id="com.alipay.mobile.nebula:id/h5_rl_title"]').exists: 87 | logging.info("进入了支日历") 88 | time.sleep(2) 89 | # 退回领喵币中心 90 | self.d.press("back") 91 | logging.info("退出支日历") 92 | time.sleep(1) 93 | if self.d.xpath('//*[@text="关闭"]').exists: 94 | self.d.xpath('//*[@text="关闭"]').click() 95 | elif self.d.xpath('//*[@text="去浏览"]').exists: 96 | self.d.xpath('//*[@text="去浏览"]').click() 97 | time.sleep(5) 98 | self.d.press("back") 99 | short_wait() 100 | if self.d.xpath('//*[@text="关闭"]').exists: 101 | self.d.xpath('//*[@text="关闭"]').click() 102 | elif self.d.xpath('//*[@text="去浇水"]').exists: 103 | self.d.xpath('//*[@text="去浇水"]').click() 104 | time.sleep(5) 105 | self.d(scrollable=True).scroll.to(description="查看更多好友") 106 | if self.d.xpath("//*[contains(@text, '查看更多好友')]").exists: 107 | self.d.xpath("//*[contains(@text, '查看更多好友')]").click() 108 | else: 109 | logging.error("《查看更多好友》定位不到") 110 | return 111 | short_wait() 112 | self.d.xpath('//*[@resource-id="J_rank_list_append"]/android.view.View[1]').click() 113 | time.sleep(1) 114 | self.d.xpath('//*[@text="浇水"]').click() 115 | time.sleep(2) 116 | if self.d.xpath( 117 | '//android.webkit.WebView/android.view.View[1]/android.view.View[2]/android.view.View[1]').exists: 118 | self.d.xpath( 119 | '//android.webkit.WebView/android.view.View[1]/android.view.View[2]/android.view.View[1]').click() 120 | short_wait() 121 | self.d.press("back") 122 | short_wait() 123 | self.d.press("back") 124 | short_wait() 125 | self.d.press("back") 126 | short_wait() 127 | if self.d.xpath('//*[@text="关闭"]').exists: 128 | self.d.xpath('//*[@text="关闭"]').click() 129 | elif self.d.xpath('//*[@text="去完成"]').exists: 130 | self.d.xpath('//*[@text="去完成"]').click() 131 | time.sleep(5) 132 | self.d.press("back") 133 | short_wait() 134 | if self.d.xpath('//*[@text="关闭"]').exists: 135 | self.d.xpath('//*[@text="关闭"]').click() 136 | elif self.d.xpath('//*[@text="关闭"]').exists: 137 | self.d.xpath('//*[@text="关闭"]').click() 138 | time.sleep(5) 139 | if self.d.xpath('//*[@text="关闭"]').exists: 140 | self.d.xpath('//*[@text="关闭"]').click() 141 | --------------------------------------------------------------------------------