安装python环境

1、安装Python需要的包

1.1电脑安装Android SDK Platform-Tools

pip install uiautomator2

1.2给手机安装ATX软件

2、运行脚本(抖音极速版,含签到和广告浏览)

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 19:24:06 2020
@author: FanGang
"""
 
 
 
import uiautomator2 as u2
import time
import random
 
d = u2.connect('192.168.3.86')
 
print('连接成功!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
 
 
def 滑动():
    d.swipe(0.5, 0.6, 0.5, 0.2)  # 滑动屏幕
    print('手机页面滑动成功!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
 
 
def 签到():
    # 来赚钱 点击页面跳转,针对1080分辨率
    try:
        d.click(0.500, 0.966)#点击
        time.sleep(3)
        d.swipe(0.5, 0.6, 0.5, 0.8)  # 滑动屏幕
        time.sleep(3)
        d.swipe(0.5, 0.6, 0.5, 0.8)  # 滑动屏幕
        print('已进入任务界面{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    except:
        print('未进入任务界面{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    
    try:
        #d.click(0.50, 0.678).click()
        try:
            d(description="去领取").click()#d.click(0.50, 0.678)#j将屏幕向下滑动两次后的坐标
        except:
            d(description="已领取").click()
        print('可能已进入整点广告,等待20秒{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        time.sleep(20)
        
        
        try:
            d(text="关闭广告").click()
            time.sleep(3)
        except:
            print('关闭广告失败{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            time.sleep(3)
        
    except:
        print('已领取过整点广告{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
 
    
    
    # 开宝箱
    try:
        d.click(0.863, 0.921)
        print('已完成点击开宝箱{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        time.sleep(3)
    # 看广告再赚
        try:
            
            #d(description="看广告视频再赚").click()
            d.click(0.50, 0.678)#j将屏幕向下滑动两次后的坐标
            print('可能已进入宝箱广告,等待20秒{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            time.sleep(20)
            d(text="关闭广告").click()
            print('已完成宝箱广告{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        except:
            print('无宝箱广告,等倒计时结束后再来领取吧{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    except:
        print('等倒计时结束后再来领取吧{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
 
    try:
        time.sleep(3)
        d(description="去赚钱").click()
        print('可以继续观看视频了!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    except:
        print('返回失败!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
 
 
 
def 运行(t1, t2):
    h = 3600
    while True:
        滑动()
        t = random.randint(t1, t2)
        print('将等待{}秒后继续……'.format(t))
        time.sleep(t)  # 暂停
        h = h + t
        print('距离下一次整点任务还剩{}秒'.format(3600-h))
        if h > 3600:
            # 签到看广告
            print('即将进入签到和广告浏览!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            签到()
            # 重置计时
            h = 0
        else:
            # print('继续!')
            pass
 
 
运行(1, 12)

3、抖音极速版脚本(版本2)

# -*- coding: utf-8 -*-
"""
Created on Fri Mar 27 20:39:34 2020
@author: FanGang
"""
 
import uiautomator2 as u2
import time
import random
 
 
 
class 手机:
    ip='192.168.3.85'
    t1=1
    t2=12
    h=3260
    正态分布平均时间=12
 
 
    def 启动(self):
        d = u2.connect(self.ip)
        #启动快手极速版
        d.app_start("com.ss.android.ugc.aweme.lite")
        #退出快手极速版
        #d.app_stop("com.kuaishou.nebula") #停止
 
 
    def 滑动(self):
        d = u2.connect(self.ip)
        d.swipe(0.5, 0.6, 0.5, 0.12)  # 滑动屏幕
        print('手机页面滑动成功!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
 
 
    def 签到(self):
        d = u2.connect(self.ip)
        # 来赚钱 点击页面跳转,针对1080分辨率
        try:
            d.click(0.500, 0.966)#点击
            time.sleep(3)
            d.swipe(0.5, 0.6, 0.5, 0.8)  # 滑动屏幕
            time.sleep(3)
            d.swipe(0.5, 0.6, 0.5, 0.8)  # 滑动屏幕
            print('已进入任务界面{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        except:
            print('未进入任务界面{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            
            
        
        try:
            #d.click(0.50, 0.678).click()
            try:
                d(description="去领取").click()#d.click(0.50, 0.678)#j将屏幕向下滑动两次后的坐标
            except:
                d(description="已领取").click()
            print('可能已进入整点广告,等待20秒。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            time.sleep(20)
            
            
            try:
                d(text="关闭广告").click()
                time.sleep(3)
            except:
                print('关闭广告失败。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
                time.sleep(3)
            
        except:
            print('已领取过整点广告。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    
        
        
        # 开宝箱
        try:
            d.click(0.863, 0.921)
            print('已完成点击开宝箱。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            time.sleep(3)
        # 看广告再赚
            try:
                
                #d(description="看广告视频再赚").click()
                d.click(0.50, 0.678)#j将屏幕向下滑动两次后的坐标
                print('可能已进入宝箱广告,等待20秒。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
                time.sleep(20)
                d(text="关闭广告").click()
                print('已完成宝箱广告。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            except:
                print('无宝箱广告,等倒计时结束后再来领取吧。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        except:
            print('等倒计时结束后再来领取吧。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    
        try:
            time.sleep(3)
            d(description="去赚钱").click()
            print('可以继续观看视频了!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        except:
            print('返回失败!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
            
    def 随机时间等待(self):
        t = random.randint(self.t1, self.t2)
        print('将等待{}秒后继续……'.format(t))
        self.h=self.h+t
        # print('self.h={}'.format(self.h))
        time.sleep(t)
        ct=3260-self.h
        if ct>0:
            print('距离下一次整点任务还剩{}秒!'.format(ct))
        else:
            print('即将进入整点任务。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    def 正态分布随机时间等待(self):
        mu=self.正态分布平均时间
        print('正态分布平均时间为:{}'.format(mu))
        sigma=6
        t = random.normalvariate(mu,sigma)
        #如果生成的随机时间不在指定范围,则重新按照正态分布生成随机时间
        while t<=0 or t>=15:
            t = random.normalvariate(mu,sigma)
        t=round(t,2)
        print('将等待{}秒后继续……'.format(t))
        self.h=self.h+t
        # print('self.h={}'.format(self.h))
        time.sleep(t)
        ct=3260-self.h
        ct=round(ct,2)
        if ct>0:
            print('距离下一次整点任务还剩{}秒!'.format(ct))
        else:
            print('即将进入整点任务。{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
 
 
 
def 运行():
    我的手机=手机()
    print('手机实例化完成!{}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    ip=input('请输入IP地址:')
    if ip=='':
        pass
    else:
        我的手机.ip=ip
    h=input('距离下一次签到时间间隔为(分钟):')
    if h=='':
        pass
    else:
        我的手机.h=3260-eval(h)*60
    print('已设置滑动连接为{}的手机屏幕,请保持手机处于抖音极速版视频浏览界面!\n'.format(手机.ip,time.strftime('%Y-%m-%d %H:%M:%S')))
    mu=input('输入正态分布时间:')
    if mu=='':
        print('未输入正态分布时间,程序将采用随机整数时间间隔!')
    else:
        我的手机.正态分布平均时间=eval(mu)
        
        
        
        
    try:
        我的手机.启动()
        print('抖音启动完成!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    except:
        print('抖音启动失败,请手动启动抖音!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    time.sleep(3)
    
    i=0
    while True:
        try:
            我的手机.启动()#每次屏幕滑动前保持抖音极速版处于启动状态
            我的手机.滑动()
            #如果未指定正态分布时间,则采用随机整数时间间隔
            if mu=='':
                我的手机.随机时间等待()
            else:
                我的手机.正态分布随机时间等待()
            # print('我的手机.h={}秒'.format(我的手机.h))
            if 我的手机.h > 3260:
                # 签到看广告
                print('即将进入签到和广告浏览!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
                我的手机.签到()
                time.sleep(3)
                # 重置计时
                我的手机.h = 0
            else:
                # print('继续!')
                pass
        except:
            i=i+1
            print('操作失败,开始第{}次重试!'.format(i))
 
运行()

4、运行脚本(快手极速版,随机正态分布时间滑动)

# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 13:58:47 2020
@author: FanGang
"""
 
import uiautomator2 as u2
import time
import random
 
 
ip=input('请输入局域网手机IP:')
 
d = u2.connect(ip)
 
print('IP:{}连接成功!{}'.format(ip,time.strftime('%Y-%m-%d %H:%M:%S')))
 
 
def 滑动():
    d.swipe(0.5, 0.6, 0.5, 0.12)  # 滑动屏幕
    print('{}手机页面滑动成功!{}'.format(ip,time.strftime('%Y-%m-%d %H:%M:%S')))
    
def 运行(mu, sigma):
    # 正态分布。 mu 是平均值,sigma 是标准差。
    while True:
        滑动()
        t=random.normalvariate(mu,sigma)
        while t<=0:
            #当随机数小于0,重新生成随机数
            t=random.normalvariate(mu,sigma)
        t=round(t,2)
        #对随机数保留两位小数
        print('将等待{}秒后继续……'.format(t))
        time.sleep(t)  # 暂停
 
 
mu=10
sigma=6
运行(mu, sigma)

5、类的使用(屏幕滑动,正态分布时间间隔)

# -*- coding: utf-8 -*-
"""
Created on Sun Mar 15 10:38:08 2020
@author: FanGang
"""
 
import uiautomator2 as u2
import time
import random
 
# 定义一个手机类
class 手机:
    '''
    mu=M
    '''
    def 时间等待(self,正态分布平均时间):
        mu=正态分布平均时间
        sigma=6
        t=random.normalvariate(mu,sigma)
        while t<=0 or t>=35:
            t=random.normalvariate(mu,sigma)
        # t=4
        while t>0:
            t=round(t,2)
            time.sleep(0.08)
            print('\r剩余等待时间:{:>5}秒'.format(str(t)),end='')
            t=t-0.08
 
    #
    def 向上滑动屏幕(self,IP地址):
        连接 = u2.connect(IP地址)
        连接.swipe(0.5, 0.6, 0.5, 0.12)  # 滑动屏幕
        print('\r手机页面滑动成功!{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        
 
 
def main():
    print('请输按照提示输入程序参数。')
    IP=input('地址(IP):')
    M=input('时长(秒):')
    if IP=='' or M=='':
        IP="192.168.3.85"
        M=12
        print('\n默认参数如下:\n局域网IP:{}\n平均时长:{}秒\n'.format(IP,M))
        
    else:
        M=eval(M)
        print('\n程序参数如下:\n局域网IP:{}\n平均时长:{}秒\n'.format(IP,M))
        
    我的手机=手机()
    print('手机实例化完成!{}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    while True:
        我的手机.向上滑动屏幕(IP)
        我的手机.时间等待(M)
        
if __name__ == "__main__":
    main()

6、类的使用版本(版本2)

# -*- coding: utf-8 -*-
"""
Created on Sun Mar 15 10:38:08 2020
@author: FanGang
"""
 
import uiautomator2 as u2
import time
import random
 
# 定义一个手机类
class 手机:
    '''
    mu=M
    '''
    IP地址="192.168.137.74"
    正态分布平均时间=12
    软件='快手极速版'
 
    def 时间等待(self):
        mu=self.正态分布平均时间
        # print(mu)
        sigma=6
        t=random.normalvariate(mu,sigma)
        while t<=0 or t>=12:
            t=random.normalvariate(mu,sigma)
        # t=4
        while t>0:
            t=round(t,2)
            time.sleep(0.08)
            print('\r剩余等待时间:{:>5}秒'.format(str(t)),end='')
            t=t-0.08
 
    #
    def 向上滑动屏幕(self):
        连接 = u2.connect(self.IP地址)
        连接.swipe(0.5, 0.88, 0.5, 0.12)  # 滑动屏幕
        print('\r手机{}页面滑动成功!{}'.format(self.软件,time.strftime('%Y-%m-%d %H:%M:%S')))
        
    def 启动软件(self):
        连接 = u2.connect(self.IP地址)
        if self.软件=='快手极速版':
            #启动快手极速版
            连接.app_start("com.kuaishou.nebula")
            #退出快手极速版
            # d.app_stop("com.kuaishou.nebula") #停止
        elif self.软件=='抖音极速版':
            #启动抖音极速版
            连接.app_start("com.ss.android.ugc.aweme.lite")
            #退出抖音极速版
            # 连接.app_stop("com.ss.android.ugc.aweme.lite") #停止
 
        else:
            pass
        time.sleep(3)
        
 
 
def main(): 
    我的手机=手机()
    # 可变更的对象属性
    print('请输按照提示输入程序参数。')
    IP=input('输入手机地址(IP):')
    if IP=='':
        pass
    else:
        手机.IP地址=IP#对IP重新赋值
        
        
        
    M=input('输入滑动间隔时长(秒):')
    if M=='':
        pass
    else:
        手机.正态分布平均时间=eval(M)#对间隔正态分布平均时间重新赋值
        
    软件=input('输入软件名称:')
    if 软件=='':
        pass
    else:
        手机.软件=软件
    
    
    
    
    手机.IP地址
    手机.正态分布平均时间
    手机.软件
    print('即将滑动连接为{}的手机{}屏幕,平均时间为{}秒\n'.format(手机.IP地址,手机.软件,手机.正态分布平均时间))
    print('手机实例化完成!{}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
    print('----------ok----------')
 
    i=0
    while True:
        try:
            我的手机.启动软件()#软件
            我的手机.向上滑动屏幕()
            我的手机.时间等待()
        except:
            i=i+1
            print('开始第{}次重新开始'.format(i))
            print('即将滑动连接为{}的手机{}屏幕,平均时间为{}秒\n'.format(手机.IP地址,手机.软件,手机.正态分布平均时间))
        
        
if __name__ == "__main__":
    main()

————————————————