我的核心写法,使用node
官方文档地址 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013
import * as client from 'superagent';
const createMenu = async function () {
// @ts-ignore
let access_token = await this.getGlobalToken();
const url = `https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${access_token}`;
const menu = [
{
"type": "view",
"name": "菜单名称",
"url": "http://xx.xxxx.wang"
}];
const data = await client.post(url).send({ button: menu }).catch(err => { console.log(err) });
// @ts-ignore
const result = JSON.parse(data.text);
return { code: 1, msg: '设置成功', data: result }
}