跳到主要内容
CNode

新玩具!微信Nodejs版,可编程控制微信消息

分享
Iifeiteng发布于 10 年前最后回复 9 年前
1689430

前言

过年的时候加入了泰稳大大主持的精进学堂 读书运动群,并主动请缨进入了策划组,因为要实行积分制,所以作为coder的我提出做一个群机器人,于是便有了这个项目,我也是近一阵才开始分析网页版微信的各种参数,所以还不太健全,欢迎pr 群

安装

npm install weixinbot --save

实例

// Require Nodejs v4+

// index.js
const Weixinbot = require('weixinbot')

// will send qrcode to your email address
const bot = new Weixinbot({ receiver: '[email protected]' })

// will emit when bot fetch a new qrcodeUrl
bot.on('qrcode', (qrcodeUrl) => {
  console.log(qrcodeUrl)
})

bot.on('friend', (msg) => {
  console.log(msg.Member.NickName + ': ' + msg.Content)
  bot.sendText(msg.FromUserName, 'Got it')
})

bot.run()

运行

# 建议打开DEBUG标志,以便查看详细信息
DEBUG=weixinbot node index.js

项目地址

查看回复

回复 (16)

F
fightAndLearn#169 年前

mark From Noder

Y
YingjieChen#159 年前

群消息呢??

N
naruto900814#1410 年前

mark

I
imfly#1310 年前

不错

A
alsotang#1210 年前

好东西

I
ifeiteng#1110 年前

@leizongmin +1

X
XGHeaven#910 年前

挺有意思的

来自酷炫的 CNodeMD

L
leizongmin#810 年前
const qrcode = require('qrcode-terminal');

// 直接在控制台上打印二维码
bot.on('qrcode', (qrcodeUrl) => {
  qrcode.generate(qrcodeUrl.replace('/qrcode/', '/l/'), console.log);
});
L
leizongmin#710 年前

接收好友消息时有问题,比如有时候消息内容msg.Content是这样的:

&lt;msg&gt;<br/>&lt;op id='5'&gt;<br/>&lt;username&gt;919338054@chatroom&lt;/username&gt;<br/>&lt;/op&gt;<br/>&lt;/msg&gt;

应该是没有正确解析XML导致的。

Y
yuanzhhh#610 年前

mark

S
stonexer#510 年前

@reverland 嗯啊,那个看上去是在微信 webapp 基础上的吧。

R
reverland#410 年前
S
stonexer#310 年前

@reverland 哈哈哈哈,坐等第三方客户端

R
reverland#210 年前

微信干脆开放api好了2333 @stonexer 来看看

I
i5ting#110 年前

挺好的,写的比较规范,就是单个文件内代码太多,适当拆分一下

参与回复

登录后即可参与回复。登录