ASP. NET public account add menu, asp.net letter public add
The examples in this article share the code for adding a menu to the public account for your reference. The details 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 operation assistant 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"; // 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 songs", "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 ": "like us", "key": "V1001_GOOD"}]}
Running result:
This article has been compiled into ASP. NET development tutorial summary. You are welcome to learn and read it.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.