微信公众号 - 自定义菜单

公众号可通过API创建自定义菜单,支持点击推事件、跳转网页、扫码等多种类型。

菜单类型

类型 type值 说明
点击推事件 click 点击后推送event事件到开发者服务器
跳转URL view 点击后跳转到指定网页
扫码推事件 scancode_push 点击后调起扫码功能
发送位置 location_select 点击后弹出地理位置选择器
小程序 miniprogram 点击后打开指定小程序

创建菜单 - API调用

async function createMenu() { const token = await getAccessToken() const menu = { button: [ { type: 'click', name: '今日签到', key: 'SIGN_IN' }, { name: '服务中心', sub_button: [ { type: 'view', name: '个人中心', url: 'https://example.com/user' }, { type: 'click', name: '联系客服', key: 'CONTACT_US' }, { type: 'scancode_push', name: '扫码', key: 'SCAN' } ] }, { type: 'view', name: '官方网站', url: 'https://example.com' } ] } await axios.post( `https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${token}`, menu ) }
← Mp Message Mp Webpage →