设置自定义菜单
最后更新于:2022-04-01 20:00:29
自定义菜单和自动回复不一样,自动回复是需要接收微信转发到服务器的请求和事件
所以不需要http服务器,只需要将请求发送给微信api接口就可以了
代码用wechat-api实现也比较方便
需要node 一下的js文件
~~~
var config = require('./config');
var API = require('wechat-api');
var api = new API(config.appid, config.appsecret);
/*null
{ accessToken: 'bMawBdyY5idQLeX_-ODTWZVhOd51yIklU3oYPeeLTg_8BmqrmUAEEvszsKGDLconZxHOx6Nwd32W50X7ThzBWzgOCQanOeg4Vwv3xMhN7KU',
expireTime: 1445244891114 }
{ errcode: 0, errmsg: 'ok' }*/
api.getAccessToken(function (err, token) {
console.log(err);
console.log(token);
});
var menu = JSON.stringify(require('./fixture/wx_menu.json'));
api.createMenu(menu, function (err, result) {
console.log(result);
});
~~~
config.js
~~~
/**
* Created by tangxuelong on 15-10-19.
*/
module.exports = {
appid : "wx01ca1966fe6f8a88",
appsecret : "ecedd0e93feccac893b05b67f5fe8538"
}
~~~
菜单的json文件
~~~
{
"button":[
{
"type":"click",
"name":"今日歌曲",
"key":"V1001_TODAY_MUSIC"
},
{
"type":"click",
"name":"歌手简介",
"key":"V1001_TODAY_SINGER"
},
{
"name":"菜单",
"sub_button":[
{
"type":"view",
"name":"搜索",
"url":"http://www.soso.com/"
},
{
"type":"view",
"name":"视频",
"url":"http://v.qq.com/"
},
{
"type":"click",
"name":"赞一下我们",
"key":"V1001_GOOD"
}
]
}
]
}
~~~
';