Nodejs 微信开发 自定义菜单
var map = require('../router-config').getMapping() , wechat = require('wechat') , fs = require('fs'); var API = wechat.API , appid = 'xxx' , secret = 'xxxx'; var api = new API(appid, secret); var router = express.Router(); router.use('/', wechat('wechatToken', function(req, res, next) { var menu = fs.readFileSync('./node-app/config/wechat-menu.json'); if(menu) { menu = JSON.parse(menu); } api.createMenu(menu, function(err, result){}); // 微信输入信息都在req.weixin上 var message = req.weixin; var msgType = message.MsgType; if(msgType == 'event'){ var eventType = message.Event; if(eventType) { eventType = eventType.toLowerCase(); } if(eventType == 'subscribe') { // 新用户关注/订阅事件 subscribeEvent(res); } else if(eventType == 'click') { clickEvent(message, res); } else { notFoundEvent(eventType, res); } }
wechat-menu.json
{ "button": [ { "name": "我的账号", "sub_button": [ { "type": "click", "name": "我的帐户", "key": "V1001_MY_ACCOUNT" }, { "type": "click", "name": "已投项目", "key": "V1002_BID_PROJECTS" }, { "type": "click", "name": "回款计划", "key": "V1003_RETURN_PLAN" }, { "type": "click", "name": "交易明细", "key": "V1004_TRANS_DETAIL" }, { "type": "click", "name": "注册/绑定", "key": "V1005_REGISTER_BIND" } ] }, { "type": "view", "name": "马上投资", "url": "http://qiaole.sinaapp.com/" }, { "name": "送钱活动", "sub_button": [ { "type": "view", "name": "注册送红包", "url": "http://qiaole.sinaapp.com/" }, { "type": "click", "name": "邀请好友一起赚钱", "key": "V1001_GOOD" }, { "type": "view", "name": "加入我们", "url": "http://qiaole.sinaapp.com/" }, { "type": "view", "name": "APP下载", "url": "http://qiaole.sinaapp.com/" } ] } ] }
相关推荐
jieq 2020-11-09
ZZZhangbingyi 2020-08-26
haixianTV 2020-08-15
Develop 2020-06-25
郴州小程序 2020-06-13
huningjun 2020-06-12
zuoliangzhu 2020-06-11
hgzhang 2020-06-04
浪味仙 2020-06-03
powderhose 2020-06-02
cdkey 2020-05-29
戴翔的技术 2020-05-27
郴州小程序 2020-05-26
cdkey 2020-05-26
sucheng 2020-05-25
newhappy 2020-05-16
cbao 2020-05-12
cbao 2020-04-26
草根工程师 2020-03-27