AdonisJs开发微信自动回复Demo
发布于 7 年前 作者 wxs77577 4253 次浏览 来自 分享

AdonisJs本身并没有什么微信开发框架,但NodeJs有。所以NodeJs界大名鼎鼎的 Webot 开发的微信插件稍加改动即可直接使用。

安装

安装node-webot/wechat

cnpm install wechat --save

微信测试号

https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index 申请一个并填入正确的信息

本地3333端口开放公网访问

中国的ngrok: https://www.ngrok.cc/https://www.ngrok.cc/ 注册一个账号,配置一下信息,映射到本地 3333端口

AdonisJs 路由代码

Route.any('/wechat/server', function *(request, response) {
	const wechat = require('wechat')
	let config = {
		token: 'keyboardcat123',
		appid: 'wx60263a4de4789f44',
		encodingAESKey: null,
		checkSignature: false
	};
	let req = request.request
	let res = response.response
	req.query = request.get()
	wechat(config, function (req, res, next) {
		let message = req.weixin;
		console.log(message)
		res.reply('https://adonis-china.org')
	})(req, res)
})

调试

  • 手机上关注测试号直接说话,可以看到电脑上终端输出message对象,并收到https://adonis-china.org回复。
  • 用微信接口调试工具调试,效果一样。https://mp.weixin.qq.com/debug/
  • node-webot/webot-cli调试

webot-cli调试

安装

npm install webot-cli -g

使用

命令行运行

webot send t --des http://localhost:3333/wechat/server haha
希望大家喜欢AdonisJs

原文: https://adonis-china.org/posts/10

5 回复

中国的ngrok: https://www.ngrok.cc/ 这个不错, 调试 Webhook 之类的方便多了…

@magicdawn 是的,而且还免费

@magicdawn 还不如localtunnel呢

@i5ting 好东西,试试看

回到顶部