微信发消息自动化

adb按键顺序


1.启动微信
adb shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI

2. 模拟点击指定位置
adb shell input tap 284 1240
adb shell input tap 424 642
adb shell input tap 399 757

adb shell input tap 245 1254
adb shell input tap 680 702
adb shell input tap 552 689
adb shell input tap 683 621

3. 模拟点击“返回键”
adb shell input keyevent 4
adb shell input keyevent 4
adb shell input keyevent 4

环境搭建

1、 安装python运行环境

2、 安装adb工具,并设置adb环境变量

3、 将手机用数据线连接至电脑(可连接多个)

4、 手机的锁屏设置关掉、微信正常登录、搜狗更新至2019版本

5、双击执行此脚本

步骤

1、python脚本调用adb

2、adb检测当前的手机设备

3、adb模拟按键点击事件

代码

#!/usr/bin/env python3

# -*- coding: UTF-8 -*-

import os
import subprocess
import time
import random

def getdevs():
        out = subprocess.Popen(
                'adb devices'.split(),
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE
        ).communicate()[0]
        devs = []
        filters = [b'list', b'of', b'device', b'devices', b'attached']
        for item in out.split():
                
                if item.lower() not in filters:
                        devs.append(item)
        return devs

class test_phone:
        '测试手机'
        devnum = ''
        linkx = {'a': {1: True}, 
                        'c': {1: True},
                        'h': {1: False},
                        'j': {1: False},
                        'm': {1: True, 2: True, 3: True},
                        #'n': {1: True}
                         }

        def __init__(self, devnum):
                self.devnum = devnum

        # 唤醒手机
        def wake_up_phone(self):
                cmd = 'adb -s %s shell input keyevent 26' % self.devnum.decode().strip()
                os.system(cmd)
                return 

        # 打开微信
        def openwx(self):
                cmd = 'adb -s %s shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI' % self.devnum.decode().strip()
                os.system(cmd)
                return 

        # 打开联系人a 1
        def open_linkman_x_n(self, x = 'a', n = 1, m = True):
                cmd = 'adb -s %s shell input tap 284 1240' % self.devnum.decode().strip()
                os.system(cmd)
                if (x == 'a'):
                        cmd = 'adb -s %s shell input tap 710 257' % self.devnum.decode().strip()
                elif (x == 'c'):
                        cmd = 'adb -s %s shell input tap 710 340' % self.devnum.decode().strip()
                elif (x == 'h'):
                        cmd = 'adb -s %s shell input tap 710 487.6' % self.devnum.decode().strip()
                elif (x == 'j'):
                        cmd = 'adb -s %s shell input tap 710 550.5' % self.devnum.decode().strip()
                elif (x == 'm'):
                        cmd = 'adb -s %s shell input tap 710 652.5' % self.devnum.decode().strip()
                elif (x == 'n'):
                        cmd = 'adb -s %s shell input tap 710 695.5' % self.devnum.decode().strip()
                os.system(cmd)
                if (n == 1):
                        cmd = 'adb -s %s shell input tap 220 239' % self.devnum.decode().strip()
                elif (n == 2):
                        cmd = 'adb -s %s shell input tap 429 344' % self.devnum.decode().strip()
                elif (n == 3):
                        cmd = 'adb -s %s shell input tap 405 451' % self.devnum.decode().strip()
                os.system(cmd)
                if (m):
                        cmd = 'adb -s %s shell input tap 156.8 750' % self.devnum.decode().strip()
                else:
                        cmd = 'adb -s %s shell input tap 156.8 650' % self.devnum.decode().strip()
                os.system(cmd)
                return

        # 发送搜狗信息
        def send_sougou_ms(self):
                cmd = 'adb -s %s shell input tap 245 1254' % self.devnum.decode().strip()
                os.system(cmd)
                #time.sleep(5)
                cmd = 'adb -s %s shell input tap 680 702' % self.devnum.decode().strip()
                os.system(cmd)
                #time.sleep(5)
                cmd = 'adb -s %s shell input tap 552 689' % self.devnum.decode().strip()
                os.system(cmd)
                cmd = 'adb -s %s shell input tap 683 621' % self.devnum.decode().strip()
                os.system(cmd)
                return

        # 返回三次
        def wx_back(self, n = 3):
                cmd = 'adb -s %s shell input keyevent 4' % self.devnum.decode().strip()
                while n:
                        n -= 1
                        os.system(cmd)
                return


devs = getdevs()

while True:
        for item in devs:
                # 创建手机
                phone = test_phone(item)
                # 唤醒手机
                phone.wake_up_phone()
                # 打开微信
                phone.openwx()

                # 打开微信联系人x n
                x = random.sample(phone.linkx.keys(), 1)
                n = random.sample(phone.linkx[x[0]].keys(), 1)
                phone.open_linkman_x_n(x[0], n[0], phone.linkx[x[0]][n[0]])

                # 发送搜狗消息
                phone.send_sougou_ms()
                # 返回桌面
                phone.wx_back()
                # 关闭手机
                phone.wake_up_phone()
        # 随机间隔时间
        s = random.randint(100,10000)
        while (s):
                print('\r等待时长:%d s' % s, end = '')
                s -= 1
                time.sleep(1)
  • 15
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随风而来j

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值