This example for you to share the micro-letter public number of the specific code to add a menu for your reference, the specific contents are as follows
Testjs.aspx Code:
<%@ Page language= "C #" autoeventwireup= true "codebehind=" Testjs.aspx.cs "inherits=" MyTest.WebUI.Manager.Main.testjs "%> <! DOCTYPE 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 Menu Action Assistant class
public class Menuoperator {public string Menu_add () {String url = ' Https://api.weixin.qq.com/cgi-bin/menu/creat
E?access_token= ";
String token = Mainarg.get_token ();
URL + token;
HttpWebRequest req = (HttpWebRequest) httpwebrequest.create (URL); Req.
method = "POST";//Case not limited to 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); The 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 content:
{"
button": [
{
"type": "Click",
"name": "Today's song",
"key": "V1001_today_music"
},
{
" Name ': ' Menu ',
' Sub_button ': [
{
' type ': ' View ',
' name ': ' Search ',
' url ': ' http://www.soso.com/'
},
{
' type ': ' View ',
' name ': ' Video ',
' url ': ' http://v.qq.com/'
},
{
' type ' : "Click",
"name": "Praise Us",
"key": "V1001_good"}
]}
Run the results as shown in figure:
This article has been sorted out to the ASP. NET micro-Credit Development tutorial Summary, you are welcome to learn to read.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.