這篇文章給大家分享的是有關ASP.NET微信公眾號如何添加菜單的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
創新互聯專注于賓縣網站建設服務及定制,我們擁有豐富的企業做網站經驗。 熱誠為您提供賓縣營銷型網站建設,賓縣網站制作、賓縣網頁設計、賓縣網站官網定制、微信小程序定制開發服務,打造賓縣網絡公司原創品牌,更為您提供賓縣網站排名全網營銷落地服務。具體內容如下
testjs.aspx代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testjs.aspx.cs" Inherits="MyTest.WebUI.Manager.Main.testjs" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" /> <title></title> <script type="text/javascript" src="../../js/jweixin-1.0.0.js"></script> <script type="text/javascript" src="../../js/jquery-1.12.2.min.js"></script> <style> .btn { width: 100%; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label> <asp:Button CssClass="btn" ID="Button1" runat="server" Text="添加菜單" OnClick="Button1_Click" /><br /> <asp:Button CssClass="btn" ID="Button2" runat="server" Text="刪除菜單" OnClick="Button2_Click" /><br /> </div> </form> </body> </html>
public partial class testjs : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { MenuOperator mm = new MenuOperator(); lblMsg.Text=mm.menu_add(); } protected void Button2_Click(object sender, EventArgs e) { MenuOperator mm = new MenuOperator(); lblMsg.Text = mm.menu_del(); } }
MenuOperator.cs菜單操作助手類
public class MenuOperator { public string menu_add() { string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="; string token = mainArg.get_Token(); url += token; HttpWebRequest req =(HttpWebRequest) HttpWebRequest.Create(url); req.Method = "POST";//大小寫不限 string menuPath = HttpContext.Current.Server.MapPath(@"~/TemplePath/menu.txt"); Stream ms =File.Open(menuPath, FileMode.OpenOrCreate); byte[] paramb = new byte[ms.Length]; ms.Read(paramb, 0, (Int32)ms.Length); string param = Encoding.Default.GetString(paramb); ms.Close(); using (StreamWriter stream=new StreamWriter(req.GetRequestStream())) { stream.Write(param); } using (HttpWebResponse response=(HttpWebResponse)req.GetResponse()) { Stream s = response.GetResponseStream(); StreamReader sr = new StreamReader(s); string result = sr.ReadToEnd(); sr.Close(); return result; } } public string menu_del() { string token = mainArg.get_Token(); string url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + token; ; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); using (HttpWebResponse response =(HttpWebResponse) req.GetResponse()) { StreamReader sr = new StreamReader(response.GetResponseStream()); string result = sr.ReadToEnd(); sr.Close(); return result; } } }
menu.txt內容:
{ "button":[ { "type":"click", "name":"今日歌曲", "key":"V1001_TODAY_MUSIC" }, { "name":"菜單", "sub_button":[ { "type":"view", "name":"搜索", "url":"http://www.soso.com/" }, { "type":"view", "name":"視頻", "url":"http://v.qq.com/" }, { "type":"click", "name":"贊一下我們", "key":"V1001_GOOD" }] }] }
運行結果如圖:
感謝各位的閱讀!關于“ASP.NET微信公眾號如何添加菜單”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
標題名稱:ASP.NET微信公眾號如何添加菜單-創新互聯
文章起源:http://vcdvsql.cn/article18/dsdedp.html
成都網站建設公司_創新互聯,為您提供建站公司、品牌網站設計、全網營銷推廣、用戶體驗、網站維護、網站收錄
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯