WeChat custom menu and email custom menu

Source: Internet
Author: User

Custom menu, custom menu

Although the self-written methods for constructing custom menus are somewhat repetitive, they feel clearer after all! Do you have any good comments!

SubButton (sub menu) and ParentButton (parent menu ).

public class ParentButton{  public string name;  public List<SubButton> list;}public class SubButton{  public string name;  public string type;  public string url;  public string key;}

 

The constructed menu is passed to getmmmmenujsondata to obtain the correct Json format data.

Public string GetCustomMenuJsonData (List <ParentButton> list) {string jsonStr = ""; string str = ""; if (list! = Null & list. Count> 0) {foreach (ParentButton parentButton in list) {if (parentButton! = Null) {string subStr = ""; if (parentButton. list! = Null & parentButton. list. Count> 0) {foreach (SubButton button in parentButton. list) {if (button! = Null) {if (subStr! = "") {SubStr + = ",";} if (button. type = "click") {subStr + = "{\" type \ ": \" click \ ", \" name \ ": \" "+ button. name + "\", \ "key \": \ "" + button. key + "\"} ";} else {subStr + =" {\ "type \": \ "view \", \ "name \": \ "" + button. name + "\", \ "url \": \ "" + button. url + "\"} ";}}} if (str! = "") {Str + = ",";} str + = "{\" name \ ": \" "+ parentButton. name + "\", \ "sub_button \": ["+ subStr +"]} ";}} jsonStr = (" {\ "button \": ["+ str +"]} ");} return jsonStr ;}View Code

 

Example:

Publish List <ParentButton> Centers () {ParentButton button1 = new ParentButton (); List <SubButton> subButtonList1 = new List <SubButton> (); SubButton subButton = new SubButton (); subButton. name = "Baidu"; subButton. type = "view"; subButton. url = "www.baidu.com"; subButtonList1.Add (subButton); subButton = new SubButton (); subButton. name = "google"; subButton. type = "view"; subButton. url = "www.google.com"; subButtonList1.Add (subButton); button1.name = "Search"; button1.list = subButtonList1; ParentButton button2 = new ParentButton (); button2.name = "other "; list <ParentButton> list = new List <ParentButton> (); list. add (button1); list. add (button2); return list ;}View Code

 

After obtaining json data, use

Https://api.wexin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = AppId & secret = AppSecret

Obtain the accesstoken, and then use

Https://api.weixin.qq.com/cgi-bin/menu/create? Access_token = AccessToken

Submit the json data of the custom menu to generate the menu!

  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.