微信開發----設置菜單
阿新 • • 發佈:2018-02-25
wiki com 寫代碼 搜索 line ati www. ast build
①創建我們的菜單API
這裏只寫了創建菜單,還有查詢和刪除菜單這裏沒有寫。跟這個差不多的,照著搬就好了。
②因為上篇我們設置了我們的服務器URL。在設置的url中寫代碼
GetAccessToken方法:
CacheHelper網址
JsonHelp:
創建菜單Json字符串:
/// <summary> /// 有關菜單的模板 /// https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013 /// 註意你的菜單json字符串 要保證正確View Code/// </summary> /// <returns></returns> public string GetWeixinMenu() { StringBuilder menStr = new StringBuilder(); menStr.AppendLine("{"); menStr.AppendLine("\"button\":["); //第一個主菜單 沒有子菜單 menStr.AppendLine("{"); menStr.AppendLine("\"type\":\"click\","); menStr.AppendLine("\"name\":\"點擊事件\","); menStr.AppendLine("\"key\":\"test01\""); //這個key對應的值是用來做這個事件處理的,這裏就不寫了,後面會介紹 menStr.AppendLine("},"); //第二個主菜單,有子菜單的 menStr.AppendLine("{"); menStr.AppendLine("\"name\":\"測試功能\","); menStr.AppendLine("\"sub_button\":["); //子菜單 menStr.AppendLine("{"); menStr.AppendLine("\"type\":\"view\","); menStr.AppendLine("\"name\":\"搜索\","); menStr.AppendLine("\"url\":\"http://www.baidu.com/\""); menStr.AppendLine(" },"); menStr.AppendLine("{"); menStr.AppendLine("\"type\":\"view\","); menStr.AppendLine("\"name\":\"網頁授權\","); menStr.AppendLine("\"url\":\"http://www.baidu.com/\""); menStr.AppendLine(" }"); menStr.AppendLine("]}"); menStr.AppendLine("]}"); return menStr.ToString(); }
③然後發布你的項目,打開網站
微信開發----設置菜單