ASP.NET微信公众号添加菜单
网络编程 2021-07-04 22:41www.168986.cn编程入门
这篇文章主要为大家详细介绍了ASP.NET微信公众号添加菜单的相关代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了微信公众号添加菜单的具体代码,供大家参考,具体内容如下
testjs.aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testjs.aspx.cs" Inherits="MyTest.WebUI.Manager.Main.testjs" %> <!DOCTYPE html> <html xmlns="http://.w3./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./cgi-bin/menu/create?aess_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./cgi-bin/menu/delete?aess_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://.soso./" }, { "type":"view", "name":"视频", "url":"http://v.qq./" }, { "type":"click", "name":"赞一下我们", "key":"V1001_GOOD" }] }] }
运行结果如图:
本文已被整理到了《》,欢迎大家学习阅读。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程