Ejemplo n.º 1
0
 protected void lnk_Delete_Click(object sender, System.EventArgs e)
 {
     if (!base.IsAuthorizedOp(ActionType.Delete.ToString()))
     {
         base.ShowAjaxMsg(this.UpdatePanel1, "Không có thẩm quyền");
     }
     else
     {
         int        @int     = WebUtils.GetInt((sender as LinkButton).CommandArgument);
         WxMenuInfo dataById = WxMenu.GetDataById(@int);
         if (dataById == null)
         {
             base.ShowAjaxMsg(this.UpdatePanel1, "Những thông tin này không được tìm thấy, các dữ liệu không tồn tại hoặc đã bị xóa");
         }
         else if (dataById.ChildCount > 0)
         {
             base.ShowAjaxMsg(this.UpdatePanel1, "包含子菜单,请先删除子菜单");
         }
         else if (WxMenu.Del(@int))
         {
             this.BindData();
             PageBase.log.AddEvent(base.LoginAccount.AccountName, "删除微信菜单[" + dataById.Name + "] thành công");
             base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công");
         }
         else
         {
             base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại");
         }
     }
 }
Ejemplo n.º 2
0
        internal WxMenu GetWxmenuByOperType(int opertype, int comid)
        {
            string sql = "select top 1 * from wxmenu  where operationtypeid=" + opertype + " and comid=" + comid;

            try
            {
                var cmd = sqlHelper.PrepareTextSqlCommand(sql);


                using (var reader = cmd.ExecuteReader())
                {
                    WxMenu m = null;
                    if (reader.Read())
                    {
                        m = new WxMenu
                        {
                            Menuid            = reader.GetValue <int>("Menuid"),
                            Name              = reader.GetValue <string>("Name"),
                            Instruction       = reader.GetValue <string>("instruction"),
                            Operationtypeid   = reader.GetValue <int>("operationtypeid"),
                            Linkurl           = reader.GetValue <string>("linkurl"),
                            Wxanswertext      = reader.GetValue <string>("wxanswertext"),
                            SalePromoteTypeid = reader.GetValue <int>("SalePromoteTypeid"),
                            Fathermenuid      = reader.GetValue <int>("fathermenuid")
                        };
                    }
                    return(m);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public void SubmitForm(string menuData)
        {
            string appId         = WxOperatorProvider.Provider.GetCurrent().AppId;
            var    specification = new Specification <WxMenu>(obj => obj.AppId == appId);
            WxMenu wxMenu        = wxMenuRepository.Find(specification);

            if (wxMenu == null)
            {
                wxMenu              = new WxMenu();
                wxMenu.Id           = IdWorkerHelper.GenId64();
                wxMenu.AppId        = appId;
                wxMenu.MenuData     = menuData;
                wxMenu.CreationTime = System.DateTime.Now;
                wxMenu.DeletedMark  = false;
                wxMenuRepository.Add(wxMenu);
            }
            else
            {
                wxMenu.MenuData             = menuData;
                wxMenu.LastModificationTime = System.DateTime.Now;
                wxMenuRepository.Update(wxMenu);
            }
            JObject jo     = (JObject)JsonConvert.DeserializeObject(menuData);
            JObject menu   = (JObject)jo["menu"];
            JArray  button = (JArray)menu["button"];

            Debug.WriteLine(menu.ToString());
            AccessTokenResult accessTokenResult = AccessTokenContainer.GetAccessTokenResult(appId);

            WxJsonResult wxJsonResult = CommonApi.CreateMenu(accessTokenResult.access_token, menu);
        }
Ejemplo n.º 4
0
 public int EditWxMenu(WxMenu wxmenu)
 {
     using (var helper = new SqlHelper())
     {
         var id = new InternalWxMenu(helper).EditWxMenu(wxmenu);
         return(id);
     }
 }
Ejemplo n.º 5
0
        public WxMenu GetForm()
        {
            string appId         = WxOperatorProvider.Provider.GetCurrent().AppId;
            var    specification = new Specification <WxMenu>(obj => obj.AppId == appId);
            WxMenu wxMenu        = wxMenuRepository.Find(specification);

            return(wxMenu);
        }
Ejemplo n.º 6
0
        private void updateMenuName(ref JsonData Result)
        {
            var    id   = this.getInt("id");
            var    text = this.getString("text");
            WxMenu m    = bll.GetModel <WxMenu>(id);

            m.BtnName = text;
            bll.Update(m);
        }
Ejemplo n.º 7
0
        public async Task PullMenuAsync(string accessTokenOrAppId, int siteId)
        {
            var result = CommonApi.GetMenu(accessTokenOrAppId);

            if (result == null)
            {
                return;
            }

            await _wxMenuRepository.DeleteAllAsync(siteId);

            var json    = result.menu.button.ToJson();
            var buttons = TranslateUtils.JsonDeserialize <List <MenuFull_RootButton> >(json);

            var firstTaxis = 1;

            foreach (var button in buttons)
            {
                var first = new WxMenu
                {
                    SiteId   = siteId,
                    ParentId = 0,
                    Taxis    = firstTaxis++,
                    Text     = button.name,
                    MenuType = TranslateUtils.ToEnum(button.type, WxMenuType.View),
                    Key      = button.key,
                    Url      = button.url,
                    AppId    = button.appid,
                    PagePath = button.pagepath,
                    MediaId  = button.media_id
                };
                var menuId = await _wxMenuRepository.InsertAsync(first);

                if (button.sub_button != null && button.sub_button.Count > 0)
                {
                    var childTaxis = 1;
                    foreach (var sub in button.sub_button)
                    {
                        var child = new WxMenu
                        {
                            SiteId   = siteId,
                            ParentId = menuId,
                            Taxis    = childTaxis++,
                            Text     = sub.name,
                            MenuType = TranslateUtils.ToEnum(sub.type, WxMenuType.View),
                            Key      = sub.key,
                            Url      = sub.url,
                            AppId    = sub.appid,
                            PagePath = sub.pagepath,
                            MediaId  = sub.media_id
                        };
                        await _wxMenuRepository.InsertAsync(child);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void BindParentMenu()
 {
     System.Collections.Generic.IList <WxMenuInfo> list = WxMenu.GetList(3, "ParentID=0", "Sort asc");
     if (list != null)
     {
         this.parentmenu.DataSource     = list;
         this.parentmenu.DataTextField  = "Name";
         this.parentmenu.DataValueField = "AutoID";
         this.parentmenu.DataBind();
     }
     this.parentmenu.Items.Insert(0, new ListItem("做为顶级菜单", "0"));
 }
Ejemplo n.º 9
0
        private void updateMenuOrder(ref JsonData Result)
        {
            var id       = this.getInt("id");
            var pid      = this.getInt("pid");
            var ordernum = this.getInt("ordernum");

            WxMenu m = bll.GetModel <WxMenu>(id);

            m.PID        = pid;
            m.OrderNum   = ordernum;
            m.UpdateTime = DateTime.Now;
            bll.Update(m);
        }
Ejemplo n.º 10
0
        public WxMenu GetMenu()
        {
            WxMenu menu        = null;
            var    accessToken = GetAccessToken();
            var    data        = string.Format("access_token={0}", accessToken);
            var    menuList    = GetJosnData <WxMenuList>(data, WxConfig.MenuUrlGet);

            if (menuList != null)
            {
                menu = menuList.menu;
            }
            return(menu);
        }
Ejemplo n.º 11
0
        internal WxMenu GetWxMenu(int menuid, int comid)
        {
            string sql = @"SELECT  [menuid]
      ,[name]
      ,[instruction]
      ,[linkurl]
      ,[fathermenuid]
      ,[operationtypeid]
      ,[SalePromoteTypeid]
      ,[wxanswertext]
 ,[comid]
,product_class
,keyy
,pictexttype 
  FROM [EtownDB].[dbo].[WxMenu] where menuid=@menuid and comid=@comid";
            var    cmd = sqlHelper.PrepareTextSqlCommand(sql);

            cmd.AddParam("@menuid", menuid);
            cmd.AddParam("@comid", comid);

            using (var reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    WxMenu wxMenu = new WxMenu();
                    wxMenu.Menuid            = reader.GetValue <int>("Menuid");
                    wxMenu.Name              = reader.GetValue <string>("Name");
                    wxMenu.Instruction       = reader.GetValue <string>("Instruction");
                    wxMenu.Linkurl           = reader.GetValue <string>("Linkurl");
                    wxMenu.Fathermenuid      = reader.GetValue <int>("Fathermenuid");
                    wxMenu.Operationtypeid   = reader.GetValue <int>("Operationtypeid");
                    wxMenu.SalePromoteTypeid = reader.GetValue <int>("SalePromoteTypeid");
                    wxMenu.Wxanswertext      = reader.GetValue <string>("Wxanswertext");
                    wxMenu.Comid             = reader.GetValue <int>("comid");
                    wxMenu.Product_class     = reader.GetValue <int>("product_class");
                    wxMenu.Keyy              = reader.GetValue <string>("keyy");
                    wxMenu.pictexttype       = reader.GetValue <int>("pictexttype");

                    reader.Close();

                    return(wxMenu);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 12
0
        internal List <WxMenu> GetSecondMenuList(int fatherid, int comid, out int totalcount)
        {
            string sqlsecondlist = @"SELECT   [menuid]
      ,[name]
      ,[instruction]
      ,[linkurl]
      ,[fathermenuid]
      ,[operationtypeid]
      ,[SalePromoteTypeid]
      ,[wxanswertext]
      ,[comid]
     , product_class
FROM [EtownDB].[dbo].[WxMenu] where fathermenuid=@fathermenuid and comid=@comid order by sortid ";
            var    cmd           = sqlHelper.PrepareTextSqlCommand(sqlsecondlist);

            cmd.AddParam("@fathermenuid", fatherid);
            cmd.AddParam("@comid", comid);


            List <WxMenu> list = new List <WxMenu>();

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    WxMenu wxmenu = new WxMenu();

                    wxmenu.Menuid            = reader.GetValue <int>("Menuid");
                    wxmenu.Name              = reader.GetValue <string>("Name");
                    wxmenu.Instruction       = reader.GetValue <string>("instruction");
                    wxmenu.Operationtypeid   = reader.GetValue <int>("operationtypeid");
                    wxmenu.Linkurl           = reader.GetValue <string>("linkurl");
                    wxmenu.Wxanswertext      = reader.GetValue <string>("wxanswertext");
                    wxmenu.SalePromoteTypeid = reader.GetValue <int>("SalePromoteTypeid");
                    wxmenu.Fathermenuid      = reader.GetValue <int>("fathermenuid");
                    wxmenu.Product_class     = reader.GetValue <int>("product_class");

                    list.Add(wxmenu);
                }
            }
            totalcount = list.Count;

            return(list);
        }
Ejemplo n.º 13
0
        internal List <WxMenu> GetFristMenuList(int pageindex, int pagesize, int comid, out int totalcount)
        {
            var cmd          = this.sqlHelper.PrepareStoredSqlCommand("usp_PagingLarge");
            var tblName      = "WxMenu";
            var strGetFields = "*";
            var sortKey      = "sortid";
            var sortMode     = "0";

            var condition = "";

            condition += "fathermenuid=0 and comid=" + comid;


            cmd.PagingCommand(tblName, strGetFields, pageindex, pagesize, sortKey, sortMode, condition);


            List <WxMenu> list = new List <WxMenu>();

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    WxMenu wxmenu = new WxMenu();

                    wxmenu.Menuid            = reader.GetValue <int>("Menuid");
                    wxmenu.Name              = reader.GetValue <string>("Name");
                    wxmenu.Instruction       = reader.GetValue <string>("instruction");
                    wxmenu.Operationtypeid   = reader.GetValue <int>("operationtypeid");
                    wxmenu.Linkurl           = reader.GetValue <string>("linkurl");
                    wxmenu.Wxanswertext      = reader.GetValue <string>("wxanswertext");
                    wxmenu.SalePromoteTypeid = reader.GetValue <int>("SalePromoteTypeid");
                    wxmenu.Fathermenuid      = reader.GetValue <int>("fathermenuid");
                    wxmenu.Product_class     = reader.GetValue <int>("product_class");


                    list.Add(wxmenu);
                }
            }
            totalcount = int.Parse(cmd.Parameters[7].Value.ToString());

            return(list);
        }
Ejemplo n.º 14
0
        private string getBtnStr(WxMenu btn, bool hasChild)
        {
            string btnstr = "";

            if (hasChild)
            {
                btnstr = "{\"name\":\"" + btn.BtnName + "\",\"sub_button\":[";
            }
            else
            {
                if (btn.BtnType == "view")
                {
                    btnstr = "{\"type\":\"view\",\"name\":\"" + btn.BtnName + "\",\"url\":\"" + btn.ReplyUrl + "\"}";
                }
                else
                {
                    btnstr = "{\"type\":\"click\",\"name\":\"" + btn.BtnName + "\",\"key\":\"" + btn.BtnKey + "\"}";
                }
            }
            return(btnstr);
        }
Ejemplo n.º 15
0
        private void addMenu(ref JsonData Result)
        {
            var pid      = this.getInt("pid");
            var text     = this.getString("text");
            var type     = this.getString("type");
            var ordernum = this.getInt("ordernum");
            int id       = bll.Add(new WxMenu()
            {
                PID = pid, BtnName = text, BtnType = "click", OrderNum = ordernum, ReplyType = -1, ReplyID = -1, UpdateTime = DateTime.Now
            });
            WxMenu obj = bll.GetModel <WxMenu>(id);

            if (type == "main")
            {
                obj.BtnKey = "m" + id;
            }
            else
            {
                obj.BtnKey = "s" + id;
            }
            bll.Update(obj);
        }
Ejemplo n.º 16
0
        internal int EditWxMenu(WxMenu model)
        {
            var cmd = sqlHelper.PrepareStoredSqlCommand(SQLInsertOrUpdate);

            cmd.AddParam("@Menuid", model.Menuid);
            cmd.AddParam("@Name", model.Name);
            cmd.AddParam("@Instruction", model.Instruction);
            cmd.AddParam("@Operationtypeid", model.Operationtypeid);
            cmd.AddParam("@Linkurl", model.Linkurl);
            cmd.AddParam("@Wxanswertext", model.Wxanswertext);
            cmd.AddParam("@Fathermenuid", model.Fathermenuid);
            cmd.AddParam("@SalePromoteTypeid", model.SalePromoteTypeid);
            cmd.AddParam("@Comid", model.Comid);
            cmd.AddParam("@ProductClass", model.Product_class);
            cmd.AddParam("@Keyy", model.Keyy);
            cmd.AddParam("@pictexttype", model.pictexttype);


            var parm = cmd.AddReturnValueParameter("ReturnValue");

            cmd.ExecuteNonQuery();
            return((int)parm.Value);
        }
Ejemplo n.º 17
0
        private void InitForModify()
        {
            WxMenuInfo dataById = WxMenu.GetDataById(base.OpID);

            this.InitMenuType = dataById.Type;
            ListItem listItem = this.parentmenu.Items.FindByValue(dataById.ParentID.ToString());

            if (listItem != null)
            {
                listItem.Selected = true;
            }
            this.parentmenu.Enabled = false;
            this.menuname.Text      = dataById.Name;
            ListItem listItem2 = this.menutype.Items.FindByValue(dataById.Type);

            if (listItem2 != null)
            {
                listItem2.Selected = true;
            }
            if (dataById.Type == "click" && !string.IsNullOrEmpty(dataById.EventKey))
            {
                AutoRlyInfo eventRly = AutoRly.GetEventRly(dataById.EventKey);
                if (eventRly != null)
                {
                    this.TextBox1.Text   = eventRly.MsgText;
                    this.TextBox2.Text   = eventRly.MediaPath;
                    this.Image1.ImageUrl = eventRly.MediaPath;
                    this.TextBox3.Text   = eventRly.Description;
                    this.TextBox4.Text   = eventRly.LinkUrl;
                }
            }
            else
            {
                this.TextBox4.Text = dataById.Url;
            }
        }
Ejemplo n.º 18
0
 protected void btnok_Click(object sender, System.EventArgs e)
 {
     if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString()))
     {
         base.ShowMsg("Không có thẩm quyền");
     }
     else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString()))
     {
         base.ShowMsg("Không có thẩm quyền");
     }
     else
     {
         WxMenuInfo wxMenuInfo = new WxMenuInfo();
         if (base.IsEdit)
         {
             wxMenuInfo = WxMenu.GetDataById(base.OpID);
         }
         wxMenuInfo.ParentID = WebUtils.GetInt(this.parentmenu.SelectedValue);
         wxMenuInfo.Name     = WebUtils.GetString(this.menuname.Text);
         wxMenuInfo.Type     = this.menutype.SelectedValue;
         wxMenuInfo.Url      = WebUtils.GetString(this.TextBox4.Text);
         wxMenuInfo.EventKey = string.Empty;
         AutoRlyInfo autoRlyInfo = new AutoRlyInfo
         {
             RlyType     = "事件回复",
             MsgKey      = StringUtils.GetRandomNumber(),
             MsgText     = WebUtils.GetString(this.TextBox1.Text),
             MediaPath   = WebUtils.GetString(this.TextBox2.Text),
             Description = WebUtils.GetString(this.TextBox3.Text),
             LinkUrl     = WebUtils.GetString(this.TextBox4.Text)
         };
         if (string.IsNullOrEmpty(wxMenuInfo.Name))
         {
             base.ShowMsg("菜单名称不能为空");
         }
         else if (wxMenuInfo.ParentID == 0 && wxMenuInfo.Name.Length > 4)
         {
             base.ShowMsg("一级菜单文字长度不超过4个汉字");
         }
         else if (wxMenuInfo.ParentID > 0 && wxMenuInfo.Name.Length > 8)
         {
             base.ShowMsg("二级菜单文字长度不超过8个汉字");
         }
         else if (wxMenuInfo.Type == "click" && string.IsNullOrEmpty(autoRlyInfo.MsgText))
         {
             base.ShowMsg("图文推送文本不能为空");
         }
         else if (wxMenuInfo.Type == "click" && (autoRlyInfo.MsgText.Length > 600 || autoRlyInfo.Description.Length > 600))
         {
             base.ShowMsg("推送图文中的文本不能超过600汉字");
         }
         else if (wxMenuInfo.Type == "view" && string.IsNullOrEmpty(autoRlyInfo.LinkUrl))
         {
             base.ShowMsg("地址跳转的地址不能为空");
         }
         else
         {
             if (base.Action.Equals(ActionType.Add.ToString()))
             {
                 wxMenuInfo.Sort          = WxMenu.MaxSort + 1;
                 wxMenuInfo.AutoTimeStamp = System.DateTime.Now;
                 WxStatus wxStatus = WxMenu.Add(wxMenuInfo, autoRlyInfo);
                 if (wxStatus == WxStatus.增加成功)
                 {
                     PageBase.log.AddEvent(base.LoginAccount.AccountName, "添加微信菜单[" + wxMenuInfo.Name + "] thành công");
                     MessageUtils.DialogCloseAndParentReload(this);
                 }
                 else
                 {
                     base.ShowMsg(wxStatus.ToString());
                 }
             }
             if (base.Action.Equals(ActionType.Modify.ToString()))
             {
                 WxStatus wxStatus2 = WxMenu.Update(wxMenuInfo, autoRlyInfo);
                 if (wxStatus2 == WxStatus.修改成功)
                 {
                     PageBase.log.AddEvent(base.LoginAccount.AccountName, "修改微信菜单[" + wxMenuInfo.Name + "] thành công");
                     MessageUtils.DialogCloseAndParentReload(this);
                 }
                 else
                 {
                     base.ShowMsg(wxStatus2.ToString());
                 }
             }
         }
     }
 }
Ejemplo n.º 19
0
 public async Task UpdateAsync(WxMenu menu)
 {
     await _repository.UpdateAsync(menu, Q
                                   .CachingRemove(GetCacheKey(menu.SiteId))
                                   );
 }
Ejemplo n.º 20
0
        public ActionResult SubmitForm(WxMenu entity, string keyValue)
        {
            try
            {
                MenuManage         mMrg   = new MenuManage();
                WxBaseConfigEntity weixin = app.GetDefaultConfig();
                AccessTokenResult  token  = AccessTokenContainer.GetAccessTokenResult(weixin.AppId);
                if (token.errcode != Senparc.Weixin.ReturnCode.请求成功)
                {
                    return(Error(token.errmsg));
                }

                //重新整理按钮信息
                ButtonGroup          bg      = new ButtonGroup();
                IList <BaseButton>   topList = new List <BaseButton>();
                IList <SingleButton> subList = new List <SingleButton>();
                #region 菜单设置
                for (int i = 0; i < 3; i++)
                {
                    string txtName = (string)ForeachClass.GetValue <WxMenu>(entity, "Top" + (i + 1));
                    string txtKey  = (string)ForeachClass.GetValue <WxMenu>(entity, "Top" + (i + 1) + "Key");
                    string txtUrl  = (string)ForeachClass.GetValue <WxMenu>(entity, "Top" + (i + 1) + "Url");
                    if (string.IsNullOrEmpty(txtName))
                    {
                        // 如果名称为空,则忽略该菜单,以及下面的子菜单
                        continue;
                    }
                    subList = new List <SingleButton>();
                    string txtSubName;
                    string txtSubKey;
                    string txtSubUrl;
                    for (int j = 0; j < 5; j++)
                    {
                        #region 子菜单的设置
                        txtSubName = (string)ForeachClass.GetValue <WxMenu>(entity, "Menu" + (i + 1) + (j + 1));
                        txtSubKey  = (string)ForeachClass.GetValue <WxMenu>(entity, "Menu" + (i + 1) + (j + 1) + "Key");
                        txtSubUrl  = (string)ForeachClass.GetValue <WxMenu>(entity, "Menu" + (i + 1) + (j + 1) + "Url");
                        if (string.IsNullOrEmpty(txtSubName))
                        {
                            continue;
                        }

                        if (!string.IsNullOrEmpty(txtSubUrl))
                        {
                            SingleViewButton sub = new SingleViewButton();
                            sub.name = txtSubName.Trim();
                            sub.url  = Utils.UrlDecode(txtSubUrl.Trim());
                            subList.Add(sub);
                        }
                        else if (!string.IsNullOrEmpty(txtSubKey))
                        {
                            SingleClickButton sub = new SingleClickButton();
                            sub.name = txtSubName.Trim();
                            sub.key  = txtSubKey.Trim();
                            subList.Add(sub);
                        }
                        else
                        {
                            //报错 :子菜单必须有key和name
                            return(Error("二级菜单的名称和key或者url必填!"));

                            ;
                        }
                        #endregion
                    } //子菜单循环结束


                    if (subList != null && subList.Count > 0)
                    {
                        //有子菜单, 该一级菜单是SubButton
                        if (subList.Count < 1)
                        {
                            return(Error("子菜单个数为2~5个!"));
                        }
                        SubButton topButton = new SubButton(Utils.CutString(txtName.Trim(), 16));
                        topButton.sub_button.AddRange(subList);
                        topList.Add(topButton);
                    }
                    else
                    {
                        // 无子菜单
                        if (string.IsNullOrEmpty(txtKey) && string.IsNullOrEmpty(txtUrl))
                        {
                            return(Error("若无子菜单,必须填写key或者url值!"));
                        }

                        if (!string.IsNullOrEmpty(txtUrl))
                        {  //view 页面跳转
                            SingleViewButton topSingleButton = new SingleViewButton();
                            topSingleButton.name = txtName.Trim();
                            topSingleButton.url  = Utils.UrlDecode(txtUrl.Trim());
                            topList.Add(topSingleButton);
                        }
                        else if (!string.IsNullOrEmpty(txtKey))
                        {
                            SingleClickButton topSingleButton = new SingleClickButton();
                            topSingleButton.name = txtName.Trim();
                            topSingleButton.key  = txtKey.Trim();
                            topList.Add(topSingleButton);
                        }
                    }
                }
                #endregion

                bg.button.AddRange(topList);

                var result = mMrg.CreateMenu(token.access_token, bg);
                return(Success("菜单提交成功!"));
            }
            catch (Exception ex)
            {
                return(Error("报错:" + ex.Message));
            }
        }
Ejemplo n.º 21
0
        private void LoadFromServer()
        {
            AccessTokenResult token             = CommonApi.GetToken(SinGooCMS.Weixin.Config.AppID, SinGooCMS.Weixin.Config.AppSecret, "client_credential");
            string            strUrl            = string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", token.access_token);
            string            strValue          = NetWorkUtils.HttpGet(strUrl);
            GetMenuResultFull getMenuResultFull = JsonUtils.JsonToObject <GetMenuResultFull>(strValue);

            if (getMenuResultFull != null && getMenuResultFull.menu != null && getMenuResultFull.menu.button.Count > 0)
            {
                WxMenu.EmptyLocal();
                int num = 1;
                foreach (MenuFull_RootButton current in getMenuResultFull.menu.button)
                {
                    WxMenuInfo wxMenuInfo = new WxMenuInfo
                    {
                        RootID        = 0,
                        ParentID      = 0,
                        Type          = (current.type ?? string.Empty),
                        Name          = current.name,
                        EventKey      = (current.key ?? string.Empty),
                        Url           = (current.url ?? string.Empty),
                        ChildCount    = 0,
                        ChildIDs      = string.Empty,
                        Sort          = num,
                        AutoTimeStamp = System.DateTime.Now
                    };
                    int num2 = WxMenu.Add(wxMenuInfo);
                    if (num2 > 0)
                    {
                        wxMenuInfo.AutoID = num2;
                        wxMenuInfo.RootID = num2;
                        num++;
                        if (current.sub_button != null && current.sub_button.Count > 0)
                        {
                            wxMenuInfo.ChildCount = current.sub_button.Count;
                            int num3 = 1;
                            foreach (MenuFull_RootButton current2 in current.sub_button)
                            {
                                WxMenuInfo entity = new WxMenuInfo
                                {
                                    RootID        = num2,
                                    ParentID      = num2,
                                    Type          = (current2.type ?? string.Empty),
                                    Name          = current2.name,
                                    EventKey      = (current2.key ?? string.Empty),
                                    Url           = (current2.url ?? string.Empty),
                                    ChildCount    = 0,
                                    ChildIDs      = string.Empty,
                                    Sort          = num3,
                                    AutoTimeStamp = System.DateTime.Now
                                };
                                int num4 = WxMenu.Add(entity);
                                if (num4 > 0)
                                {
                                    WxMenuInfo expr_27E = wxMenuInfo;
                                    expr_27E.ChildIDs = expr_27E.ChildIDs + num4 + ",";
                                    num3++;
                                }
                            }
                        }
                        if (wxMenuInfo.ChildIDs.EndsWith(","))
                        {
                            wxMenuInfo.ChildIDs = wxMenuInfo.ChildIDs.TrimEnd(new char[]
                            {
                                ','
                            });
                        }
                        WxMenu.Update(wxMenuInfo);
                    }
                }
            }
            this.BindData();
        }
Ejemplo n.º 22
0
        protected void btnok_Click(object sender, System.EventArgs e)
        {
            AccessTokenResult token = CommonApi.GetToken(SinGooCMS.Weixin.Config.AppID, SinGooCMS.Weixin.Config.AppSecret, "client_credential");

            System.Collections.Generic.List <WxMenuInfo>     list             = WxMenu.GetList(15, "", " RootID ASC,ParentID ASC,Sort ASC ") as System.Collections.Generic.List <WxMenuInfo>;
            System.Collections.Generic.Dictionary <int, int> repeaterSortDict = base.GetRepeaterSortDict(this.Repeater1, "txtsort", "autoid");
            foreach (WxMenuInfo current in list)
            {
                current.Sort = repeaterSortDict[current.AutoID];
            }
            list = (from p in list
                    orderby p.RootID
                    orderby p.ParentID
                    orderby p.Sort
                    select p).ToList <WxMenuInfo>();
            if (WxMenu.UpdateSort(repeaterSortDict))
            {
                PageBase.log.AddEvent(base.LoginAccount.AccountName, "更新微信菜单排序成功");
            }
            ButtonGroup buttonGroup = new ButtonGroup();

            foreach (WxMenuInfo level1 in list)
            {
                if (level1.ParentID.Equals(0))
                {
                    if (level1.ChildCount > 0)
                    {
                        SubButton subButton = new SubButton
                        {
                            name = level1.Name
                        };
                        System.Collections.Generic.IEnumerable <WxMenuInfo> enumerable = from p in list
                                                                                         where p.ParentID.Equals(level1.AutoID)
                                                                                         select p;
                        if (enumerable != null && enumerable.Count <WxMenuInfo>() > 0)
                        {
                            foreach (WxMenuInfo current2 in enumerable)
                            {
                                string type = current2.Type;
                                if (type != null)
                                {
                                    if (!(type == "click"))
                                    {
                                        if (type == "view")
                                        {
                                            subButton.sub_button.Add(new SingleViewButton
                                            {
                                                name = current2.Name,
                                                url  = current2.Url
                                            });
                                        }
                                    }
                                    else
                                    {
                                        subButton.sub_button.Add(new SingleClickButton
                                        {
                                            name = current2.Name,
                                            key  = current2.EventKey
                                        });
                                    }
                                }
                            }
                        }
                        buttonGroup.button.Add(subButton);
                    }
                    else
                    {
                        string type = level1.Type;
                        if (type != null)
                        {
                            if (!(type == "click"))
                            {
                                if (type == "view")
                                {
                                    buttonGroup.button.Add(new SingleViewButton
                                    {
                                        name = level1.Name,
                                        url  = level1.Url
                                    });
                                }
                            }
                            else
                            {
                                buttonGroup.button.Add(new SingleClickButton
                                {
                                    name = level1.Name,
                                    key  = level1.EventKey
                                });
                            }
                        }
                    }
                }
            }
            Senparc.Weixin.Entities.WxJsonResult wxJsonResult = Senparc.Weixin.MP.CommonAPIs.CommonApi.CreateMenu(token.access_token, buttonGroup, 10000);
            if (wxJsonResult.errcode == ReturnCode.请求成功)
            {
                PageBase.log.AddEvent(base.LoginAccount.AccountName, "更新微信菜单成功");
                base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công");
                this.BindData();
            }
            else
            {
                PageBase.log.AddErrLog("更新微信菜单出错了", wxJsonResult.errmsg);
                base.ShowAjaxMsg(this.UpdatePanel1, wxJsonResult.errmsg);
            }
        }
Ejemplo n.º 23
0
        public ActionResult Add(WxMenuModel model)
        {
            if (ModelState.IsValid)
            {
                var isOk = RunWithCatch((ms) =>
                {
                    var entity      = new WxMenu();
                    entity.Name     = model.Name;
                    entity.Content  = model.BindValue;
                    entity.Bind     = model.Bind;
                    entity.Type     = model.BindType;
                    entity.ParentId = model.ParentId;
                    entity.Sequence = model.Sequence;

                    BindType bindType = model.Bind;
                    switch (bindType)
                    {
                    case BindType.Key:
                        entity.ReplyId = model.BindValue;
                        break;

                    case BindType.Topic:
                        entity.Content = model.BindTopic;
                        break;

                    default:
                        if (bindType == BindType.Url)
                        {
                            entity.Content = model.Url;
                        }
                        break;
                    }
                    entity.Client = MenuClient.Weixin;
                    entity.Type   = "click";
                    if (entity.ParentId.IsBlank())
                    {
                        entity.Type = "view";
                    }
                    else if (entity.Bind == BindType.None)
                    {
                        ms.AddModelError("Bind", "二级菜单必须绑定一个对象");
                        return(false);
                    }

                    _repository.Insert(entity);
                    return(true);
                });

                if (isOk)
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                model.BindTypes = SelectListItems.FromEnum(model.Bind).ToArray();

                model.Keywords = _wxReplyRepository.Query()
                                 .Select(x => new { x.Sequence, x.Id, x.Content })
                                 .OrderByDescending(x => x.Sequence)
                                 .ToList()
                                 .Select(x => new SelectListItem
                {
                    Value    = x.Id,
                    Text     = x.Content,
                    Selected = model.BindValue == x.Id
                }).ToArray();

                model.Topics = new SelectListItem[] { };
            }
            return(View(model));
        }
Ejemplo n.º 24
0
 public async Task <int> InsertAsync(WxMenu menu)
 {
     return(await _repository.InsertAsync(menu, Q
                                          .CachingRemove(GetCacheKey(menu.SiteId))
                                          ));
 }
Ejemplo n.º 25
0
        public ActionResult PublishWXMenus()
        {
            KeyValueModel ret = new KeyValueModel {
                Key = "error", Value = "操作失败!"
            },
                          successret = new KeyValueModel {
                Key = "success", Value = "操作成功!"
            };

            try
            {
                using (WechatEntities context = new WechatEntities())
                {
                    var menus = context.T_Wx_Menus.Where(m => m.IsDeleted == false);
                    #region 一级菜单
                    var menubuttons = menus.Where(k => k.MenuLevel == "button").OrderBy(g => g.SortNum)
                                      .Select(p => new WxButtonMenu
                    {
                        key  = p.MenuId,
                        name = p.MenuName,
                        type = p.MenuType,
                        url  = p.MenuUrl
                    })
                                      .ToList();
                    #endregion

                    #region 二级菜单
                    foreach (var mn in menubuttons)
                    {
                        mn.sub_button = menus.Where(k => k.ParentMenu == mn.key).OrderBy(o => o.SortNum).Select(p => new WxBaseMenu
                        {
                            key  = p.MenuId,
                            name = p.MenuName,
                            type = p.MenuType,
                            url  = p.MenuUrl,
                        })
                                        .ToList();
                    }
                    #endregion

                    WxMenu btn = new WxMenu
                    {
                        button = menubuttons
                    };

                    WXApiUrl WXApiUrl        = new WXApiUrl();
                    string   CreateWxMenuUrl = string.Format(WXApiUrl.Dic_WXUrls[WXApiUrl.Enum_WXUrls.CreateWxMenu], new Utils().GetAccessToken());
                    string   backmsg         = wxCOM.Utils.SendPostHttpRequest(CreateWxMenuUrl, JsonConvert.SerializeObject(btn));
                    RetMsg   retmsg          = JsonConvert.DeserializeObject <RetMsg>(backmsg);
                    if (retmsg.errcode != 0)
                    {
                        ret.Value = RetMsg.DicWxRetMsg[retmsg.errcode];
                    }
                    else
                    {
                        ret = successret;
                    }
                }
            }
            catch (Exception ex)
            {
                ret.Value = ex.Message;
            }
            return(Json(ret, JsonRequestBehavior.AllowGet));
        }