Skip to main content

Push your messages to wechat easily.

Project description

WechatPush

基于 企业微信 API 的微信消息推送, 无需自建服务器的 Python 库解决方案.

前言

很多时候编写程序时希望能将程序的运行结果实时告知开发者, 需要点对点的推送服务.

Telegram Bot 国内使用不便, 现有的微信推送大多需要使用第三方服务器, 接口调用有限制.

而此 Python 库有以下优点:

  • 无需自建服务器, 不使用第三方服务器, 无其他费用
  • 第一次需要配置(只需要个人微信), 之后可以直接调用, 简单方便
  • 无需安装企业微信客户端, 可以直接在微信接收推送
  • 调用次数充足, 限制少
  • 可以推送 文本, 超链接, 图片, 文件, Markdown 多种格式

配置(本步内容参考了 WecomChan 的相关文档)

配置过程中, 你需要记录下 corp_id secret 以及 agent_id 三个值.

  • 第一步,注册企业

    用电脑打开企业微信官网,注册一个企业

  • 第二步,创建应用

    注册成功后,点「管理企业」进入管理界面,选择「应用管理」 → 「自建」 → 「创建应用」

    img

    应用名称可以随意填入,应用logo自己上传一张图片,可见范围选择公司名。

    img

    创建完成后进入应用详情页,可以得到 agent_id,应用Secret( secret )。

    注意:secret推送到手机端时,只能在企业微信客户端中查看。

    img

  • 第三步,获取企业ID

    进入「我的企业」页面,拉到最下边,可以看到企业ID(corp_id)③,复制并填到上方。

    推送UID直接填 @all ,推送给公司全员。

  • 第四步,推送消息到微信

    进入「我的企业」 → 「微信插件」,拉到下边扫描二维码,关注以后即可收到推送的消息。

    img

    PS:如果出现接口请求正常,企业微信接受消息正常,个人微信无法收到消息的情况:

    进入「我的企业」 → 「微信插件」,拉到最下方,勾选 “允许成员在微信插件中接收和回复聊天消息” img

    在企业微信客户端 「我」 → 「设置」 → 「新消息通知」中关闭 “仅在企业微信中接受消息” 限制条件 img

安装

pip3 install wechat_push

示例

>>> from wechat_push import WechatPush
>>> push = WechatPush("你的corp_id", "你的secret", "你的agent_id")
>>> push.send_text('Hello!\n文本支持换行\n<a href="https://github.com">文本支持超链接</a>')
{'errcode': 0, 'errmsg': 'ok', 'msgid': 'xxx'}
>>> push.send_markdown("**Markdown here!**")
{'errcode': 0, 'errmsg': 'ok', 'msgid': 'xxx'}
>>> push.send_file(open("test.txt", "rb"), "微信中显示的文件名称")
{'errcode': 0, 'errmsg': 'ok', 'msgid': 'xxx'}
>>> push.send_image(open("test.png", "rb"))
{'errcode': 0, 'errmsg': 'ok', 'msgid': 'xxx'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wechat_push-1.0.1.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wechat_push-1.0.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file wechat_push-1.0.1.tar.gz.

File metadata

  • Download URL: wechat_push-1.0.1.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for wechat_push-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c20b52544db18240a76017b0ef6511bbe9e11b18888c2db8e812b7f8655ee56a
MD5 487754d2a2205c98b522188617da23fe
BLAKE2b-256 021f024333b2029d2fa8724c3d86f8e1a0721cd355e7d25c6a89ca7c404de0c0

See more details on using hashes here.

File details

Details for the file wechat_push-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: wechat_push-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for wechat_push-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 435656bdfbeb480917fb1fe4f183f5b5746497ffcba5b2fcea0a9f6b044d88f1
MD5 9af16ec4cd369bd10149d2e38d57af21
BLAKE2b-256 f3eaa7f468efef77675ccd6468c6e8417ad79083966b1290ab7e9565832825c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page