upload
This commit is contained in:
@@ -0,0 +1,318 @@
|
||||
# -*- encoding=utf8 -*-
|
||||
__author__ = "Administrator"
|
||||
|
||||
import json
|
||||
import random
|
||||
import time
|
||||
import uiautomator2 as u2
|
||||
import adbutils
|
||||
import pymysql
|
||||
import subprocess
|
||||
from multiprocessing import Pool, Manager
|
||||
|
||||
from 来喜 import wsapi
|
||||
|
||||
|
||||
class Jx:
|
||||
def __init__(self, device_uri):
|
||||
self.device_uri = device_uri
|
||||
# 从device_uri中提取设备序列号
|
||||
self.device_serial = device_uri.split('///')[-1]
|
||||
|
||||
# 连接设备
|
||||
self.d = u2.connect(self.device_serial)
|
||||
|
||||
# 获取屏幕尺寸
|
||||
info = self.d.info
|
||||
self.width = info['displayWidth']
|
||||
self.height = info['displayHeight']
|
||||
|
||||
# 设置滑动起始和结束点
|
||||
self.start_pt1 = (int(self.width / 2), int(self.height * 0.8))
|
||||
self.end_pt1 = (int(self.width / 2), int(self.height * 0.1))
|
||||
|
||||
# 设置操作超时时间
|
||||
self.d.settings['operation_delay'] = (0, 1)
|
||||
self.d.settings['operation_delay_methods'] = ['click', 'swipe']
|
||||
|
||||
def wait_and_click(self, selector, timeout=10):
|
||||
"""等待元素出现并点击"""
|
||||
try:
|
||||
if self.d(text=selector).wait(timeout=timeout):
|
||||
self.d(text=selector).click()
|
||||
time.sleep(0.2)
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"点击元素 {selector} 失败: {e}")
|
||||
return False
|
||||
|
||||
def element_exists(self, selector):
|
||||
"""检查元素是否存在"""
|
||||
try:
|
||||
return self.d(text=selector).exists
|
||||
except:
|
||||
return False
|
||||
|
||||
def swipe_up(self, duration=200):
|
||||
"""向上滑动"""
|
||||
try:
|
||||
self.d.swipe(self.start_pt1[0], self.start_pt1[1],
|
||||
self.end_pt1[0], self.end_pt1[1],
|
||||
duration=duration / 1000.0)
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
print(f"滑动失败: {e}")
|
||||
|
||||
def random_click(self):
|
||||
"""随机点击屏幕"""
|
||||
try:
|
||||
x = random.randint(int(self.width * 0.2), int(self.width * 0.8))
|
||||
y = random.randint(int(self.height * 0.3), int(self.height * 0.7))
|
||||
self.d.click(x, y)
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
print(f"随机点击失败: {e}")
|
||||
|
||||
def gai_jx(self):
|
||||
"""修改机型"""
|
||||
try:
|
||||
if not self.wait_and_click("设备参数修改与伪装", 5):
|
||||
print("未找到设备参数修改与伪装按钮")
|
||||
return False
|
||||
|
||||
if not self.wait_and_click("仓库", 5):
|
||||
print("未找到仓库按钮")
|
||||
return False
|
||||
|
||||
# 上滑N次
|
||||
for i in range(random.randint(1, 15)):
|
||||
self.swipe_up()
|
||||
|
||||
# 随机点击直到找到"使用"按钮
|
||||
max_attempts = 20
|
||||
attempts = 0
|
||||
while attempts < max_attempts:
|
||||
self.random_click()
|
||||
if self.element_exists("使用"):
|
||||
print("找到使用按钮")
|
||||
return True
|
||||
attempts += 1
|
||||
time.sleep(0.5)
|
||||
|
||||
print("未找到使用按钮")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"修改机型失败: {e}")
|
||||
return False
|
||||
|
||||
def gai_wx(self):
|
||||
"""修改微信标识"""
|
||||
try:
|
||||
# 如果安卓ID修改不存在,先滑动
|
||||
if not self.element_exists("安卓ID修改"):
|
||||
self.swipe_up(1000)
|
||||
|
||||
if not self.wait_and_click("安卓ID修改", 5):
|
||||
print("未找到安卓ID修改按钮")
|
||||
return False
|
||||
|
||||
# 寻找微信按钮
|
||||
max_attempts = 10
|
||||
attempts = 0
|
||||
while attempts < max_attempts:
|
||||
if self.element_exists("微信"):
|
||||
if self.wait_and_click("微信", 3):
|
||||
if self.wait_and_click("随机修改", 3):
|
||||
break
|
||||
else:
|
||||
self.swipe_up()
|
||||
attempts += 1
|
||||
|
||||
# 返回上一级
|
||||
if self.element_exists("转到上一层级"):
|
||||
self.wait_and_click("转到上一层级", 3)
|
||||
elif self.d(description="转到上一层级").exists:
|
||||
self.d(description="转到上一层级").click()
|
||||
else:
|
||||
# 使用返回键
|
||||
self.d.press("back")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"修改微信标识失败: {e}")
|
||||
return False
|
||||
|
||||
def main(self, model):
|
||||
"""主要执行函数"""
|
||||
try:
|
||||
# 停止并启动应用
|
||||
self.d.app_stop('com.byyoung.setting')
|
||||
time.sleep(2)
|
||||
self.d.app_start('com.byyoung.setting')
|
||||
time.sleep(3)
|
||||
self.d.shell("settings put system accelerometer_rotation 0")
|
||||
|
||||
# 等待应用启动
|
||||
if not self.d(packageName='com.byyoung.setting').wait(timeout=10):
|
||||
print("应用启动失败")
|
||||
return self.device_uri
|
||||
|
||||
# 点击导航
|
||||
if not self.wait_and_click("导航", 5):
|
||||
print("未找到导航按钮")
|
||||
return self.device_uri
|
||||
|
||||
# 点击系统相关
|
||||
if not self.wait_and_click("系统相关", 5):
|
||||
print("未找到系统相关按钮")
|
||||
return self.device_uri
|
||||
|
||||
# 根据模式执行不同操作
|
||||
success = True
|
||||
if model == 1: # 全部改
|
||||
success = self.gai_wx() and self.gai_jx()
|
||||
elif model == 2: # 只改微信标识
|
||||
success = self.gai_wx()
|
||||
elif model == 3: # 只改机型
|
||||
success = self.gai_jx()
|
||||
|
||||
if not success:
|
||||
print(f"操作失败,模式: {model}")
|
||||
return self.device_uri
|
||||
|
||||
# 清除poco服务数据
|
||||
try:
|
||||
self.d.shell("pm clear com.netease.open.pocoservice")
|
||||
except:
|
||||
pass
|
||||
|
||||
return (self.device_uri,)
|
||||
|
||||
except Exception as e:
|
||||
print(f"{self.device_uri}出现错误: {e}")
|
||||
return self.device_uri
|
||||
|
||||
|
||||
def work(device_uri, model=1):
|
||||
"""工作函数"""
|
||||
try:
|
||||
jx = Jx(device_uri)
|
||||
return jx.main(model)
|
||||
except Exception as e:
|
||||
print(f"设备 {device_uri} 初始化失败: {e}")
|
||||
return device_uri
|
||||
|
||||
|
||||
def get_group():
|
||||
"""获取设备分组"""
|
||||
groups = wsapi.main()
|
||||
groups_id = {}
|
||||
n = 1
|
||||
for i in list(groups.keys()):
|
||||
groups_id[n] = i
|
||||
print(f"{n}:{i}")
|
||||
n += 1
|
||||
|
||||
try:
|
||||
choice = int(input("请选择一个分组: "))
|
||||
if choice in groups_id:
|
||||
group = groups[groups_id[choice]]
|
||||
return group
|
||||
else:
|
||||
print("无效选择")
|
||||
return []
|
||||
except ValueError:
|
||||
print("请输入有效数字")
|
||||
return []
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("=== Android设备参数修改工具 (uiautomator2版本) ===")
|
||||
|
||||
# 检查ADB连接
|
||||
try:
|
||||
adb = adbutils.AdbClient(host="127.0.0.1", port=5037)
|
||||
devices = adb.device_list()
|
||||
print(f"检测到 {len(devices)} 台设备")
|
||||
except Exception as e:
|
||||
print(f"ADB连接失败: {e}")
|
||||
return
|
||||
|
||||
# 获取设备分组
|
||||
group = get_group()
|
||||
if not group:
|
||||
print("未选择有效分组")
|
||||
return
|
||||
|
||||
# 选择操作模式
|
||||
print("\n操作模式:")
|
||||
print("1. 全部改")
|
||||
print("2. 只改微信标识")
|
||||
print("3. 只改机型")
|
||||
|
||||
try:
|
||||
model = int(input("请输入你的选择: "))
|
||||
if model not in [1, 2, 3]:
|
||||
print("无效选择")
|
||||
return
|
||||
except ValueError:
|
||||
print("请输入有效数字")
|
||||
return
|
||||
|
||||
# 使用进程池处理
|
||||
with Pool() as p:
|
||||
tasks = []
|
||||
print(f"\n开始处理 {len(group)} 台设备...")
|
||||
|
||||
for device_name in group:
|
||||
device_uri = f'Android:///{device_name}'
|
||||
result = p.apply_async(work, args=(device_uri, model))
|
||||
tasks.append(result)
|
||||
|
||||
print(f"设备总数: {len(group)}")
|
||||
print("-" * 50)
|
||||
|
||||
# 获取所有任务结果
|
||||
fail = []
|
||||
success_devices = []
|
||||
|
||||
for i, task in enumerate(tasks):
|
||||
try:
|
||||
result = task.get(timeout=300) # 5分钟超时
|
||||
if isinstance(result, tuple):
|
||||
device_uri = result[0]
|
||||
success_devices.append(device_uri)
|
||||
print(f"✓ {device_uri} 操作成功")
|
||||
else:
|
||||
device_uri = result
|
||||
fail.append(device_uri)
|
||||
print(f"✗ {device_uri} 操作失败")
|
||||
except Exception as e:
|
||||
device_uri = f'Android:///{group[i]}'
|
||||
fail.append(device_uri)
|
||||
print(f"✗ {device_uri} 处理异常: {e}")
|
||||
|
||||
# 输出统计结果
|
||||
print("\n" + "=" * 50)
|
||||
print(f"处理完成!")
|
||||
print(f"总设备数: {len(group)}")
|
||||
print(f"成功设备数: {len(success_devices)}")
|
||||
print(f"失败设备数: {len(fail)}")
|
||||
|
||||
if success_devices:
|
||||
print(f"\n成功设备列表:")
|
||||
for device in success_devices:
|
||||
print(f" - {device}")
|
||||
|
||||
if fail:
|
||||
print(f"\n失败设备列表:")
|
||||
for device in fail:
|
||||
print(f" - {device}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user