protected void Page_Load(object sender, EventArgs e) { int id = RequestTool.RequestInt("id", 0); int pid = RequestTool.RequestInt("pid", 0); model = B_Lebi_weixin_menu.GetModel(id); if (model == null) { model = new Lebi_weixin_menu(); } else { pid = model.parentid; } pmodel = B_Lebi_weixin_menu.GetModel(pid); if (pmodel == null) { pmodel = new Lebi_weixin_menu(); } if (model.url.Contains("weixinlogin=1")) { IsLogin = 1; } }
/// <summary> /// 保存菜单 /// </summary> public void Menu_Edit() { int id = RequestTool.RequestInt("id", 0); int IsLogin = RequestTool.RequestInt("IsLogin", 0); Lebi_weixin_menu model = B_Lebi_weixin_menu.GetModel(id); bool addflag = false; if (model == null) { model = new Lebi_weixin_menu(); addflag = true; } model = B_Lebi_weixin_menu.BindForm(model); //if (model.parentid == 0) // model.url = ""; if (IsLogin == 1) { if (!model.url.Contains("weixinlogin=1")) { if (model.url.Contains("?")) { model.url += "&weixinlogin=1"; } else { model.url += "?weixinlogin=1"; } } } else { if (model.url.Contains("weixinlogin=1")) { if (model.url.Contains("?")) { model.url = model.url.Replace("?weixinlogin=1", ""); } else { model.url = model.url.Replace("&weixinlogin=1", ""); } } } if (addflag) { B_Lebi_weixin_menu.Add(model); } else { B_Lebi_weixin_menu.Update(model); } Response.Write("{\"msg\":\"OK\"}"); }
/// <summary> /// 删除菜单 /// </summary> public void Menu_Del() { int id = RequestTool.RequestInt("id", 0); Lebi_weixin_menu model = B_Lebi_weixin_menu.GetModel(id); if (model == null) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } B_Lebi_weixin_menu.Delete("id=" + id + " or parentid=" + id + ""); Response.Write("{\"msg\":\"OK\"}"); }
/// <summary> /// 下载菜单 /// </summary> public string DownMenu() { try { string res = Get("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + Token + ""); JavaScriptSerializer jss = new JavaScriptSerializer(); //KeyValue menu = jss.Deserialize<KeyValue>(res); //KeyValue button = jss.Deserialize<KeyValue>(menu.V); Model.weixin.Downmenu dmenu = jss.Deserialize <Model.weixin.Downmenu>(res); //List<Model.weixin.menu> menus = jss.Deserialize<List<Model.weixin.menu>>(button.V); if (dmenu.menu.button != null) { B_Lebi_weixin_menu.Delete("id>0"); int i = 100; foreach (Model.weixin.menu m in dmenu.menu.button) { Lebi_weixin_menu model = new Lebi_weixin_menu(); model.name = m.name; model.Sort = i; model.url = m.url; model.type = m.type; B_Lebi_weixin_menu.Add(model); model.id = B_Lebi_weixin_menu.GetMaxId(); i--; foreach (Model.weixin.menu sm in m.sub_button) { Lebi_weixin_menu smodel = new Lebi_weixin_menu(); smodel.name = sm.name; smodel.Sort = i; smodel.url = sm.url; smodel.type = sm.type; smodel.parentid = model.id; B_Lebi_weixin_menu.Add(smodel); i--; } } } return("OK"); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 生成菜单 /// </summary> /// <returns></returns> public Model.weixin.errormsg CreateMenu() { List <Lebi_weixin_menu> pmodels = B_Lebi_weixin_menu.GetList("parentid=0", "Sort desc", 3, 1); string json = ""; List <Model.weixin.menu> menus = new List <Model.weixin.menu>(); foreach (Lebi_weixin_menu pmodel in pmodels) { Model.weixin.menu menu = new Model.weixin.menu(); menu.name = pmodel.name; menu.type = "view"; List <Lebi_weixin_menu> models = B_Lebi_weixin_menu.GetList("parentid=" + pmodel.id + "", "Sort desc", 5, 1); if (models.Count > 0) { List <Model.weixin.menu> smenus = new List <Model.weixin.menu>(); foreach (Lebi_weixin_menu model in models) { Model.weixin.menu smenu = new Model.weixin.menu(); smenu.name = model.name; smenu.url = model.url; smenu.type = "view"; smenus.Add(smenu); } menu.sub_button = smenus; menu.url = ""; } else { menu.url = pmodel.url; menu.sub_button = new List <Model.weixin.menu>(); } menus.Add(menu); } JavaScriptSerializer jss = new JavaScriptSerializer(); json = jss.Serialize(menus); json = "{\"button\":" + json + "}"; json = json.Replace(",\"sub_button\":null", ""); json = json.Replace("\"type\":\"\",", ""); json = json.Replace("\"url\":\"\",", ""); string res = Post("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + Token + "", json); return(GetErrorMsg(res)); //return json; }
public List <Lebi_weixin_menu> GetwxMenus(int pid) { List <Lebi_weixin_menu> models = B_Lebi_weixin_menu.GetList("parentid=" + pid + "", "Sort desc,id desc"); return(models); }