예제 #1
0
        /// <summary>
        /// 删除自定义菜单
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public Hashtable MenuDelete(string accessToken)
        {
            Hashtable retHash = new Hashtable();

            string    wxurl   = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + accessToken;
            string    result  = Web.WebHelper.GetPage(wxurl, "", "GET");
            Hashtable resHash = JsonExtend <Hashtable> .ToObject(result);

            if (resHash["errcode"].GetInt() == 0)
            {
                retHash.Add("state", "success");
            }
            else
            {
                retHash.Add("state", "error");
                retHash.Add("errcode", resHash["errcode"]);
                retHash.Add("errmsg", resHash["errmsg"]);
            }
            return(retHash);
        }
예제 #2
0
        /// <summary>
        /// 自定义菜单查询
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public List <MenuButton> GetMenu(string accessToken)
        {
            string wxurl  = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + accessToken;
            string result = Web.WebHelper.GetPage(wxurl, "", "GET");

            object[]          firstBtnArr = (JsonExtend <Hashtable> .ToObject(result)["menu"] as Dictionary <string, object>)["button"] as object[];
            List <MenuButton> list        = new List <MenuButton>();

            foreach (Dictionary <string, object> firstItem in firstBtnArr)
            {
                MenuButton firstBtn = new MenuButton();
                firstBtn.Name = firstItem["name"].ToString();

                if (firstItem.ContainsKey("sub_button"))
                {
                    object[]          secondBtnArr  = firstItem["sub_button"] as object[];
                    List <MenuButton> secondBtnList = new List <MenuButton>();

                    foreach (Dictionary <string, object> secondItem in secondBtnArr)
                    {
                        MenuButton secondBtn = new MenuButton();

                        secondBtn.Name = secondItem["name"].ToString();
                        if (secondItem.ContainsKey("sub_button"))
                        {
                            object[]          thirdBtnArr  = secondItem["sub_button"] as object[];
                            List <MenuButton> thirdBtnList = new List <MenuButton>();
                            foreach (Dictionary <string, object> thirdItem in thirdBtnArr)
                            {
                                MenuButton thirdBtn = new MenuButton();
                                thirdBtn.Name       = thirdItem["name"].ToString();
                                thirdBtn.ButtonType = thirdItem["type"].ToString();
                                if (secondBtn.ButtonType == "view")
                                {
                                    secondBtn.Url = thirdItem["url"].ToString();
                                }
                                else
                                {
                                    secondBtn.Key = thirdItem["key"].ToString();
                                }
                            }
                            secondBtn.SubButtonList = thirdBtnList;
                        }
                        else
                        {
                            secondBtn.ButtonType = secondItem["type"].ToString();
                            if (secondBtn.ButtonType == "view")
                            {
                                secondBtn.Url = secondItem["url"].ToString();
                            }
                            else
                            {
                                secondBtn.Key = secondItem["key"].ToString();
                            }
                        }
                        secondBtnList.Add(secondBtn);
                    }
                    firstBtn.SubButtonList = secondBtnList;
                }
                else
                {
                    firstBtn.ButtonType = firstItem["type"].ToString();
                    if (firstBtn.ButtonType == "view")
                    {
                        firstBtn.Url = firstItem["url"].ToString();
                    }
                    else
                    {
                        firstBtn.Key = firstItem["key"].ToString();
                    }
                }

                list.Add(firstBtn);
            }

            return(list);
        }