php 微信公众号开发之 三 自定义菜单

<?php  
header("Content-type: text/html; charset=utf-8"); 
//ID 密钥  
$appid = "
appid 
"; $appsecret = "
appsecret 
"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $output = https_request($url); $jsoninfo = json_decode($output, true); //返回 一个数组 //[html] view plain copy//7200 var_dump($jsoninfo); //[html] view plain copy$access_token = $jsoninfo["access_token"]; //d定义菜单的格式 $jsonmenu='{ "button":[ { "type":"view", "name":"目录1", "url":"http://wx.test.com/i.php" }, { "type":"view", "name":"目录2", "url":"http://wx.test.com/i.php" }, { "type":"view", "name":"目录3", "url":"http://wx.test.com/i.php" }] }'; $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token; $result = https_request($url, $jsonmenu); //[html] view plain copyvar_dump($result); function https_request($url,$data = null){ $curl = curl_init(); //$data=iconv('GB2312','UTF-8',$data);$encode = mb_detect_encoding($data, array('ASCII','UTF-8','GB2312','GBK','BIG5')); if ($encode!='UTF-8'){$data=iconv('GB2312','UTF-8',$data);} echo $data; curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json", "Content-Type: text/xml; charset=utf-8")); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; } echo '成功'; ?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值