一个简单的自建微信推送服务

自建一个像「Server酱(server酱)」这样的微信推送服务,主要思路是:

  1. 接收你的程序发来的消息(一般是 HTTP 请求)。
  2. 将消息推送到你的微信。

✅ 实现方式概览

📌 一、准备工作

  1. 服务器(有公网 IP)
  2. 微信订阅号/服务号(用于发送消息)
    • Server酱用的是「企业微信」,我们也推荐用这个。

✅ 方案:用企业微信 + 自建推送接口(推荐)

企业微信允许机器人向用户/群组发送消息,适合做推送服务。


🔧 步骤详解:

第一步:创建企业微信机器人
  1. 进入企业微信管理后台(https://work.weixin.qq.com/)
  2. 创建一个「企业」
  3. 添加你自己为企业成员(用微信扫码加入)
  4. 进入“应用管理”,创建一个自建应用
    • 填写名称、logo 等
    • 获取:
      • CorpID
      • AgentID
      • Secret
第二步:写一个后端推送接口(示例 Python Flask)
# push.py
import requests
from flask import Flask, request, jsonify

app = Flask(__name__)

CORP_ID = '你的企业ID'
AGENT_ID = '你的应用AgentID'
SECRET = '你的Secret'

# 获取 access_token
def get_token():
    url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={SECRET}"
    return requests.get(url).json()['access_token']

# 发送消息
def send_msg(content, to_user='@all'):
    token = get_token()
    url = f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}"
    data = {
        "touser": to_user,
        "msgtype": "text",
        "agentid": AGENT_ID,
        "text": {
            "content": content
        },
        "safe": 0
    }
    res = requests.post(url, json=data)
    return res.json()

# 接收外部 HTTP 请求,转发微信
@app.route('/push', methods=['POST'])
def push():
    data = request.json
    content = data.get('text') or '空消息'
    res = send_msg(content)
    return jsonify(res)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

第三步:部署服务
# 安装 Flask
pip install flask requests

# 启动服务
python push.py
第四步:测试推送
curl -X POST http://yourip:5000/push \
     -H "Content-Type: application/json" \
     -d '{"text":"你好,这是一条来自自建推送服务的消息"}'

你的企业微信就会收到消息了!


注意:你需要进入企业微信里面我的应用设置白名单ip把服务器的ip添进去

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇