Пример #1
0
        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);

            if (string.IsNullOrEmpty(masterSettings.AliOHAppId))
            {
                base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='AliOHServerConfig.aspx'</script>");
                return;
            }
            System.Collections.Generic.IList <MenuInfo> initMenus = VShopHelper.GetInitMenus(ClientType.AliOH);
            System.Collections.Generic.List <Ecdev.Alipay.OpenHome.Model.Button> list = new System.Collections.Generic.List <Ecdev.Alipay.OpenHome.Model.Button>();
            foreach (MenuInfo current in initMenus)
            {
                if (current.Chilren == null || current.Chilren.Count == 0)
                {
                    list.Add(new Ecdev.Alipay.OpenHome.Model.Button
                    {
                        name        = current.Name,
                        actionParam = string.IsNullOrEmpty(current.Url) ? "http://javasript:;" : current.Url,
                        actionType  = current.Type
                    });
                }
                else
                {
                    Ecdev.Alipay.OpenHome.Model.Button button = new Ecdev.Alipay.OpenHome.Model.Button
                    {
                        name = current.Name
                    };
                    System.Collections.Generic.List <Ecdev.Alipay.OpenHome.Model.Button> list2 = new System.Collections.Generic.List <Ecdev.Alipay.OpenHome.Model.Button>();
                    foreach (MenuInfo current2 in current.Chilren)
                    {
                        list2.Add(new Ecdev.Alipay.OpenHome.Model.Button
                        {
                            name        = current2.Name,
                            actionParam = string.IsNullOrEmpty(current2.Url) ? "http://javasript:;" : current2.Url,
                            actionType  = current2.Type
                        });
                    }
                    button.subButton = list2;
                    list.Add(button);
                }
            }
            Ecdev.Alipay.OpenHome.Model.Menu menu = new Ecdev.Alipay.OpenHome.Model.Menu
            {
                button = list
            };
            AlipayOHClient alipayOHClient = AliOHClientHelper.Instance(base.Server.MapPath("~/"));
            bool           flag           = false;

            try
            {
                AddMenuRequest request = new AddMenuRequest(menu);
                alipayOHClient.Execute <MenuAddResponse>(request);
                this.ShowMsg("保存到服务窗成功!", true);
                flag = true;
            }
            catch (AliResponseException)
            {
            }
            catch (System.Exception ex)
            {
                this.ShowMsg("保存到服务窗失败,失败原因:" + ex.Message, false);
                flag = true;
            }
            if (!flag)
            {
                try
                {
                    UpdateMenuRequest request2 = new UpdateMenuRequest(menu);
                    alipayOHClient.Execute <MenuUpdateResponse>(request2);
                    this.ShowMsg("保存到服务窗成功!", true);
                }
                catch (System.Exception ex2)
                {
                    this.ShowMsg("保存到服务窗失败,失败原因:" + ex2.Message, false);
                }
            }
        }
Пример #2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            SiteSettings masterSettings = SettingsManager.GetMasterSettings();

            if (string.IsNullOrEmpty(masterSettings.AliOHAppId))
            {
                base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='AliOHServerConfig.aspx'</script>");
            }
            else
            {
                IList <MenuInfo> initMenus = VShopHelper.GetInitMenus(ClientType.AliOH);
                List <Hishop.Alipay.OpenHome.Model.Button> list = new List <Hishop.Alipay.OpenHome.Model.Button>();
                foreach (MenuInfo item in initMenus)
                {
                    if (item.Chilren == null || item.Chilren.Count == 0)
                    {
                        list.Add(new Hishop.Alipay.OpenHome.Model.Button
                        {
                            name        = item.Name,
                            actionParam = (string.IsNullOrEmpty(item.Url) ? "http://javasript:;" : item.Url),
                            actionType  = item.Type
                        });
                    }
                    else
                    {
                        Hishop.Alipay.OpenHome.Model.Button button = new Hishop.Alipay.OpenHome.Model.Button
                        {
                            name = item.Name
                        };
                        List <Hishop.Alipay.OpenHome.Model.Button> list2 = new List <Hishop.Alipay.OpenHome.Model.Button>();
                        foreach (MenuInfo item2 in item.Chilren)
                        {
                            list2.Add(new Hishop.Alipay.OpenHome.Model.Button
                            {
                                name        = item2.Name,
                                actionParam = (string.IsNullOrEmpty(item2.Url) ? "http://javasript:;" : item2.Url),
                                actionType  = item2.Type
                            });
                        }
                        button.subButton = list2;
                        list.Add(button);
                    }
                }
                Hishop.Alipay.OpenHome.Model.Menu menu = new Hishop.Alipay.OpenHome.Model.Menu
                {
                    button = list
                };
                AlipayOHClient alipayOHClient = AliOHClientHelper.Instance(base.Server.MapPath("~/"));
                bool           flag           = false;
                try
                {
                    AddMenuRequest  request         = new AddMenuRequest(menu);
                    MenuAddResponse menuAddResponse = alipayOHClient.Execute <MenuAddResponse>(request);
                    this.ShowMsg("保存到生活号(原支付宝服务窗)成功!", true);
                    flag = true;
                }
                catch (AliResponseException ex)
                {
                    Globals.WriteExceptionLog_Page(ex, this.pageparam, "AliohMenuSave");
                }
                catch (Exception ex2)
                {
                    this.ShowMsg("保存到生活号失败,失败原因:" + ex2.Message, false);
                    flag = true;
                    Globals.WriteExceptionLog_Page(ex2, this.pageparam, "AliohMenuSave");
                }
                if (!flag)
                {
                    try
                    {
                        UpdateMenuRequest  request2           = new UpdateMenuRequest(menu);
                        MenuUpdateResponse menuUpdateResponse = alipayOHClient.Execute <MenuUpdateResponse>(request2);
                        this.ShowMsg("保存到生活号成功!", true);
                    }
                    catch (Exception ex3)
                    {
                        this.ShowMsg("保存到生活号失败,失败原因:" + ex3.Message, false);
                        Globals.WriteExceptionLog_Page(ex3, this.pageparam, "AliohMenuSave");
                    }
                }
            }
        }
Пример #3
0
 private void btnSubmit_Click(object sender, System.EventArgs e)
 {
     if (string.IsNullOrEmpty(SettingsManager.GetMasterSettings(false).AliOHAppId))
     {
         base.Response.Write("<script>alert('您的服务号配置存在问题,请您先检查配置!');location.href='AliOHServerConfig.aspx'</script>");
     }
     else
     {
         IList <MenuInfo> initMenus = VShopHelper.GetInitMenus(ClientType.AliOH);
         List <Hishop.Alipay.OpenHome.Model.Button> list2 = new List <Hishop.Alipay.OpenHome.Model.Button>();
         foreach (MenuInfo info in initMenus)
         {
             if ((info.Chilren == null) || (info.Chilren.Count == 0))
             {
                 Hishop.Alipay.OpenHome.Model.Button item = new Hishop.Alipay.OpenHome.Model.Button
                 {
                     name        = info.Name,
                     actionParam = string.IsNullOrEmpty(info.Url) ? "http://javasript:;" : info.Url,
                     actionType  = info.Type
                 };
                 list2.Add(item);
             }
             else
             {
                 Hishop.Alipay.OpenHome.Model.Button button2 = new Hishop.Alipay.OpenHome.Model.Button
                 {
                     name = info.Name
                 };
                 List <Hishop.Alipay.OpenHome.Model.Button> list3 = new List <Hishop.Alipay.OpenHome.Model.Button>();
                 foreach (MenuInfo info2 in info.Chilren)
                 {
                     Hishop.Alipay.OpenHome.Model.Button button3 = new Hishop.Alipay.OpenHome.Model.Button
                     {
                         name        = info2.Name,
                         actionParam = string.IsNullOrEmpty(info2.Url) ? "http://javasript:;" : info2.Url,
                         actionType  = info2.Type
                     };
                     list3.Add(button3);
                 }
                 button2.subButton = list3;
                 list2.Add(button2);
             }
         }
         Hishop.Alipay.OpenHome.Model.Menu menu = new Hishop.Alipay.OpenHome.Model.Menu
         {
             button = list2
         };
         AlipayOHClient client = AliOHClientHelper.Instance(base.Server.MapPath("~/"));
         bool           flag   = false;
         try
         {
             AddMenuRequest request = new AddMenuRequest(menu);
             client.Execute <MenuAddResponse>(request);
             this.ShowMsg("保存到服务窗成功!", true);
             flag = true;
         }
         catch (AliResponseException)
         {
         }
         catch (Exception exception)
         {
             this.ShowMsg("保存到服务窗失败,失败原因:" + exception.Message, false);
             flag = true;
         }
         if (!flag)
         {
             try
             {
                 UpdateMenuRequest request2 = new UpdateMenuRequest(menu);
                 client.Execute <MenuUpdateResponse>(request2);
                 this.ShowMsg("保存到服务窗成功!", true);
             }
             catch (Exception exception2)
             {
                 this.ShowMsg("保存到服务窗失败,失败原因:" + exception2.Message, false);
             }
         }
     }
 }