张芷铭的个人博客

微信未开放自动化接口,实现定时发送消息需通过第三方框架或模拟操作,存在封号风险。

需求场景

  • 定时发送消息到微信群
  • 接入大语言模型辅助聊天筛选

方案对比

方案适用场景风险稳定性
Python + itchat电脑常开低(微信更新易失效)
Auto.js 安卓自动化手机/模拟器
企业微信 Webhook企业群

方案一:Python + itchat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import itchat
from datetime import datetime
import time

itchat.auto_login(hotReload=True)

def send_scheduled_msg():
    group = itchat.search_chatrooms(name="群名称")[0]
    itchat.send("定时消息", toUserName=group['UserName'])

while True:
    if datetime.now().strftime("%H:%M") == "09:00":
        send_scheduled_msg()
        time.sleep(60)
    time.sleep(30)

注意:itchat 已停止维护,可能无法登录新版微信。

方案二:Auto.js 安卓自动化

1
2
3
4
5
6
7
8
setInterval(function() {
    if (new Date().getHours() === 9 && new Date().getMinutes() === 0) {
        launchApp("微信");
        click("群聊名称");
        setText("定时消息内容");
        click("发送");
    }
}, 60000);

要求:授予无障碍权限,保持屏幕常亮。

方案三:企业微信 Webhook(推荐)

1
2
3
4
5
6
import requests

webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY"

payload = {"msgtype": "text", "text": {"content": "定时消息"}}
requests.post(webhook_url, json=payload)

优势:官方接口,合规稳定,无封号风险。

风险提示

  • 非官方 API 触发微信风控可能导致封号
  • 微信更新可能导致脚本失效
  • 建议用小号测试,企业场景优先选择企业微信方案

Comments