Ejemplo n.º 1
0
        public void GetPoiCategory()
        {
            var accessToken = AccessTokenContainer.GetToken(_appId);

            var result = PoiApi.GetCategory(accessToken);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.errcode, ReturnCode.请求成功);
        }
Ejemplo n.º 2
0
        public List <WXCategory> GetCategory()
        {
            PoiCategory category = PoiApi.GetCategory(_accessToken, 10000);

            if (category.errcode != ReturnCode.请求成功)
            {
                throw new Exception(category.errmsg);
            }
            List <WXCategory> wXCategories = new List <WXCategory>();

            foreach (string categoryList in category.category_list)
            {
                string[] strArrays = categoryList.Split(new char[] { ',' });
                if (strArrays.Count() == 1)
                {
                    WXCategory wXCategory = new WXCategory()
                    {
                        Id   = Guid.NewGuid().ToString(),
                        Name = strArrays[0]
                    };
                    wXCategories.Add(wXCategory);
                }
                else if (!wXCategories.Exists((WXCategory p) => p.Name == strArrays[0]))
                {
                    WXCategory wXCategory1 = new WXCategory()
                    {
                        Id   = Guid.NewGuid().ToString(),
                        Name = strArrays[0]
                    };
                    WXCategory wXCategory2 = new WXCategory()
                    {
                        Id   = wXCategory1.Id,
                        Name = strArrays[1]
                    };
                    wXCategory1.Child.Add(wXCategory2);
                    wXCategories.Add(wXCategory1);
                }
                else
                {
                    WXCategory wXCategory3 = wXCategories.FirstOrDefault((WXCategory p) => p.Name == strArrays[0]);
                    if (wXCategory3.Child.Exists((WXCategory p) => p.Name == strArrays[1]))
                    {
                        continue;
                    }
                    WXCategory wXCategory4 = new WXCategory()
                    {
                        Id   = wXCategory3.Id,
                        Name = strArrays[1]
                    };
                    wXCategory3.Child.Add(wXCategory4);
                }
            }
            return(wXCategories);
        }
Ejemplo n.º 3
0
        public List <WXCategory> GetCategory()
        {
            var result = PoiApi.GetCategory(this._accessToken);

            if (result.errcode != 0)
            {
                Log.Debug("[WXPoi]" + result.errcode + ":" + result.errmsg);
                throw new Exception(result.errmsg);
            }

            List <WXCategory> c = new List <WXCategory>();

            foreach (string str in result.category_list)
            {
                string[] cateArr = str.Split(',');
                if (cateArr.Count() == 1)
                {
                    c.Add(new WXCategory
                    {
                        Id   = Guid.NewGuid().ToString(),
                        Name = cateArr[0]
                    });
                }
                else if (c.Exists(p => p.Name == cateArr[0]))
                {
                    var parent = c.FirstOrDefault(p => p.Name == cateArr[0]);
                    if (!parent.Child.Exists(p => p.Name == cateArr[1]))
                    {
                        WXCategory child = new WXCategory();
                        child.Id   = parent.Id;
                        child.Name = cateArr[1];
                        parent.Child.Add(child);
                    }
                }
                else
                {
                    WXCategory item = new WXCategory();
                    item.Id   = Guid.NewGuid().ToString();
                    item.Name = cateArr[0];

                    WXCategory child = new WXCategory();
                    child.Id   = item.Id;
                    child.Name = cateArr[1];
                    item.Child.Add(child);
                    c.Add(item);
                }
            }
            return(c);
        }
Ejemplo n.º 4
0
        public static IEnumerable <WXCategory> GetCategory()
        {
            IList <WXCategory> list     = new List <WXCategory>();
            GetCategoryResult  category = PoiApi.GetCategory(WXStoreHelper.siteSettings.WeixinAppId);

            foreach (string item2 in category.category_list)
            {
                string[]   array = item2.Split(',');
                WXCategory item  = new WXCategory
                {
                    FirstCategoryName  = ((array.Count() > 0) ? array[0] : string.Empty),
                    SecondCategoryName = ((array.Count() > 1) ? array[1] : string.Empty),
                    ThridCategoryName  = ((array.Count() > 2) ? array[2] : string.Empty)
                };
                list.Add(item);
            }
            return(list);
        }