Micro-mail PHP custom menu, how to Solve

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.