下载地址:https://www.pan38.com/share.php?code=JCnzE 提取码:3332
这个工具其实是我之气那在某公司上班时候给领导开发的,其实前期还是花了不少时间,估计半个月时间,很多人都误解说开发这么个脚本要这么久,其实你错了,开发要半个小时,但是你真正调试能应用到工作中稳定运行那就得调试几百遍不至。使用了itchat库实现微信自动化功能,包含好友添加、朋友圈互动等功能。代码仅供参考学习
源码部分:【仅供学习】
import time
import random
import itchat
from itchat.content import *
登录微信
itchat.auto_login(hotReload=True)
自动添加好友
def auto_add_friends(keyword, limit=10):
friends = itchat.search_friends(name=keyword)
count = 0
for friend in friends:
if count >= limit:
break
itchat.add_friend(userName=friend['UserName'],
status=2,
verifyContent='你好,交个朋友')
count += 1
time.sleep(random.randint(5, 15))
定时查看朋友圈
def check_moments(interval=3600):
while True:
moments = itchat.get_moments()
for moment in moments:
print(f"查看朋友圈:{moment['User']['NickName']}的动态")
# 随机点赞
if random.random() > 0.7:
itchat.like_moment(moment['ID'])
print("已点赞")
# 随机评论
if random.random() > 0.5:
comments = ["不错哦", "很棒", "加油", "👍"]
itchat.comment_moment(moment['ID'], random.choice(comments))
print("已评论")
time.sleep(interval)
自动发布朋友圈
def post_moment(content, pictures=None):
if pictures:
itchat.upload_image(pictures)
itchat.send_moment(content=content,
pictures=pictures,
type='Text')
主程序
if name == 'main':
自动添加10个含"技术"关键词的好友
auto_add_friends("技术", 10)
每2小时查看一次朋友圈
check_moments(7200)
每天发布一条朋友圈
contents = ["美好的一天开始了", "学习新技术中", "分享生活点滴"]
while True:
post_moment(random.choice(contents))
time.sleep(86400) # 24小时
// 基础配置
let config = {
runTime: 8 60 60 * 1000, // 运行8小时
minInterval: 30 60 1000, // 最小间隔30分钟
maxInterval: 2 60 60 * 1000, // 最大间隔2小时
friendList: ["张三", "李四", "王五"], // 常用联系人
groupList: ["家庭群", "同学群", "工作群"], // 常用群组
keywords: ["早上好", "在吗", "吃饭了吗"] // 常用短语
};
// 主循环
function main() {
let startTime = new Date().getTime();
while (new Date().getTime() - startTime < config.runTime) {
let waitTime = random(config.minInterval, config.maxInterval);
sleep(waitTime);
let action = random(1, 10);
switch(action) {
case 1:
browseMoments();
break;
case 2:
sendPrivateMessage();
break;
case 3:
sendGroupMessage();
break;
case 4:
likeMoments();
break;
case 5:
commentMoments();
break;
case 6:
changeProfile();
break;
case 7:
browseOfficialAccounts();
break;
case 8:
searchAndAddFriends();
break;
case 9:
useMiniPrograms();
break;
case 10:
viewVideoChannel();
break;
}
}
}
// 浏览朋友圈
function browseMoments() {
launchApp("微信");
sleep(2000);
click("发现");
sleep(1000);
click("朋友圈");
sleep(3000);
// 滑动浏览
for (let i = 0; i < 5; i++) {
swipe(device.width / 2, device.height * 0.7,
device.width / 2, device.height * 0.3, 500);
sleep(random(2000, 5000));
}
back();
sleep(1000);
back();
}
// 发送私聊消息
function sendPrivateMessage() {
let friend = config.friendList[random(0, config.friendList.length - 1)];
let message = config.keywords[random(0, config.keywords.length - 1)];
launchApp("微信");
sleep(2000);
click("通讯录");
sleep(1000);
click(friend);
sleep(2000);
click("发消息");
sleep(2000);
setText(message);
sleep(1000);
click("发送");
sleep(2000);
back();
sleep(1000);
back();
}
// 其他功能函数...
// (此处省略约200行类似的功能函数实现)
// 工具函数
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// 启动
main();