這篇文章給大家分享的是有關(guān)ASP.NET微信公眾號(hào)如何添加菜單的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
創(chuàng)新互聯(lián)專注于賓縣網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供賓縣營(yíng)銷型網(wǎng)站建設(shè),賓縣網(wǎng)站制作、賓縣網(wǎng)頁(yè)設(shè)計(jì)、賓縣網(wǎng)站官網(wǎng)定制、微信小程序定制開(kāi)發(fā)服務(wù),打造賓縣網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供賓縣網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。具體內(nèi)容如下
testjs.aspx代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testjs.aspx.cs" Inherits="MyTest.WebUI.Manager.Main.testjs" %>
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內(nèi)容:
{ "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" }] }] }
運(yùn)行結(jié)果如圖:
感謝各位的閱讀!關(guān)于“ASP.NET微信公眾號(hào)如何添加菜單”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!