Пример #1
0
 public string GetMenuJson()
 {
     Hishop.Weixin.MP.Domain.Menu.Menu menu = new Hishop.Weixin.MP.Domain.Menu.Menu();
     SingleClickButton item = new SingleClickButton {
         name = "热卖商品",
         key = "123"
     };
     SingleClickButton button2 = new SingleClickButton {
         name = "推荐商品",
         key = "SINGER"
     };
     SingleViewButton button3 = new SingleViewButton {
         name = "会员卡",
         url = "www.baidu.com"
     };
     SingleViewButton button4 = new SingleViewButton {
         name = "积分商城",
         url = "www.baidu.com"
     };
     SubMenu menu2 = new SubMenu {
         name = "个人中心"
     };
     menu2.sub_button.Add(button3);
     menu2.sub_button.Add(button4);
     menu.menu.button.Add(item);
     menu.menu.button.Add(button2);
     menu.menu.button.Add(menu2);
     return new JavaScriptSerializer().Serialize(menu.menu);
 }
Пример #2
0
        public string GetMenuJson()
        {
            Hishop.Weixin.MP.Domain.Menu.Menu menu = new Hishop.Weixin.MP.Domain.Menu.Menu();
            SingleClickButton item = new SingleClickButton {
                name = "热卖商品",
                key  = "123"
            };
            SingleClickButton button2 = new SingleClickButton {
                name = "推荐商品",
                key  = "SINGER"
            };
            SingleViewButton button3 = new SingleViewButton {
                name = "会员卡",
                url  = "www.baidu.com"
            };
            SingleViewButton button4 = new SingleViewButton {
                name = "积分商城",
                url  = "www.baidu.com"
            };
            SubMenu menu2 = new SubMenu {
                name = "个人中心"
            };

            menu2.sub_button.Add(button3);
            menu2.sub_button.Add(button4);
            menu.menu.button.Add(item);
            menu.menu.button.Add(button2);
            menu.menu.button.Add(menu2);
            return(new JavaScriptSerializer().Serialize(menu.menu));
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #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);
                }
            }
        }
Пример #6
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     IList<MenuInfo> initMenus = VShopHelper.GetInitMenus();
     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);
     }
 }
Пример #7
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();
                    }
                }
            }
        }