Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement the custom menu bar in the development of the official account of c # Wechat

Shulou Source: shulou.com Published: 2022-06-01 18:44:49 10月05日 Update

Editor to share with you how to implement the custom menu bar in the development of c # Wechat official account, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it!

"

This paper mainly realizes the customization of the menu bar of the official account, the Wechat public platform also has specific instructions, and there are also online debugging tools. In this paper, we realize the custom menu bar by requesting the background interface of our project. Note: when we deploy the back-end program, the port must be 80 or 443

Official development of Wechat customized menu bar: https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.htmlhttps://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html Wechat official online debugging menu bar: https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=%E8%87%AA%E5%AE%9A%E4% B9%89%E8%8F%9C%E5%8D%95&form=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3%20/menu/creat https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=%E8%87%AA%E5%AE%9A%E4%B9%89%E8% 8F%9C%E5%8D%95&form=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3%20/menu/creat. "Okay. Let's code to implement the custom menu bar, where we need an access_token, we can just get it from the database, or global storage, which will explain in detail how to get access_token and other necessary values.

Request custom backend API http://wx.zyynet.club/WeixinAuthor/CreateMenu

/ Custom official account interface menu item / public string CreateMenu () {string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + Config.WxConfig.Config.access_token" String data = "{\" button\ ": [{\" name\ ":\" Dotnet column\ ",\" sub_button\ ": [{\" type\ ":\" view\ ",\" name\ ":\" about me\ ",\" url\ ":\" https://blog.csdn.net/Hakim2214\"},{\"type\":\"view\",\"name\":\" Wechat Development\ " \ "url\":\ "https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html\"}]},{\"name\":\" Test\",\ "sub_button\": [{\ "type\":\ "view\",\ "name\":\ "Encyclopedia of Operations and maintenance\",\ "url\":\ "https://blog.csdn.net/Hakim2214\"},{\"type\":\"view\"," \ "name\":\ "online exam\",\ "url\":\ "http://sfmes.rjtx.net:55291/MobileApp/index.html\"}]}]}"; System.Net.HttpWebRequest httpWebRequest = (HttpWebRequest) System.Net.WebRequest.Create (url); httpWebRequest.Method = "POST"; byte [] postBytes = Encoding.UTF8.GetBytes (data); httpWebRequest.ContentType = "application/json; charset=utf-8"; / / httpWebRequest.ContentLength = Encoding.UTF8.GetByteCount (data); / / data is the json string Stream stream = httpWebRequest.GetRequestStream (); stream.Write (postBytes, 0, postBytes.Length); stream.Close () / / after sending, accept the return value var response = httpWebRequest.GetResponse (); Stream streamResponse = response.GetResponseStream (); StreamReader streamRead = new StreamReader (streamResponse); String responseString = streamRead.ReadToEnd (); return responseString;}

After a successful request, you can see the effect.

The above is all the contents of the article "how to implement a custom menu bar in the development of the official account of c # Wechat". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Menus public developers articles online caching content background official interface necessary successful not so much columns code global online exams most characters strings Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Xiaomi MariaDB macOS