Home  >  Article  >  Backend Development  >  WeChat development methods to create custom menus

WeChat development methods to create custom menus

小云云
小云云Original
2018-03-20 15:20:453517browse

Custom menus can help public accounts enrich their interfaces and allow users to understand the functions of public accounts better and faster. This article mainly shares with you how to develop and create custom menus on WeChat. I hope it can help you.

1. The custom menu includes up to 3 first-level menus, and each first-level menu contains up to 5 second-level menus.
2. The first-level menu can contain up to 4 Chinese characters, and the second-level menu can contain up to 7 Chinese characters. The extra parts will be replaced by "...".
3. After creating a custom menu, the refresh strategy of the menu is that when the user enters the public account conversation page or public account profile page, if the last request to pull the menu is found 5 minutes ago, it will be pulled. Menu, if the menu is updated, the client's menu will be refreshed. When testing, you can try to unfollow the public account and follow it again, and you can see the effect after creation.

The custom menu interface can implement multiple types of buttons. There are a total of 10 types of buttons. There are two most common ones:
1. Click: Click push event. After the user clicks the click type button, the WeChat server will send a message through The interface pushes the message type event structure to the developer (refer to the Message Interface Guide), and brings the key value filled in by the developer in the button. The developer can interact with the user through the customized key value;
2. view : Jump URL After the user clicks the view type button, the WeChat client will open the web page URL filled in by the developer in the button. It can be combined with the web page authorization interface to obtain the user's basic information to obtain the user's basic information.

As for constructing the curl request function and obtaining the access_token, there is no need to post it here. For details, see

curl network request in PHP

Getting the WeChat basic interface credential Access_token

//自定义菜单栏
public function _createMenu(){
	$curl = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$this->_getAccessToken();
	$data = ' {
			 "button":[
			  {
				   "name":"常用服务",
				   "sub_button":[
				   {	
					   "type":"view",
					   "name":"百度一下",
					   "url":"https://www.baidu.com/"
					},
					{
					   "type":"view",
					   "name":"腾讯视频",
					   "url":"http://v.qq.com/"
					},
					{
					   "type":"click",
					   "name":"创业杂谈",
					   "key":"TALK"
					}]
			   },
			  {	
				  "type":"click",
				  "name":"今日歌曲",
				  "key":"TODAY_MUSIC"
			  }]
		 }';
	$result = $this->_request($curl,true,'POST',$data);
	echo $result;
}


When the button type is click type, there must be a corresponding key value in the event push received, otherwise the appropriate response will not be obtained. For details, see WeChat message management receiving event push


Related recommendations:

WeChat public account custom menu PHP version

PHP method to create WeChat custom menu

PHP code to implement the custom menu interface in WeChat public account enterprise account

The above is the detailed content of WeChat development methods to create custom menus. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn