//获取菜单
protected void Button2_Click(object sender, EventArgs e)
{
Wechat.Config.Model.Request.MenuGet ss = new Model.Request.MenuGet();
ss.agentid = "0";
var ar = ss.Send();
//for (int i = 0; i < ar.menu.button.Count; i++)
//{
// Response.Write(ar.menu.button[i].name.ToString());
//}
ListBox1.Items.Add(JsonConvert.SerializeObject(ar));
}
//创建菜单
protected void Button3_Click(object sender, EventArgs e)
{
Wechat.Config.Model.Request.MenuCreate ss = new Model.Request.MenuCreate();
ss.agentid = "0";
List<Wechat.Config.Model.Request.MenuItem> list = new List<Wechat.Config.Model.Request.MenuItem>();
List<Wechat.Config.Model.Request.MenuItem> list1 = new List<Wechat.Config.Model.Request.MenuItem>();
Wechat.Config.Model.Request.MenuItem m;
m = new Wechat.Config.Model.Request.MenuItem();
m.key = "";
m.name = "本地新闻";
m.type = "view";
m.sub_button = null;
m.url = "http://www.baidu.com";
//ss.button.Add(m);
list.Add(m);
m = new Wechat.Config.Model.Request.MenuItem();
m.key = "http://www.baidu.com";
m.name = "今日天气";
m.type = "click";
m.sub_button = null;
m.url = "http://www.baidu.com";
//ss.button.Add(m);
list.Add(m);
m = new Wechat.Config.Model.Request.MenuItem();
m.key = "http://www.baidu.com";
m.name = "菜单";
m.type = "click";
m.sub_button = list1;
m.url = "00011";
//ss.button.Add(m);
list.Add(m);
ss.button = list;
m = new Wechat.Config.Model.Request.MenuItem();
m.key = "http://www.baidu.com";
m.name = "关于...";
m.type = "click";
m.sub_button = null;
m.url = "00011";
list1.Add(m);
m = new Wechat.Config.Model.Request.MenuItem();
m.key = "http://www.baidu.com";
m.name = "赞一下我们";
m.type = "click";
m.sub_button = null;
m.url = "00011";
list1.Add(m);
var ar = ss.Send();
ListBox1.Items.Add(JsonConvert.SerializeObject(ar));
}
/// <summary>
/// 删除菜单,其实是关闭自定义菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button4_Click(object sender, EventArgs e)
{
Wechat.Config.Model.Request.MenuDelete ss = new Model.Request.MenuDelete();
ss.agentid = "0";
var ar = ss.Send();
ListBox1.Items.Add(JsonConvert.SerializeObject(ar));
}
用到的类
class MenuGet : OperationRequestBase<MenuGetResult, HttpGetRequest>
{
private string url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN&agentid={0}";
protected override string Url()
{
return string.Format(url, agentid);
}
/// <summary>
/// 企业应用的id,整型。可在应用的设置页面查看
/// </summary>
/// <returns></returns>
[IsNotNull]
public string agentid { get; set; }
}
class MenuCreate : OperationRequestBase<OperationResultsBase, HttpPostRequest>
{
private string url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN&agentid={0}";
protected override string Url()
{
return string.Format(url, agentid);
}
/// <summary>
/// 企业应用的id,整型。可在应用的设置页面查看
/// </summary>
/// <returns></returns>
[IsNotNull]
public string agentid { private get; set; }
/// <summary>
/// 一级菜单数组,个数应为1~3个
/// </summary>
/// <returns></returns>
public List<MenuItem> button { get; set; }
}
class MenuDelete : OperationRequestBase<OperationResultsBase, HttpGetRequest>
{
private string url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN&agentid={0}";
protected override string Url()
{
return string.Format(url, agentid);
}
/// <summary>
/// 企业应用的id,整型。可在应用的设置页面查看
/// </summary>
/// <returns></returns>
[IsNotNull]
public string agentid { private get; set; }
QQ群:108845298,期待你的加入