PHP生成公眾號菜單接口createmenu,可設(shè)置主菜單和子菜單,可添加鏈接或者小程序代碼,用戶掃企業(yè)公眾號二維碼,點(diǎn)擊菜單進(jìn)去小程序
首先獲取公眾號appid 和 appsecret,打開https://mp.weixin.qq.com/登錄進(jìn)入(開發(fā)->基本設(shè)置),IP白名單也要設(shè)置好,否則獲取不到access_token
主菜單和子菜單代碼設(shè)置(注意主菜單不能超過3個(gè))
$appid='wx422133b0b6bbfcfc'; //公眾號appid
$appsecret='559cc5a5e606dc473c47a'; //公眾號app密鑰
$wx = new WxService($appid,$appsecret);
$data[0]['name'] = array('素材火官網(wǎng)','view');//主菜單(1)
$data[1]['name'] = array('其他菜單','view');//主菜單(2)
$data[2]['name'] = array('素材火小程序','miniprogram',array("url"=>"https://www.sucaihuo.com","appid"=>"wxce2e7ecb9c1968b7","pagepath"=>"pages/index/index"));//主菜單(3)
$data[0]['sub_button'][0] = array('整站源碼','https://www.sucaihuo.com/source');//子菜單1-0
$data[0]['sub_button'][1] = array('視頻教程','https://www.sucaihuo.com/video');//子菜單1-1
$data[1]['sub_button'][0] = array('服務(wù)器','https://www.sucaihuo.com/servers');//子菜單2-0
$data[1]['sub_button'][1] = array('菜單1-2','http://www.jiuniao.com');//子菜單2-1
$data[1]['sub_button'][2] = array('菜單1-3','http://www.lanrenzhijia.com');//子菜單2-2
$data[1]['sub_button'][3] = array('菜單1-4小程序', 'miniprogram',array("url"=>"https://www.sucaihuo.com","appid"=>"wxce2e7ecb9c1968b7","pagepath"=>"pages/index/index"));//子菜單2-3
$result = $wx->menuCreate($data);
素材火就設(shè)置了一級主菜單,沒有子菜單
$data[0]['name'] = array('素材火官網(wǎng)','https://www.sucaihuo.com');//主菜單(1)
$data[1]['name'] = array('整站源碼','https://www.sucaihuo.com/source');//主菜單(2)
$data[2]['name'] = array('小程序','miniprogram',array("url"=>"https://www.sucaihuo.com","appid"=>"wxce2e7ecb9c1968b7","pagepath"=>"pages/index/index"));//主菜單(3)