Exemplo n.º 1
0
 public JsonResult PublishMenu(string companyId)
 {
     try
     {
         WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(companyId);
         if (config == null || string.IsNullOrWhiteSpace(config.AppId) || string.IsNullOrWhiteSpace(config.AppSecret) ||
             string.IsNullOrWhiteSpace(config.SystemName))
         {
             throw new MyException("获取微信基础信息失败,请确认微信基础信息已配置");
         }
         var accessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, false);
         var buttonGroup = ToButtonGroup(WXMenuServices.GetMenus(companyId));
         TxtLogServices.WriteTxtLogEx("PublishMenu", JsonHelper.GetJsonString(buttonGroup));
         var result = WxApi.CreateMenu(companyId, accessToken, buttonGroup);
         if (!result)
         {
             throw new MyException("发布菜单失败");
         }
         return(Json(MyResult.Success()));
     }
     catch (MyException ex)
     {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "发布菜单失败");
         return(Json(MyResult.Error("发布菜单失败")));
     }
 }
Exemplo n.º 2
0
        public JsonResult GetMasterMenu(string companyId)
        {
            Dictionary <string, string> dicMenu = new Dictionary <string, string>();

            dicMenu.Add("-1", "一级菜单");
            JsonResult     json  = new JsonResult();
            List <WX_Menu> menus = WXMenuServices.GetMenus(companyId).Where(p => p.MasterID == null || p.MasterID == 0).ToList();

            foreach (var item in menus)
            {
                dicMenu.Add(item.ID.ToString(), item.MenuName);
            }
            var result = from p in dicMenu
                         select new
            {
                id   = p.Key,
                text = p.Value
            };

            json.Data = result;
            return(json);
        }
Exemplo n.º 3
0
        private void CheckMenu(int?masterId, int id, string companyId)
        {
            if (id > 1)
            {
                return;
            }

            List <WX_Menu> menus = WXMenuServices.GetMenus(companyId);

            if (masterId.HasValue)
            {
                if (menus.Count(p => p.MasterID == masterId) >= 5)
                {
                    throw new MyException("最多只能添加5个二级菜单");
                }
            }
            else
            {
                if (menus.Count(p => p.MasterID == null || p.MasterID == 0) >= 3)
                {
                    throw new MyException("最多只能添加3个一级级菜单");
                }
            }
        }
Exemplo n.º 4
0
        public string GetMenuData(string companyId)
        {
            try
            {
                List <WX_Menu> menus = WXMenuServices.GetMenus(companyId);

                string         json     = "{\"rows\":[";
                List <WX_Menu> topMenus = menus.Where(p => p.MasterID == 0).OrderBy(p => p.Sort).ToList();
                foreach (WX_Menu dr in topMenus)
                {
                    var    childs       = menus.Where(p => p.MasterID == dr.ID).OrderBy(o => o.Sort);
                    string masterId     = dr.MasterID != 0 ? dr.MasterID.ToString() : string.Empty;
                    string hasChildMenu = childs.Count() > 0 ? "1" : "0";
                    json += "{\"id\":\"" + dr.ID + "\"";
                    json += ",\"MenuName\":\"" + dr.MenuName + "\"";
                    json += ",\"Url\":\"" + dr.Url + "\"";
                    json += ",\"KeywordId\":\"" + GetKeywordId(dr) + "\"";
                    json += ",\"ModuleId\":\"" + GetModuleId(dr) + "\"";
                    json += ",\"CompanyID\":\"" + dr.CompanyID + "\"";
                    json += ",\"MenuType\":" + (int)dr.MenuType + "";
                    json += ",\"MenuTypeDes\":\"" + GetMenuTypeDescription(menus, dr.ID) + "\"";
                    json += ",\"MenuTypeValue\":\"" + GetMenuTypeValue(menus, dr.ID) + "\"";
                    json += ",\"Sort\":\"" + dr.Sort + "\"";
                    json += ",\"MasterID\":\"" + masterId + "\"";
                    json += ",\"MinIprogramAppId\":\"" + dr.MinIprogramAppId + "\"";
                    json += ",\"MinIprogramPagePath\":\"" + dr.MinIprogramPagePath + "\"";
                    json += ",\"HasChildMenu\":\"" + hasChildMenu + "\"";
                    json += ",\"iconCls\":\"my-menu-icon\"},";

                    foreach (var obj in childs)
                    {
                        string childmasterId = obj.MasterID == 0 ? obj.MasterID.ToString() : string.Empty;

                        json += "{\"id\":\"" + obj.ID + "\"";
                        json += ",\"MenuName\":\"" + obj.MenuName + "\"";
                        json += ",\"Url\":\"" + obj.Url + "\"";
                        json += ",\"KeywordId\":\"" + GetKeywordId(obj) + "\"";
                        json += ",\"ModuleId\":\"" + GetModuleId(obj) + "\"";
                        json += ",\"CompanyID\":\"" + dr.CompanyID + "\"";
                        json += ",\"MenuType\":" + (int)obj.MenuType + "";
                        json += ",\"MenuTypeDes\":\"" + GetMenuTypeDescription(menus, obj.ID) + "\"";
                        json += ",\"MenuTypeValue\":\"" + GetMenuTypeValue(menus, obj.ID) + "\"";
                        json += ",\"Sort\":\"" + obj.Sort + "\"";
                        json += ",\"MasterID\":\"" + obj.MasterID + "\"";
                        json += ",\"MinIprogramAppId\":\"" + obj.MinIprogramAppId + "\"";
                        json += ",\"MinIprogramPagePath\":\"" + obj.MinIprogramPagePath + "\"";
                        json += ",\"HasChildMenu\":\"0\"";
                        json += ",\"_parentId\":\"" + dr.ID + "\"";
                        json += ",\"iconCls\":\"my-menu-icon\"},";
                    }
                }
                if (topMenus.Count() > 0)
                {
                    json = json.Substring(0, json.Length - 1);
                }
                json += "]}";
                return(json);
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "微信菜单管理获取菜单失败");
                return("{\"rows\":[]}");
            }
        }