首頁  >  文章  >  後端開發  >  微信 php 自定义菜单,该如何解决

微信 php 自定义菜单,该如何解决

WBOY
WBOY原創
2016-06-13 11:43:18786瀏覽

微信 php 自定义菜单
我申请了一个微信公众平台的测试账号,之前已经通过验证,关注后用我的微信号向测试账号发消息可以得到测试账号的正确响应,我现在想实现微信的自定义菜单,下面用***代替了我测试账号的appid和secret,我进测试账号没看到自定义菜单,请问问题出在哪?

<br /><?php<br />/**<br />  * wechat php test<br />  */<br /><br />//define your token<br />define("TOKEN", "weixin");<br /><br />$token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=***&secret=***";<br /><br />$data = "{<br />     "button":[<br />     {	<br />          "type":"click",<br />          "name":"今日歌曲",<br />          "key":"V1001_TODAY_MUSIC"<br />      },<br />      {<br />           "type":"click",<br />           "name":"歌手简介",<br />           "key":"V1001_TODAY_SINGER"<br />      },<br />      {<br />           "name":"菜单",<br />           "sub_button":[<br />            {<br />               "type":"click",<br />               "name":"hello word",<br />               "key":"V1001_HELLO_WORLD"<br />            },<br />            {<br />               "type":"click",<br />               "name":"赞一下我们",<br />               "key":"V1001_GOOD"<br />            }]<br />       }]<br /> }";<br /><br />$wechatObj = new wechatCallbackapiTest();<br />$wechatObj->post($wechatObj->get_access_token(), $data);<br /><br />class wechatCallbackapiTest<br />{	<br />	public function get_access_token(){  <br />        $json=http_request_json($token_url);<br />        $data=json_decode($json,true);  <br />        if($data['access_token']){  <br />            return $data['access_token'];  <br />        }else{  <br />            return "获取access_token错误";  <br />        }         <br />    }  <br />	<br />    public function http_request_json($url){    <br />        $ch = curl_init();  <br />        curl_setopt($ch, CURLOPT_URL,$url);  <br />        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  <br />        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  <br />        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  <br />        $result = curl_exec($ch);  <br />        curl_close($ch);  <br />        return $result;    <br />    }  <br />	<br />	public function post($access_token, $jsonData){<br />		$ch = curl_init("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token) ;<br />		curl_setopt($ch, CURLOPT_POST, 1);<br />		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");<br />		curl_setopt($ch, CURLOPT_POSTFIELDS,$jsonData);<br />		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br />		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));<br /><br />		$result = curl_exec($ch) ;<br />		curl_close($ch) ;<br />		return $result;<br />	}<br />}<br /><br />?><br />

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn