采用分层设计:主控模块+功能模块+配置模块实现两种添加方式:手机号精确添加和群聊成员添加加入定时控制和防检测机制(随机延迟)建议配合免root权限工具使用下载地址:https://pan38.com/share.php?code=XJy5Y 提取码:8888 【仅供学习参考】
代码语言:txt复制/**
* AutoJS微信自动化脚本
* 功能:定时通过手机号/群聊批量添加好友
* 环境要求:Android 7.0+,AutoJS 4.1.1+
*/
const _VERSION = "v2.5";
let config = {
delay: 3000, // 操作间隔(ms)
maxRetry: 3, // 单次失败重试次数
schedule: [ // 定时执行配置
{start: "09:00", end: "12:00"},
{start: "14:00", end: "18:00"}
]
};
// 主入口
function main() {
prepareEnv();
while (true) {
if (checkTimeValid()) {
executeBatchAdd();
sleep(config.delay * 10);
}
sleep(60000); // 每分钟检查时间
}
}
// 环境检测
function prepareEnv() {
auto.waitFor();
if (!requestScreenCapture()) {
toast("请开启屏幕截图权限");
exit();
}
console.show(); // 调试控制台
}
// 定时检测
function checkTimeValid() {
let now = new Date();
let hhmm = now.getHours() + ":" + now.getMinutes();
return config.schedule.some(t => hhmm >= t.start && hhmm <= t.end);
}
// 核心添加逻辑
function executeBatchAdd() {
let targets = loadTargets(); // 加载待添加号码/群聊
targets.forEach(target => {
if (target.type === "phone") {
addByPhone(target.value);
} else if (target.type === "group") {
addFromGroup(target.value);
}
});
}
// 手机号添加实现
function addByPhone(phone) {
launchApp("微信");
click("通讯录", 0);
click("添加朋友", 0);
setText(phone);
click("搜索", 0);
if (id("send_request").exists()) {
click("发送添加朋友申请");
setText("您好,我是" + device.getAndroidId());
click("发送");
log("已发送申请至:" + phone);
} else {
log("未找到用户:" + phone);
}
}
// 群聊添加实现
function addFromGroup(groupName) {
launchApp("微信");
click("通讯录", 0);
click("群聊", 0);
let group = text(groupName).findOne(config.delay);
if (group) {
group.click();
click("群成员", 0);
// 模拟滑动查找目标用户
for (let i = 0; i < 5; i++) {
if (click("添加", 0)) {
setText("商务合作请求");
click("发送");
log("群成员添加成功");
break;
}
swipe(device.width/2, device.height*0.7,
device.width/2, device.height*0.3, 500);
}
}
}
// 加载待处理数据
function loadTargets() {
return [
{type: "phone", value: "13800138000"},
{type: "group", value: "AI技术交流群"}
]; // 实际使用时应替换为文件读取
}
main();核心部分:
代码语言:txt复制/**
* 配置文件解析模块
* 格式:JSON文件存储待添加目标
*/
function readConfig() {
let path = "/sdcard/wechat_add_config.json";
if (!files.exists(path)) {
toast("请先在/sdcard/创建配置文件");
exit();
}
try {
return JSON.parse(files.read(path));
} catch (e) {
toast("配置文件格式错误");
exit();
}
}
// 示例配置文件内容:
/*
{
"targets": [
{"type": "phone", "value": "13800138001"},
{"type": "group", "value": "技术讨论组"}
],
"message": "您好,请通过好友申请"
}
*/