PHP custom Menu
I applied for a public platform test account, has passed the verification, after the attention with my number to the test account to send messages can get the correct response of the test account, I now want to implement the custom menu, the following replace my test account AppID and secret, I entered the test account did not see the custom menu, Where is the problem, please?
/**
* WeChat PHP Test
*/
Define your Token
Define ("TOKEN", "Weixin");
$token _url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=***&secret=***" ;
$data = "{
"Button": [
{
"Type": "Click",
"Name": "Song of the Day",
"Key": "V1001_today_music"
},
{
"Type": "Click",
"Name": "Introduction to the singer",
"Key": "V1001_today_singer"
},
{
"Name": "Menu",
"Sub_button": [
{
"Type": "Click",
"Name": "Hello word",
"Key": "V1001_hello_world"
},
{
"Type": "Click",
"Name": "Praise Us",
"Key": "V1001_good"
}]
}]
}";
$WECHATOBJ = new Wechatcallbackapitest ();
$WECHATOBJ->post ($WECHATOBJ->get_access_token (), $data);
Class Wechatcallbackapitest
{
Public Function Get_access_token () {
$json =http_request_json ($token _url);
$data =json_decode ($json, true);
if ($data [' Access_token ']) {
return $data [' Access_token '];
}else{
Return "Get Access_token error";
}
}
Public Function Http_request_json ($url) {
$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);
$result = curl_exec ($ch);
Curl_close ($ch);
return $result;
}
Public Function post ($access _token, $jsonData) {
$ch = Curl_init ("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=". $access _token);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_customrequest, "POST");
curl_setopt ($ch, Curlopt_postfields, $jsonData);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_httpheader, Array (' Content-type:application/json '));
$result = curl_exec ($ch);
Curl_close ($ch);
return $result;
}
}
?>
Share to: more