Asp. NET micro-letter Public Number Add Menu _ Practical Tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.