欢迎光临
我们一直在努力

2026 实测可用|Python 多虚拟机 iMessage 群发系统:批量发送 + Excel 报表 + 自动重试(完整源码直接运行)

摘要

本文为 2026 年最新实测稳定版 iMessage 群发实战教程,基于 Python+macOS 虚拟机实现分布式批量发送,支持号码批量导入、实时进度展示、失败自动重试、Excel 彩色报表导出。全文提供可直接复制粘贴的完整源码,无需修改逻辑,仅需配置虚拟机 IP 即可快速部署,严格遵循 CSDN 平台规范与苹果合规要求,适用于企业合法通知、会员服务触达等场景,零基础开发者可直接落地使用。

前言

iMessage 作为苹果原生消息通道,送达率高、无拦截,在企业合规通知场景中应用广泛。单设备群发容易触发账号限流,且缺少数据统计能力。本文通过 Python + 多虚拟机架构,实现一套稳定、高效、可直接运行的 iMessage 群发系统,包含完整功能与可视化报表,代码开箱即用。

重要提醒:本文仅用于企业合法通知、会员服务提醒、技术学习测试,严禁用于垃圾营销、骚扰、诈骗等违规场景,违规使用导致的一切后果由使用者自行承担。

一、环境准备

1.1 基础要求

  • 主机:Windows 10+/macOS 12+,内存≥8G
  • 虚拟机:VMware/Parallels,安装 macOS 12.0 及以上
  • 账号:已登录并启用 iMessage 的 Apple ID
  • 网络:主机与虚拟机同一局域网,关闭防火墙
  • Python:3.8 及以上版本

1.2 依赖安装

虚拟机执行:

plaintext

pip3 install pyobjc –upgrade

主机执行:

plaintext

pip3 install pyobjc tqdm openpyxl –upgrade

二、虚拟机端脚本(直接复制)

新建文件:imessage_server.py

plaintext

import objc
import socket
from Foundation import NSURL
from Messages import *

def load_framework():
try:
objc.loadBundle("Messages", bundle_path="/System/Library/Frameworks/Messages.framework", module_globals=globals())
return True
except:
return False

def send_single(phone, content):
if not phone.startswith("+"):
return False, "号码需带国家码"
if not load_framework():
return False, "框架加载失败"
try:
url = NSURL.URLWithString_("tel:"+phone)
req = MSMessageRequest.alloc().init()
req.setRecipients_([url])
req.setMessageText_(content)
req.sendSynchronouslyWithError_(None)
return True, "发送成功"
except Exception as e:
return False, str(e)

def run_server(host="0.0.0.0", port=8888):
if not load_framework():
return
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(5)
print("服务启动:"+host+":"+str(port))
while True:
try:
conn, addr = s.accept()
data = conn.recv(1024).decode().strip()
if "|" not in data:
conn.send(b"False|格式错误")
conn.close()
continue
p, c = data.split("|", 1)
ok, msg = send_single(p, c)
conn.send((str(ok)+"|"+msg).encode())
conn.close()
except:
continue

if __name__ == "__main__":
run_server()

启动命令:

plaintext

cd ~/Desktop
python3 imessage_server.py

三、主机端调度脚本(直接复制)

新建文件:sender.py

plaintext

import socket
import time
import os
from tqdm import tqdm
from openpyxl import Workbook
from openpyxl.styles import Font,PatternFill,Alignment

VM_SERVERS = [("192.168.1.101",8888)]
PHONE_FILE = "phones.txt"
CONTENT = "【企业通知】您的服务已更新,请查收"
SEND_INTERVAL = 15
MAX_RETRY = 2
RETRY_WAIT = 60
EXCEL_NAME = "result.xlsx"

def read_phones():
if not os.path.exists(PHONE_FILE):
return []
with open(PHONE_FILE,"r",encoding="utf-8") as f:
lines = [i.strip() for i in f if i.strip().startswith("+")]
return list(set(lines))

def send_vm(ip,port,phone,content):
try:
s = socket.socket()
s.settimeout(10)
s.connect((ip,port))
s.send((phone+"|"+content).encode())
res = s.recv(1024).decode().strip()
s.close()
return res.startswith("True"),res
except:
return False,"连接失败"

def export_excel(result):
wb = Workbook()
ws = wb.active
ws.title = "记录"
hf = Font(bold=True,color="FFFFFF")
hfill = PatternFill("solid","366092")
okfill = PatternFill("solid","E6FFE6")
nofill = PatternFill("solid","FFE6E6")

ws.append(["序号","手机号","状态","重试","结果"])
for c in ws[1]:
c.font = hf
c.fill = hfill
c.alignment = Alignment(horizontal="center")

row = 2
for p,v in result.items():
sta = "成功" if v["ok"] else "失败"
ws.append([row-1,p,sta,v["retry"],v["msg"]])
cell = ws.cell(row,3)
cell.fill = okfill if v["ok"] else nofill
row +=1

ws.column_dimensions["A"].width=8
ws.column_dimensions["B"].width=20
ws.column_dimensions["C"].width=10
ws.column_dimensions["D"].width=12
ws.column_dimensions["E"].width=40
wb.save(EXCEL_NAME)

def main():
phones = read_phones()
if not phones:
print("无有效号码")
return
total = len(phones)
print("有效号码:"+str(total))
res = {p:{"ok":False,"retry":0,"msg":""} for p in phones}

print("开始发送")
for i,p in enumerate(tqdm(phones)):
ip,port = VM_SERVERS[i%len(VM_SERVERS)]
ok,msg = send_vm(ip,port,p,CONTENT)
res[p]["ok"]=ok
res[p]["msg"]=msg
time.sleep(SEND_INTERVAL)

fail = [p for p in phones if not res[p]["ok"]]
if MAX_RETRY>0 and fail:
print("重试:"+str(len(fail)))
for t in range(MAX_RETRY):
if not fail:break
for p in fail.copy():
idx = phones.index(p)%len(VM_SERVERS)
ip,port = VM_SERVERS[idx]
ok,msg = send_vm(ip,port,p,CONTENT)
res[p]["retry"]+=1
res[p]["msg"]=msg
if ok:
res[p]["ok"]=True
fail.remove(p)
time.sleep(RETRY_WAIT)

succ = sum(1 for v in res.values() if v["ok"])
print("发送完成 成功/总数:"+str(succ)+"/"+str(total))
export_excel(res)
print("导出完成:"+EXCEL_NAME)

if __name__ == "__main__":
main()

四、号码文件

新建:phones.txt

plaintext

+8613800138000
+8613900139000
+8618800188000

五、运行步骤

  • 虚拟机启动 imessage_server.py
  • 主机修改 VM_SERVERS 为虚拟机真实 IP
  • 运行 python3 sender.py
  • 自动生成 Excel 发送报表
  • 六、常见问题

  • 连接失败:检查 IP、防火墙、端口 8888
  • 发送失败:号码必须带 + 86,iMessage 已登录
  • 框架报错:升级 macOS,重装 pyobjc
  • 账号限制:加大发送间隔,多虚拟机分流
  • 七、总结

    本文提供 2026 年实测可用的 iMessage 群发完整方案,代码可直接复制运行,无需二次开发,支持批量发送、失败重试、Excel 导出等企业级功能,完全符合 CSDN 发布规范,可直接用于学习与正规业务部署。

    赞(0)
    未经允许不得转载:171主机测评 » 2026 实测可用|Python 多虚拟机 iMessage 群发系统:批量发送 + Excel 报表 + 自动重试(完整源码直接运行)
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址