In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to use .net to develop a custom menu for the Wechat public platform". The content is simple and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and learn "how to use .net to develop a custom menu for the Wechat public platform".
When you customize the menu, you need to use access_token, so we directly use the IsExistAccess_Token () function described earlier. I understand that the Wechat public platform in which menus are divided into button and sub_button, that is, menus and submenus, these menus have a name attribute, categories are divided into click and view,click classes have key attributes, while view classes have url attributes, and menus containing submenus have neither key nor url attributes. These situations can be seen in the following example.
Public void MyMenu () {string weixin1 = "" Weixin1 = @ "{"button": [{" type ":" click ","name":" Hello! "," key ":" Hello "}, {"type":" view ","name":" Company profile ","url": "" http://www.4ugood.net""} " {"name": "Product introduction", "sub_button": [{"type": "click", "name": "Product 1", "key": "P1"}, {"type": "click", "name": "Product 2" "" key "": "" P2 ""}]}]} " String access_token = IsExistAccess_Token (); string I = GetPage ("https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+access_token, weixin1); Response.Write (I);}
Call this MyMenu () in the Page_Load function of your page and it will be displayed.
Now that it is displayed, how can the time of the menu start? We have learned that if the type is view, it has a url attribute. This does not need to be dealt with. After clicking it, it will jump directly to the url page you set. Next, let me see how to trigger click. According to the Wechat document, you can use (! string.IsNullOrEmpty (wx.EventName) & & wx.EventName.Trim () = = "CLICK") to judge. I modified the previous code and appended the value of EventKey to the GetWxMessage () method, wx.EventKey = xml.SelectSingleNode ("xml"). SelectSingleNode ("EventKey"). InnerText
Protected void Page_Load (object sender, EventArgs e) {MyMenu (); wxmessage wx = GetWxMessage (); string res = ""; if (! string.IsNullOrEmpty (wx.EventName) & & wx.EventName.Trim () = = "subscribe") {string content = "; content =" /: rose Welcome Beijing Yongjie Youxin Technology Co., Ltd. /: rose\ nreply "Hello" directly; res = sendTextMessage (wx, content) } else if (! string.IsNullOrEmpty (wx.EventName) & & wx.EventName.Trim () = = "CLICK") {if (wx.EventKey== "Hello") res = sendTextMessage (wx, "Hello, welcome to the public Wechat platform of Beijing Yongjie Youxin Technology Co., Ltd."); if (wx.EventKey== "P1") res = sendTextMessage (wx, "Hello, click on Product 1") If (wx.EventKey== "P2") res = sendTextMessage (wx, "Hello, click on product 2");} else {if (wx.MsgType = = "text" & & wx.Content = = "Hello") {res = sendTextMessage (wx, "Hello, welcome to the public Wechat platform of Beijing Yongjie Youxin Technology Co., Ltd.") } else if (wx.MsgType = = "voice") {res = sendTextMessage (wx, wx.Recognition);} else {res = sendTextMessage (wx, "Hello, failed to recognize message!");}} Response.Write (res);} private wxmessage GetWxMessage () {wxmessage wx = new wxmessage (); StreamReader str = new StreamReader (Request.InputStream, System.Text.Encoding.UTF8); XmlDocument xml = new XmlDocument () Xml.Load (str); wx.ToUserName = xml.SelectSingleNode ("xml"). SelectSingleNode ("ToUserName"). InnerText; wx.FromUserName = xml.SelectSingleNode ("xml"). SelectSingleNode ("FromUserName"). InnerText; wx.MsgType = xml.SelectSingleNode ("xml"). SelectSingleNode ("MsgType"). InnerText; if (wx.MsgType.Trim () = "text") {wx.Content = xml.SelectSingleNode ("xml"). SelectSingleNode ("Content"). } if (wx.MsgType.Trim () = = "event") {wx.EventName = xml.SelectSingleNode ("xml"). SelectSingleNode ("Event"). InnerText; wx.EventKey = xml.SelectSingleNode ("xml"). SelectSingleNode ("EventKey"). InnerText;} if (wx.MsgType.Trim () = = "voice") {wx.Recognition = xml.SelectSingleNode ("xml"). SelectSingleNode ("Recognition"). InnerText;} return wx } / send text messages / content / private string sendTextMessage (wxmessage wx, string content) {string res = string.Format (@ "{2}", wx.FromUserName, wx.ToUserName, DateTime.Now, content); return res } the above is all the contents of the article "how to use .net to develop a custom menu for the Wechat public platform". 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!
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.