随时随地发送消息到微信

2017-06-08 18:23:40 +08:00
 rapospectre

Wechat_Sender

随时随地发送消息到微信

简介

wechat_sender 是基于 wxpytornado 实现的一个可以将你的网站、爬虫、脚本等其他应用中各种消息 (日志、报警、运行结果等) 发送到微信的工具

初衷

wxpy 基于 itchat 提供了较为完备的微信个人号 API,而我想使用个人微信来接收我的网站的报警信息以及一些爬虫的结果,因此我写了这个工具。

安装

pip install wechat_sender

运行环境

Python 2.7 及以上 Python 3 及以上

使用

  1. 登录微信并启动 wechat_sender 服务.
from wxpy import *
from wechat_sender import *
bot = Bot()
listen(bot)
# 之后 wechat_sender 将持续运行等待接收外部消息
  1. 在外部向微信发送消息.
from wechat_sender import Sender
Sender().send('Hello From Wechat Sender')
# Hello From Wechat Sender 这条消息将通过 1 中登录微信的文件助手发送给你

如果你是 wxpy 的使用者,只需更改一句即可使用 wechat_sender:

例如这是你本来的代码:

# coding: utf-8
from __future__ import unicode_literals

from wxpy import *
bot = Bot('bot.pkl')

my_friend = bot.friends().search('xxx')[0]

my_friend.send('Hello WeChat!')

@bot.register(Friend)
def reply_test(msg):
    msg.reply('test')

bot.join()

使用 wechat_sender:

# coding: utf-8
from __future__ import unicode_literals

from wxpy import *
from wechat_sender import listen
bot = Bot('bot.pkl')

my_friend = bot.friends().search('xxx')[0]

my_friend.send('Hello WeChat!')

@bot.register(Friend)
def reply_test(msg):
    msg.reply('test')

listen(bot) # 只需改变最后一行代码

之后如果你想在其他程序或脚本中向微信发消息,只需要:

# coding: utf-8
from wechat_sender import Sender
Sender().send("Hello From Wechat Sender")

文档

http://wechat-sender.readthedocs.io/zh_CN/latest/

交流

扫描二维码,验证信息输入 ‘ wechat_sender ’ 或 ‘加群’ 进入微信交流群

5752 次点击
所在节点    程序员
15 条回复
coolloves
2017-06-08 19:08:59 +08:00
马克,感谢分享
torbrowserbridge
2017-06-08 19:17:05 +08:00
这个不错 马克
golmic
2017-06-08 20:08:10 +08:00
不错不错,支持一下
ihciah
2017-06-09 02:18:49 +08:00
似乎测试号也可以主动推消息,自用的话可能也够了
Spectre
2017-06-09 08:49:08 +08:00
支持支持~
rapospectre
2017-06-09 10:17:47 +08:00
@ihciah 微信公众平台测试号嘛?那个账号好像是有有效期的哦
rapospectre
2017-06-09 10:18:08 +08:00
@Spectre 哈哈,又看到你啦
rapospectre
2017-06-09 10:18:30 +08:00
@golmic 谢谢大兄弟
rapospectre
2017-06-09 10:18:41 +08:00
@torbrowserbridge 谢谢啦
rapospectre
2017-06-09 10:19:09 +08:00
@coolloves 谢谢支持
Jboys
2017-06-09 11:19:34 +08:00
大写的赞!
Z1076
2017-06-09 13:29:08 +08:00
向个人微信号发消息吗? 请问下这个是怎么实现的? 发消息的 API 我记得只有公众号里面发送
falcon05
2017-06-09 16:22:55 +08:00
我想起了 Server 酱
rapospectre
2017-06-09 18:35:58 +08:00
@Z1076 嗯嗯,是用 web 版微信接口做的
rapospectre
2017-06-09 18:36:50 +08:00
@falcon05 server 酱 是基于公众号做的哈,看来 server 酱在 v 站名气很大嘛

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/367030

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX