国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

微信自定義菜單

2019-11-17 02:46:12
字體:
來源:轉載
供稿:網友

微信自定義菜單

自己寫的構造自定義菜單的方法,雖然有些重復,但畢竟是自己寫的感覺更清楚些!各位有什么好的意見指出來呀!

兩個類SubButton(子菜單),ParentButton(父級菜單)。

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;}

構造好的菜單傳給GetCustomMenuJsonData得到正確的Json格式數據。

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

舉例:

Publish List<ParentButton> CreateCustomButton(){ParentButton button1 = new ParentButton();List<SubButton> subButtonList1 = new List<SubButton>();SubButton subButton = new SubButton();subButton.name = "百度";subButton.type = "view";subButton.url = "www.baidu.com";subButtonList1.Add(subButton);subButton = new SubButton();subButton.name = "谷歌";subButton.type = "view";subButton.url = "www.google.com";subButtonList1.Add(subButton);button1.name = "搜索"; button1.list = subButtonList1;ParentButton button2 = new ParentButton();button2.name="其他";List<ParentButton> list = new List<ParentButton>();list.Add(button1);list.Add(button2);return list;}
View Code

得到json數據后通過

https://api.wexin.QQ.com/cgi-bin/token?grant_type=client_credential&appid=AppId&secret=AppSecret

獲取到accesstoken,然后通過

https://api.weixin.qq.com/cgi-bin/menu/create?access_token=AccessToken

提交自定義菜單的json數據,生成菜單!

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 司法| 界首市| 广南县| 贡觉县| 中西区| 安义县| 增城市| 永济市| 方山县| 宜阳县| 唐河县| 且末县| 昌邑市| 永平县| 广州市| 彰化县| 宝鸡市| 克什克腾旗| 理塘县| 视频| 澜沧| 台州市| 九江县| 红桥区| 岳阳县| 论坛| 盐亭县| 延庆县| 钟山县| 科尔| 巴彦淖尔市| 天长市| 梓潼县| 泰宁县| 海盐县| 江山市| 吐鲁番市| 旌德县| 苍梧县| 法库县| 高要市|