WeChat php custom menu solution

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? & Lt ;? Ph 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;
}
}

?>

------ Solution --------------------
I remember the menu has an example in the official document.
As for debugging, the official website will throw an error number to facilitate your judgment.
------ Solution --------------------
Reference:
Quote: reference:

I remember the menu has an example in the official document.
As for debugging, the official website will throw an error number to facilitate your judgment.

The official error should be thrown on the server, but it will not be directly thrown on the interface. I just asked where I went to see the error on the server.


According to my experience, after an API is called, there should be a callback... callback.
------ Solution --------------------
Reference:
Another question is, how can I debug such php Development? where can I see the log on the server (that is, the echo value )? I am a server built with xampp

Debugging has a platform for debugging on the developer platform. However, I feel that it is best to handle program errors by myself, in this way, you can know where your problem is based on the information on the debugging platform. I personally like PHP, this is my blog http://www.ihuxu.com, hope to communicate more.
Related Article

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.