How to solve the custom menu of WeChat php

Source: Internet
Author: User
In the php user-defined menu, I applied for a public platform test account, which has passed verification before. after paying attention to it, I sent a message to the test account to get the correct response from the test account, the custom menu I want to implement now uses *** instead of the appid and secret of my test account. I did not see the custom menu in the test account. what is the problem? & L php custom menu
I have applied for a test account for the public platform. I have already passed the verification. after I followed the verification, I sent a message to the test account using my number to get the correct response from the test account, the custom menu I want to implement now uses *** instead of the appid and secret of my test account. I did not see the custom menu in the test account. what is the problem?


/**
* 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": "Today's songs ",
"Key": "V1001_TODAY_MUSIC"
},
{
"Type": "click ",
"Name": "Introduction to singers ",
"Key": "V1001_TODAY_SINGER"
},
{
"Name": "menu ",
"Sub_button ":[
{
"Type": "click ",
"Name": "hello word ",
"Key": "V1001_HELLO_WORLD"
},
{
"Type": "click ",
"Name": "Like 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 "an error occurred while obtaining access_token ";
}
}

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: 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.