The example of this article for everyone to share the public number add menu specific code for your reference, the specific content is 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 V OID 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 Operation Helper Class
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";//case is 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); } 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": "Likes Us", "key": "V1001_good" }] }]}
Operation Result:
The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.