自定义微信公众号菜单栏

  |  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs');
const superagent = require('superagent');
(async () => {

let accessTokenInfo = await superagent.get(`https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${web_appid}&secret=${web_appsecret}`).set('accept', 'json');
let { access_token = '', errcode, errmsg } = accessTokenInfo.body || {};

console.log('access_token========>', access_token);

// // 配置菜单
let button = [{
'name': '我是老师',
'type': 'miniprogram',
'url': 'http://mp.weixin.qq.com',
'appid': '',// 小程序appid
'pagepath': 'pages/course/course',// 打开小程序页面
}, {
'name': '更多服务',
'sub_button': [{
'name': '新手教程',
'type': 'view',// 打开网页 必须是公众号网页
'url': 'https://mp.weixin.qq.com/s?__biz=MzIzNjYzNjU2Ng==&mid=2247484035&idx=1&sn=4722bd94c29971726601fa963d3f9ec5&chksm=e8d5927adfa21b6c16d4139d255460fc2ddd19289637ac93f5bf1027bd9266c7d3586965ced2&token=1327323395&lang=zh_CN#rd',
}, {
'name': '人工客服',
'type': 'media_id',// 发送素材图片
'media_id': 'fxh1-aKLF1mBk4FWP4OgCdhRNZsck96l_rRaPN-SB08',
}],
}];
let url = `https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${access_token}`;
let result = await superagent.post(url).send({ button }).set('Accept-Encoding', 'gzip,sdch');

console.log('result==========>', result.body);


})();

文档:
自定义菜单栏
自定义上传素材获取 media_id

文章目录