hefei

微信创建自定义菜单接口使用

$appid = \'wxec6048a219896101\';
$appsecret = \'8c8b85a2ff2b94450aa7311b24b914f2\';
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";    //微信获取access_token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output, true);
if(isset($result[\'errcode\'])){
	echo $result[\'errmsg\'];exit;
}
$access_token = $result[\'access_token\'];
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$access_token";    //创建菜单
$data = [
	\'button\' => [
		[  
			\'name\' => \'易新秀\',
			\'type\' => \'view\',
			\'url\' => \'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx571acec999998ebe&redirect_uri=http%3a%2f%2fm.yixinxiu2016.com/index.php/Index/weixin/menu&response_type=code&scope=snsapi_base&state=2#wechat_redirect\'
		],
		[
			\'name\' => \'魔法互动\',
			\'type\' => \'view\',
			\'url\' => \'http://mp.weixin.qq.com/mp/homepage?__biz=MzIzMTUyOTYwNg==&hid=1&sn=19b6cb836d4fca34f129d7636551748f#wechat_redirect\'
		],
		[
			\'name\' => \'个人中心\',
			\'sub_button\' => [
				[
					\'name\' => \'我的订单\',
					\'type\' => \'view\',
					\'url\' => \'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx571acec999998ebe&redirect_uri=http%3a%2f%2fm.yixinxiu2016.com/index.php/Index/weixin/menu&response_type=code&scope=snsapi_base&state=account-user_order#wechat_redirect\'
					],
				[
					\'name\' => \'我的收藏\',
					\'type\' => \'view\',
					\'url\' => \'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx571acec999998ebe&redirect_uri=http%3a%2f%2fm.yixinxiu2016.com/index.php/Index/weixin/menu&response_type=code&scope=snsapi_base&state=account-user_collect_designer#wechat_redirect\',
					],
				[
					\'name\' => \'客服热线\',
					\'type\' => \'view\',
					\'url\' => \'http://mp.weixin.qq.com/s?__biz=MzIzMTUyOTYwNg==&mid=100000630&idx=1&sn=aadfa8b79d23aac5f490db8be91c3356&scene=18#wechat_redirect\'
				],
			] 
		]
	]
];
$data = json_encode($data, JSON_UNESCAPED_UNICODE);	//中文菜单需要编码,否则会报错
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;

  

分类:

技术点:

相关文章: