import itchat
import timeimport random# 登录微信itchat.auto_login(hotReload=True) # hotReload=True避免重复扫码# 获取好友列表friends = itchat.get_friends(update=True)# 发送消息给所有好友def send_to_all(message): for friend in friends: try: # 添加随机延迟避免被检测为机器人 time.sleep(random.uniform(0.5, 1.5)) itchat.send(message, toUserName=friend[‘UserName’]) print(f"已发送给: {friend[‘NickName’]}") except Exception as e: print(f"发送给 {friend[‘NickName’]} 失败: {e}")# 使用示例if name == “main”: message = “这是一条测试消息,请勿回复!” send_to_all(message) print(“消息发送完成!”)
微信群发消息Python代码
最新推荐文章于 2025-10-20 22:13:05 发布
该文章已生成可运行项目,
本文章已经生成可运行项目
697

被折叠的 条评论
为什么被折叠?



