Esempio n. 1
0
        public string CreateMenu()
        {
            string token    = this.GetToken();
            string menuJson = this.GetMenuJson();

            return(MenuApi.CreateMenus(token, menuJson));
        }
Esempio n. 2
0
        /// <summary>
        /// 发布微信菜单到微信公众号服务器。
        /// </summary>
        /// <returns></returns>
        public PublishWxMenuResponse PublishMenus()
        {
            var resp = new PublishWxMenuResponse();
            IList <WxMenuDto> initMenus = this.GetInitMenus(MenuClient.Weixin);
            Menu menu = new Menu();

            foreach (var info in initMenus.OrderBy(p => p.Sequence))
            {
                if ((info.Chilren == null) || (info.Chilren.Count == 0))
                {
                    menu.menu.button.Add(this.BuildMenu(info));
                    continue;
                }
                SubMenu item = new SubMenu
                {
                    name = info.Name
                };
                foreach (var info2 in info.Chilren.OrderBy(x => x.Sequence))
                {
                    item.sub_button.Add(this.BuildMenu(info2));
                }
                menu.menu.button.Add(item);
            }
            string json           = JsonConvert.SerializeObject(menu.menu);
            var    masterSettings = GetOfficalAccount();

            if (string.IsNullOrEmpty(masterSettings.AppId) || string.IsNullOrEmpty(masterSettings.AppSecret))
            {
                resp.AddMessage("您的服务号配置存在问题,请您先检查配置!").SetSuccess(false);
            }
            else
            {
                string token = TokenApi.GetToken(masterSettings.AppId, masterSettings.AppSecret);
                try
                {
                    token = (JsonConvert.DeserializeObject(token, typeof(Token)) as Token).access_token;
                    if (MenuApi.CreateMenus(token, json).Contains("ok"))
                    {
                        resp.AddMessage("成功的把自定义菜单保存到了微信").SetSuccess(true);
                    }
                    else
                    {
                        resp.AddMessage("操作失败!服务号配置信息错误或没有微信自定义菜单权限,请检查配置信息以及菜单的长度。")
                        .SetSuccess(false);
                    }
                }
                catch (Exception exception)
                {
                    resp.AddMessage(exception.Message + "---" + token + "---" + masterSettings.AppId + "---" + masterSettings.AppSecret)
                    .SetSuccess(false).Error = exception;
                }
            }

            return(resp);
        }
Esempio n. 3
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            IList <MenuInfo> initMenus = VShopHelper.GetInitMenus(this.wid);

            Hishop.Weixin.MP.Domain.Menu.Menu menu = new Hishop.Weixin.MP.Domain.Menu.Menu();
            foreach (MenuInfo info in initMenus)
            {
                if ((info.Chilren == null) || (info.Chilren.Count == 0))
                {
                    menu.menu.button.Add(this.BuildMenu(info));
                }
                else
                {
                    SubMenu item = new SubMenu {
                        name = info.Name
                    };
                    foreach (MenuInfo info2 in info.Chilren)
                    {
                        item.sub_button.Add(this.BuildMenu(info2));
                    }
                    menu.menu.button.Add(item);
                }
            }
            bll     = new Chenduo.BLL.sf_website();
            website = bll.GetModelByWid(this.wid);
            if (website == null)
            {
                return;
            }

            string json = JsonConvert.SerializeObject(menu.menu);

            //SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
            //if (string.IsNullOrEmpty(masterSettings.WeixinAppId) || string.IsNullOrEmpty(masterSettings.WeixinAppSecret))
            //{
            //    base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='PayConfig.aspx'</script>");
            //}
            //else if (MenuApi.CreateMenus(JsonConvert.DeserializeObject<Token>(TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret)).access_token, json).Contains("\"ok\""))
            //{
            //    this.ShowMsg("成功的把自定义菜单保存到了微信", true);
            //}
            if (string.IsNullOrEmpty(website.appid) || string.IsNullOrEmpty(website.appsecret))
            {
                base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='PayConfig.aspx'</script>");
            }
            else if (MenuApi.CreateMenus(JsonConvert.DeserializeObject <Token>(TokenApi.GetToken(website.appid, website.appsecret)).access_token, json).Contains("\"ok\""))
            {
                this.ShowMsg("成功的把自定义菜单保存到了微信", true);
            }
            else
            {
                this.ShowMsg("操作失败!服务号配置信息错误或没有微信自定义菜单权限", false);
            }
        }
Esempio n. 4
0
        private void BtnSave_Click(object sender, System.EventArgs e)
        {
            System.Collections.Generic.IList <MenuInfo> initMenus = VShopHelper.GetInitMenus();
            Hishop.Weixin.MP.Domain.Menu.Menu           menu      = new Hishop.Weixin.MP.Domain.Menu.Menu();
            foreach (MenuInfo current in initMenus)
            {
                if (current.Chilren == null || current.Chilren.Count == 0)
                {
                    menu.menu.button.Add(this.BuildMenu(current));
                }
                else
                {
                    SubMenu subMenu = new SubMenu
                    {
                        name = current.Name
                    };
                    foreach (MenuInfo current2 in current.Chilren)
                    {
                        subMenu.sub_button.Add(this.BuildMenu(current2));
                    }
                    menu.menu.button.Add(subMenu);
                }
            }
            string       json           = JsonConvert.SerializeObject(menu.menu);
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);

            if (string.IsNullOrEmpty(masterSettings.WeixinAppId) || string.IsNullOrEmpty(masterSettings.WeixinAppSecret))
            {
                base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='wxconfig.aspx'</script>");
                return;
            }
            string text = TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret);

            text = JsonConvert.DeserializeObject <Token>(text).access_token;
            string text2 = MenuApi.CreateMenus(text, json);

            if (text2.Contains("\"ok\""))
            {
                this.ShowMsg("自定义菜单已同步到微信,24小时内生效!", true);
                return;
            }
            this.ShowMsg("操作失败!服务号配置信息错误或没有微信自定义菜单权限", false);
        }
Esempio n. 5
0
        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            System.Collections.Generic.IList <MenuInfo> initMenus = VShopHelper.GetInitMenus(ClientType.VShop);
            Hishop.Weixin.MP.Domain.Menu.Menu           menu      = new Hishop.Weixin.MP.Domain.Menu.Menu();
            foreach (MenuInfo info in initMenus)
            {
                if (info.Chilren == null || info.Chilren.Count == 0)
                {
                    menu.menu.button.Add(this.BuildMenu(info));
                }
                else
                {
                    SubMenu item = new SubMenu
                    {
                        name = info.Name
                    };
                    foreach (MenuInfo info2 in info.Chilren)
                    {
                        item.sub_button.Add(this.BuildMenu(info2));
                    }
                    menu.menu.button.Add(item);
                }
            }
            string       json           = JsonConvert.SerializeObject(menu.menu);
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);

            if (string.IsNullOrEmpty(masterSettings.WeixinAppId) || string.IsNullOrEmpty(masterSettings.WeixinAppSecret))
            {
                base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='AppConfig.aspx'</script>");
            }
            else
            {
                if (MenuApi.CreateMenus(JsonConvert.DeserializeObject <Token>(TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret)).access_token, json).Contains("ok"))
                {
                    this.ShowMsg("成功的把自定义菜单保存到了微信", true);
                }
                else
                {
                    this.ShowMsg("操作失败!服务号配置信息错误或没有微信自定义菜单权限", false);
                }
            }
        }
Esempio n. 6
0
        public void ConsistentToWeixin(long shopId)
        {
            string empty           = string.Empty;
            string weixinAppSecret = string.Empty;

            if (shopId == 0)
            {
                SiteSettingsInfo siteSettings = Instance <ISiteSettingService> .Create.GetSiteSettings();

                if (string.IsNullOrEmpty(siteSettings.WeixinAppId) || string.IsNullOrEmpty(siteSettings.WeixinAppSecret))
                {
                    throw new HimallException("您的服务号配置存在问题,请您先检查配置!");
                }
                empty           = siteSettings.WeixinAppId;
                weixinAppSecret = siteSettings.WeixinAppSecret;
            }
            if (shopId > 0)
            {
                WXShopInfo vShopSetting = Instance <IVShopService> .Create.GetVShopSetting(shopId);

                if (string.IsNullOrEmpty(vShopSetting.AppId) || string.IsNullOrEmpty(vShopSetting.AppSecret))
                {
                    throw new HimallException("您的服务号配置存在问题,请您先检查配置!");
                }
                empty           = vShopSetting.AppId;
                weixinAppSecret = vShopSetting.AppSecret;
            }
            string str = CommonApi.GetToken(empty, weixinAppSecret).access_token;
            IQueryable <MenuInfo> allMenu = GetAllMenu(shopId);

            if (allMenu == null)
            {
                throw new HimallException("你还没有添加菜单!");
            }
            List <MenuInfo> list = (
                from item in allMenu
                where item.ParentId == 0
                select item).ToList();

            foreach (MenuInfo menuInfo in list)
            {
                if (GetMenuByParentId(menuInfo.Id).Count() != 0)
                {
                    continue;
                }
                MenuInfo.UrlTypes?urlType = menuInfo.UrlType;
                if ((urlType.GetValueOrDefault() != MenuInfo.UrlTypes.Nothing ? true : !urlType.HasValue))
                {
                    continue;
                }
                throw new HimallException("你有一级菜单下没有二级菜单并且也没有绑定链接");
            }
            Menu menu = new Menu();

            foreach (MenuInfo menuInfo1 in list)
            {
                if (GetMenuByParentId(menuInfo1.Id).Count() != 0)
                {
                    SubMenu subMenu = new SubMenu()
                    {
                        name = menuInfo1.Title
                    };
                    foreach (MenuInfo menuByParentId in GetMenuByParentId(menuInfo1.Id))
                    {
                        subMenu.sub_button.Add(BuildMenu(menuByParentId));
                    }
                    menu.menu.button.Add(subMenu);
                }
                else
                {
                    menu.menu.button.Add(BuildMenu(menuInfo1));
                }
            }
            string str1 = JsonConvert.SerializeObject(menu.menu);
            string str2 = MenuApi.CreateMenus(str, str1);

            Log.Info(string.Concat("微信菜单:", str1));
            if (!str2.Contains("ok"))
            {
                Log.Info(string.Concat("微信菜单同步错误,返回内容:", str2));
                throw new HimallException("服务号配置信息错误或没有微信自定义菜单权限,请检查配置信息以及菜单的长度。");
            }
        }
Esempio n. 7
0
        public string CreateMenu()
        {
            string token = GetToken();

            return(MenuApi.CreateMenus(token, GetMenuJson()));
        }
Esempio n. 8
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            SiteSettings masterSettings = SettingsManager.GetMasterSettings();

            if (masterSettings.IsDemoSite)
            {
                this.ShowMsg("演示站点不允许修改微信自定义菜单", false);
            }
            else
            {
                IList <MenuInfo> initMenus             = VShopHelper.GetInitMenus(ClientType.VShop);
                Hishop.Weixin.MP.Domain.Menu.Menu menu = new Hishop.Weixin.MP.Domain.Menu.Menu();
                foreach (MenuInfo item in initMenus)
                {
                    if (item.Chilren == null || item.Chilren.Count == 0)
                    {
                        menu.menu.button.Add(this.BuildMenu(item));
                    }
                    else
                    {
                        SubMenu subMenu = new SubMenu
                        {
                            name = item.Name
                        };
                        foreach (MenuInfo item2 in item.Chilren)
                        {
                            subMenu.sub_button.Add(this.BuildMenu(item2));
                        }
                        menu.menu.button.Add(subMenu);
                    }
                }
                string json = JsonConvert.SerializeObject(menu.menu);
                if (string.IsNullOrEmpty(masterSettings.WeixinAppId) || string.IsNullOrEmpty(masterSettings.WeixinAppSecret))
                {
                    base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='VServerConfig.aspx'</script>");
                }
                else
                {
                    string text = AccessTokenContainer.TryGetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, false);
                    string sign = text;
                    try
                    {
                        if (string.IsNullOrEmpty(text))
                        {
                            this.ShowMsg("操作失败!您的服务号配置可能存在问题,请您先检查配置!", false);
                        }
                        else
                        {
                            string text2 = MenuApi.CreateMenus(text, json);
                            if (text2.Contains("\"errmsg\":\"ok\""))
                            {
                                this.ShowMsg("成功的把自定义菜单保存到了微信", true);
                            }
                            else
                            {
                                Globals.AppendLog(text2, sign, "", "SaveMenu");
                                this.ShowMsg("操作失败!服务号配置信息错误或没有微信自定义菜单权限,请检查配置信息以及菜单的长度。", false);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        base.Response.Write(ex.Message + "---" + text + "---" + masterSettings.WeixinAppId + "---" + masterSettings.WeixinAppSecret);
                        base.Response.End();
                    }
                }
            }
        }
Esempio n. 9
0
        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            System.Collections.Generic.IList <MenuInfo> initMenus = VShopHelper.GetInitMenus(ClientType.VShop);
            Ecdev.Weixin.MP.Domain.Menu.Menu            menu      = new Ecdev.Weixin.MP.Domain.Menu.Menu();
            foreach (MenuInfo current in initMenus)
            {
                if (current.Chilren == null || current.Chilren.Count == 0)
                {
                    menu.menu.button.Add(this.BuildMenu(current));
                }
                else
                {
                    SubMenu subMenu = new SubMenu
                    {
                        name = current.Name
                    };
                    foreach (MenuInfo current2 in current.Chilren)
                    {
                        subMenu.sub_button.Add(this.BuildMenu(current2));
                    }
                    menu.menu.button.Add(subMenu);
                }
            }
            string       json           = JsonConvert.SerializeObject(menu.menu);
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);

            if (string.IsNullOrEmpty(masterSettings.WeixinAppId) || string.IsNullOrEmpty(masterSettings.WeixinAppSecret))
            {
                base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='VServerConfig.aspx'</script>");
                return;
            }
            string text = TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret);

            try
            {
                text = (JsonConvert.DeserializeObject(text, typeof(Token)) as Token).access_token;
                string text2 = MenuApi.CreateMenus(text, json);
                if (text2.Contains("ok"))
                {
                    this.ShowMsg("成功的把自定义菜单保存到了微信", true);
                }
                else
                {
                    this.ShowMsg("操作失败!服务号配置信息错误或没有微信自定义菜单权限,请检查配置信息以及菜单的长度。", false);
                }
            }
            catch (System.Exception ex)
            {
                base.Response.Write(string.Concat(new string[]
                {
                    ex.Message,
                    "---",
                    text,
                    "---",
                    masterSettings.WeixinAppId,
                    "---",
                    masterSettings.WeixinAppSecret
                }));
                base.Response.End();
            }
        }