In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to develop custom menu functions on Wechat public platform. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
I. brief introduction
The Wechat public platform service number and Subscription account, who has previously successfully applied for internal test qualification, both have the function of customizing the menu. Developers can use this function to add a custom menu to the bottom of the session interface of the public account, and users can click on the options in the menu to call up the corresponding reply message or web link. The custom menu interface will provide more possibilities for the information display space of public accounts.
II. Official statement
After obtaining the voucher, the developer can use the credential to create, query and delete the custom menu of the public account. The custom menu interface implements the following types of buttons:
Click (Click event):
After the user clicks the click type button, the Wechat server will push the click event to the developer through the message API (event type), with the key value entered by the developer in the button, and the developer can reply to the message through the custom key value.
View (visit the web page):
When the user clicks the view type button, it will jump directly to the url specified by the developer.
After creating a custom menu, it takes 24 hours for the Wechat client to display due to the Wechat client cache. It is suggested that during the test, you can try to unfollow the public account and follow it again, and you can see the effect after the creation.
Document address: http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E6%8E%A5%E5%8F%A3
Third, obtain the certificate of use
3.1get appid and appsecret
Find appid and appsecret in Wechat Public platform > Advanced Features > Development Mode.
3.2 request access_token from Wechat credential acquisition API using appid and appsecret
Request address: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Request parameter description:
Grant_type: get access_token and enter client_credential
Appid: unique credentials of third-party users
Secret: the unique credential key of a third-party user, both appsecret
Return description:
The correct Json returns the result:
{"access_token": "ACCESS_TOKEN", "expires_in": 7200}
Return parameter description:
Access_token: obtained credential
Expires_in: valid time of the credential (in seconds)
3.3 concrete implementation
a. Print out format
The results are as follows:
b. Get access_token
Note: access_token is a globally unique ticket corresponding to the official account. Repeated acquisition will invalidate the last acquired access_token.
Create a menu
Method: create a custom menu in Wechat client through a specific structure of POST.
Request address: https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
Example of request:
{"button": [{"name": "Public query", "sub_button": [{"type": "click", "name": "Weather query", "key": "tianQi"}, {"type": "click", "name": "bus query" "key": "gongJiao"}, {"type": "click", "name": "Translation", "key": "fanYi"}]}, {"name": "Suzhou Local", "sub_button": [{"type": "click" "name": "fall in love with Suzhou", "key": "loveSuzhou"}, {"type": "click", "name": "Suzhou scenic spots", "key": "suzhouScenic"}, {"type": "click", "name": "Suzhou cuisine" "key": "suzhouFood"}, {"type": "click", "name": "living in Suzhou", "key": "liveSuzhou"}]}, {"type": "click", "name": "contact us", "key": "lianxiUs"}]}
The example shows:
Menu structure and description:
{"button": [/ / button defines the structure as a menu {"name": "branch main menu name", "sub_button": [/ / sub_button defines submenu {"type": "click", / / button type "name": "branch submenu name 1" / / menu name "key": "loveSuzhou" / menu key value}, {"type": "click", "name": "branch submenu name 2", "key": "liveSuzhou"}]}, / / use between menus to separate {"type": "click" "name": "standalone menu", "key": "lianxiUs"}]}
Return description:
The correct Json returns the result:
{"errcode": 0, "errmsg": "ok"}
Submit menu:
Submit the above menu data through curl. The code is as follows:
$MENU_URL= "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$ACC_TOKEN;$ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $MENU_URL); curl_setopt ($ch, CURLOPT_CUSTOMREQUEST," POST "); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01) Windows NT 5)'); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_AUTOREFERER, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $data); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $info = curl_exec ($ch); if (curl_errno ($ch)) {echo 'Errno'.curl_error ($ch);} curl_close ($ch); var_dump ($info)
Generate menu:
After the code for creating the menu is submitted to the server, it does not come out automatically. You need to execute the code file to generate it. Therefore, open the browser and enter the complete menu code URL in the address bar. The running result is as follows:
Test results:
The menu was created successfully.
Fifth, query menu
Query the custom menu structure currently in use.
Request address: https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN
The curl code is as follows:
$MENU_URL= "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".$ACC_TOKEN;$cu = curl_init (); curl_setopt ($cu, CURLOPT_URL, $MENU_URL); curl_setopt ($cu, CURLOPT_RETURNTRANSFER, 1); $menu_json = curl_exec ($cu); $menu = json_decode ($menu_json); curl_close ($cu); echo $menu_json
Running result:
Menu query succeeded.
VI. Delete the menu
Cancel the custom menu currently in use.
Request address: https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN
The curl code is as follows:
$MENU_URL= "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".$ACC_TOKEN;$cu = curl_init (); curl_setopt ($cu, CURLOPT_URL, $MENU_URL); curl_setopt ($cu, CURLOPT_RETURNTRANSFER, 1); $info = curl_exec ($cu); $res = json_decode ($info); curl_close ($cu); if ($res- > errcode = =" 0 ") {echo" menu deleted successfully;} else {echo "menu deletion failed" }
Running result:
Test results:
Menu deleted successfully.
7. Complete code acquisition
Please visit the official online disk of Le Si Le Hang
URL: http://pan.baidu.com/s/1c0s3Jby
VIII. Concern
Please follow the public account of Zhuojin Suzhou Wechat, which is developed based on the BAE platform and is designed to develop and test the mainstream Wechat functions.
You can follow Zhuojin Suzhou public account for functional testing and obtain new application development.
1. Log in to Wechat client, address book-> add friends-> find official account-> zhuojinsz, find and follow.
Zhuo Jin Suzhou menu function:
This is the end of the article on "how to develop custom menu functions on Wechat public platform". I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.