For the problem of submitting post data to https, please refer to the custom menu that you have made and it has never been successful. hope you can get some advice.
Interface Description
By posting a specific struct, you can create a custom menu on the client.
Request description
Http request method: POST
Https://api.weixin.qq.com/cgi-bin/menu/create? Access_token = ACCESS_TOKEN
Request example
{
"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"
}]
}]
}
My code is as follows:
$ Xjson = '{"button": [{"type": "click", "name": "todaymusic", "key": "V1001_TODAY_MUSIC "}, {"type": "click", "name": "singer", "key": "V1001_TODAY_SINGER" },{ "name": "menu", "sub_button ": [{"type": "click", "name": "hello word", "key": "V1001_HELLO_WORLD" },{ "type": "click ", "name": "best", "key": "V1001_GOOD"}]} '; $ url =" https://api.weixin.qq.com/cgi-bin/menu/create?access_token= * ***** "; $ Context = json_decode ($ xjson, true); $ data = http_build_query ($ context); $ result = vpost ($ url, $ data ); var_dump ($ result); function vpost ($ url, $ data) {// simulate the data submission function $ curl = curl_init (); // Start a CURL session curl_setopt ($ curl, CURLOPT_URL, $ url); // The address to be accessed curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, FALSE); // Check the certificate source curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, FALSE ); // check from the certificate whether the SSL encryption algorithm has curl_setopt ($ curl, CURLOPT_USERAGENT, 'mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0 )'); // simulate the user's browser // curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, 1); // use automatic redirect // curl_setopt ($ curl, CURLOPT_AUTOREFERER, 1 ); // automatically set Referer curl_setopt ($ curl, CURLOPT_POST, 1); // send a regular Post request curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data ); // Post the submitted data packet curl_setopt ($ curl, CURLOPT_TIMEOUT, 30); // Set the timeout limit to prevent endless loops curl_setopt ($ curl, CURLOPT_HEADER, 0 ); // display the returned Header content curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information returns $ tmpInfo = curl_exec ($ curl) as a file stream ); // execute the operation if (curl_errno ($ curl) {echo 'errno '. curl_error ($ curl); // catch an exception} curl_close ($ curl); // Close the CURL session return $ tmpInfo; // return data}
Failed, prompt "{" errcode ": 40016," errmsg ":" invalid button size "}"
Want to ask,
1. is there a problem with the code itself?
2. Does the local environment need to support https?
Reply to discussion (solution)
There is no problem with your program environment. The problem is that the POST data format has never been touched, so no useful information can be provided. this error indicates that there are more or less buttons in your json, we recommend that you try to add or remove the button element.
This prompt should be clear.
"{" Errcode ": 40016," errmsg ":" invalid button size "}"
Invalid button count
From the prompts, it does not look like a curl error, such as an api return. if so, it is clearly sent, but the data format is incorrect.
But there is another question: can https be directly sent?
Has the landlord solved the problem? I also reported the same error. The number of menus should be correct.
I am a programmer's home in Beijing. please contact me for details: 651732826
Hello! I also encountered this problem. have you solved it? Can you give me some advice? Thank you!
Alas, I also encountered this problem.
Me too...
Me too !!!
Import java. io. IOException; import org. apache. commons. httpclient. httpClient; import org. apache. commons. httpclient. httpException; import org. apache. commons. httpclient. methods. postMethod; public class wx_menu {public static void main (String [] args) {String url =" https://api.weixin.qq.com/cgi-bin/menu/create?access_token=Sv1MA_nwKURUfNUWEusf0IOu6DpAJTQIuR0kLZ4xnj283_o9wDTS8WsLRM-AQ9q36OoWj09gbLgJit5LCZwfV9eHpbn3f4ARrlUsU-JaOxn_khR4Qnm0UDXz6NCG06PP6J3U4rP-x-kJvl87Nzb87Q ";/*** Why to use the set menu * \" you know, this is the java code */String responeJsonStr = "{" + "\" button \": ["+" {\ "name \": \ "menu name 1 \", "+" \ "type \": \ "click \", "+" \ "key \": \ "V01_S01 \" "+"}, "+" {\ "name \": \ "menu name 2 \", "+" \ "type \": \ "click \", "+" \ "key \": \ "V02_S01 \" "+ "}, "+" {\ "name \": \ "menu name 1 \", "+" \ "type \": \ "click \", "+" \ "key \": \ "V03_S01 \" "+"} "+"] "+"} "; HttpClient client = new HttpClient (); postMethod post = new PostMethod (url); post. setRequestBody (responeJsonStr); post. getParams (). setContentCharset ("UTF-8"); // send the http request String respStr = ""; try using client.exe cuteMethod (post); respStr = post. getResponseBodyAsString ();} catch (HttpException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} System. out. println (responeJsonStr); System. out. println (respStr );}}
This code is available for test. Remember to import the commons-httpclient-3.0.1.jar package.
The PHP code is found.
Http://liyandong.duapp.com /? M = study
I started to write it in php, but it cannot be solved all the time. later I switched to linux and directly used curl to solve the problem. however, pay attention to Chinese encoding.
I did this: write the json string, get a version without spaces or carriage return, and use curl in linux. the code is as follows:
Curl-d '{"button": [{"name": "Health query", "sub_button": [{"...... 'https://api.weixin.qq.com/cgi-bin/menu/create? Access_token = xxxx
Note that-d is followed by single quotes. Otherwise, it is invlide button size 40016.
Hoping this can help.
I have solved the following problems:
The problem of submitting post data to https: {"errcode": 40016, "errmsg": "invalid button size "}
Http://blog.csdn.net/e421083458/article/details/14649129