public static TreeNode GetMenuTreeNode() { MenuFull_ButtonGroup menu = GetButtonGroup(); TreeNode root = new TreeNode("微信菜单", "0", "", true, ""); TreeNode tree = new TreeNode("菜单根目录", "0", "", true, ""); root.childs.Add(tree); int i = 1, j = 1; foreach (var btn in menu.button) { TreeNode tn = new TreeNode(btn.name, i.ToString(), "", true, ""); if (btn.sub_button != null) { foreach (var btn2 in btn.sub_button) { TreeNode tn2 = new TreeNode(btn2.name, i.ToString() + "-" + j.ToString(), "", true, ""); tn.childs.Add(tn2); j++; } j = 1; } tree.childs.Add(tn); i++; } return(root); }
public static void CreateMenuNode(int pi, MenuFull_RootButton button) { MenuFull_ButtonGroup menu = GetButtonGroup(); if (pi == -1) { if (menu.button.Count == 3) { throw new Exception("菜单(一级)超出最大数量3个!"); } menu.button.Add(button); } else { var list = menu.button[pi].sub_button; if (list == null) { list = new List <MenuFull_RootButton>(); } if (menu.button.Count == 5) { throw new Exception("菜单(二级)超出最大数量5个!"); } list.Add(button); menu.button[pi].sub_button = list; } ReflushSetting(menu); }
private static MenuFull_ButtonGroup GetButtonGroup() { if (_buttonGroup == null) { String menus = Variables.MenuButtons; _buttonGroup = JsonConvert.DeserializeObject <MenuFull_ButtonGroup>(menus); } return(_buttonGroup); }
internal static MenuFull_RootButton GetMenuNode(int pi, int si) { MenuFull_ButtonGroup menu = GetButtonGroup(); MenuFull_RootButton parent = menu.button[pi]; if (si == -1) { return(parent); } return(parent.sub_button[si]); }
internal static void SaveMenuNode(int pi, int si, MenuFull_RootButton button) { MenuFull_ButtonGroup menu = GetButtonGroup(); if (si == -1) { menu.button[pi] = button; } else { menu.button[pi].sub_button[si] = button; } ReflushSetting(menu); }
private static void ReflushSetting(MenuFull_ButtonGroup menu) { String json = JsonConvert.SerializeObject(menu); SettingFile st = Config.PluginAttr.Settings; json = json.Replace(",\"sub_button\":null", "") .Replace(",\"url\":null", "") .Replace(",\"key\":null", "") .Replace("\"type\":null,", ""); st["Weixin_MenuButtons"] = json; st.Flush(); Variables.MenuButtons = json; _buttonGroup = menu; }
public static void DelMenu(int pi, int si) { MenuFull_ButtonGroup group = GetButtonGroup(); MenuFull_RootButton menu; if (si == -1) { group.button.Remove(group.button[pi]); } else { group.button[pi].sub_button.Remove(group.button[pi].sub_button[si]); } ReflushSetting(group); }
public ActionResult InitMenu() { var token = AccessTokenContainer.TryGetAccessToken(AppId, AppSecret); var buttonGroups = new MenuFull_ButtonGroup(); // 定义按钮 buttonGroups.button = new List <MenuFull_RootButton> { new MenuFull_RootButton { name = "科技资讯", type = "view", url = "https://guandian.tech", }, new MenuFull_RootButton { name = "技术分享", type = "view", url = "https://guandian.tech/blogs", }, new MenuFull_RootButton { name = "关于我们", sub_button = new List <MenuFull_RootButton> { new MenuFull_RootButton { name = "我们是谁", type = "view", url = "https://guandian.tech/home/about" }, new MenuFull_RootButton { name = "联系方式", type = "view", url = "https://guandian.tech/home/contact" } } } }; var result = CommonApi.CreateMenu(token, buttonGroups); return(Json(result.errmsg)); }
public async Task CreateOrWechatEditMenu(CreateOrEditWechatMenuInput input) { await _wechatAppConfigManager.RegisterWechatApp(input.AppId); var menuFull_ButtonGroup = new MenuFull_ButtonGroup() { button = input.Menu }; if (input.MatchRule != null) { await this.CreateConditionalMenu(input.AppId, menuFull_ButtonGroup, input.MatchRule); } else { await this.UpdateDefaultMenu(input.AppId, menuFull_ButtonGroup); } }
/// <summary> /// 更新自定义菜单(默认菜单) /// </summary> /// <param name="appId">微信appId</param> /// <param name="menuFull_Button">自定义菜单组</param> /// <returns></returns> private async Task UpdateDefaultMenu(string appId, MenuFull_ButtonGroup menuFull_Button) { await _wechatAppConfigManager.RegisterWechatApp(appId); try { var resultFull = new GetMenuResultFull() { menu = menuFull_Button }; // 数据校验 var buttonGroup = CommonApi.GetMenuFromJsonResult(resultFull, new ButtonGroup()).menu; // 立即创建 var result = CommonApi.CreateMenu(appId, buttonGroup); } catch (UserFriendlyException e) { throw e; } }
/// <summary> /// 创建个性化菜单 /// </summary> /// <param name="appId">微信appId</param> /// <param name="menuFull_Button">菜单数据定义</param> /// <param name="menuMatchRule">个性化匹配规则</param> /// <returns></returns> private async Task CreateConditionalMenu(string appId, MenuFull_ButtonGroup menuFull_Button, MenuMatchRule menuMatchRule) { await _wechatAppConfigManager.RegisterWechatApp(appId); try { var resultFull = new GetMenuResultFull() { menu = menuFull_Button }; // 数据校验 var buttonGroup = CommonApi.GetMenuFromJsonResult(resultFull, new ConditionalButtonGroup()).menu; // 附加规则 var addConditionalButtonGroup = buttonGroup as ConditionalButtonGroup; addConditionalButtonGroup.matchrule = menuMatchRule; // 立即创建 var result = CommonApi.CreateMenuConditional(appId, addConditionalButtonGroup); } catch (UserFriendlyException e) { throw e; } }