Beispiel #1
0
        public void Page_Load(object sender, System.EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            if (!IsPostBack)
            {
                BreadCrumb(AppManager.WeiXin.LeftMenu.IdAccounts, AppManager.WeiXin.LeftMenu.Function.IdInfo, string.Empty, AppManager.WeiXin.Permission.WebSite.Info);
                LtlWelcome.Text = "欢迎使用 SiteServer CMS 微信站点";

                var bindingUrl = PageAccountBinding.GetRedirectUrl(PublishmentSystemId, GetRedirectUrl(PublishmentSystemId));

                var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemId);

                var isBinding = WeiXinManager.IsBinding(accountInfo);
                if (isBinding)
                {
                    LtlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-success"">已绑定微信</a>";
                }
                else
                {
                    LtlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-danger"">未绑定微信</a>";
                }

                LtlUrl.Text = PageUtilityWX.API.GetMPUrl(PublishmentSystemId);

                LtlToken.Text = accountInfo.Token;

                var deleteUrl = PagePublishmentSystemDelete.GetRedirectUrl(PublishmentSystemId);
                LtlDelete.Text = $@"<a href=""{deleteUrl}"" class=""btn btn-danger"">删除当前站点</a>";
            }
        }
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("PublishmentSystemID");
            returnUrl = StringUtils.ValueFromUrl(GetQueryString("returnUrl"));

            if (!IsPostBack)
            {
                //base.BreadCrumbConsole(AppManager.CMS.LeftMenu.ID_Site, "绑定微信公众帐号", AppManager.Permission.Platform_Site);


                #region 确认绑定接口没有问题
                if (!IsNet45OrNewer())
                {
                    FailMessage("请检查是否安装了.NET Framework 4.5以上版本");
                    return;
                }

                var hostUrl = PageUtils.GetHost();
                if (hostUrl.IndexOf(":") >= 0)
                {
                    var port = hostUrl.Split(new char[] { ':' })[1];
                    if (port != "80")
                    {
                        FailMessage("请检查站点是否设置为80端口");
                        return;
                    }
                }

                var testUrl = PageUtils.AddProtocolToUrl("/api/mp/url?id=1");
                var result  = string.Empty;
                WebClientUtils.Post(testUrl, string.Empty, out result);
                if (!StringUtils.EqualsIgnoreCase(result, "failed:id=1") && !StringUtils.EqualsIgnoreCase(result, "参数错误"))
                {
                    FailMessage("绑定微信公众账号需要的api有问题! 详细错误信息:" + result);
                    return;
                }


                #endregion

                var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);

                EWXAccountTypeUtils.AddListItems(rblWXAccountType);
                ControlUtils.SelectListItems(rblWXAccountType, EWXAccountTypeUtils.GetValue(EWXAccountTypeUtils.GetEnumType(accountInfo.AccountType)));

                tbWhchatID.Text = accountInfo.WeChatID;

                ltlURL.Text = PageUtilityWX.API.GetMPUrl(PublishmentSystemID);

                ltlToken.Text = accountInfo.Token;

                tbAppID.Text     = accountInfo.AppID;
                tbAppSecret.Text = accountInfo.AppSecret;
            }
        }
Beispiel #3
0
        public void Delete_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                try
                {
                    var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);

                    var accessToken = MPUtils.GetAccessToken(accountInfo);

                    var result = CommonApi.DeleteMenu(accessToken);

                    if (result.errmsg == "ok")
                    {
                        SuccessMessage("菜单禁用成功,取消关注公众账号后再次关注,可以立即看到禁用后的效果");
                    }
                    else
                    {
                        FailMessage($"菜单禁用失败:{result.errmsg}");
                    }
                }
                catch (Exception ex)
                {
                    FailMessage($"菜单禁用失败:{ex.Message}");
                }
            }
        }
Beispiel #4
0
        void dgContents_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var publishmentSystemID   = (int)e.Item.DataItem;
                var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemID);
                if (publishmentSystemInfo != null)
                {
                    var ltlPublishmentSystemName = e.Item.FindControl("ltlPublishmentSystemName") as Literal;
                    var ltlPublishmentSystemType = e.Item.FindControl("ltlPublishmentSystemType") as Literal;
                    var ltlPublishmentSystemDir  = e.Item.FindControl("ltlPublishmentSystemDir") as Literal;
                    var ltlAddDate = e.Item.FindControl("ltlAddDate") as Literal;
                    var ltlManage  = e.Item.FindControl("ltlManage") as Literal;
                    var ltlBinding = e.Item.FindControl("ltlBinding") as Literal;
                    var ltlDelete  = e.Item.FindControl("ltlDelete") as Literal;

                    ltlPublishmentSystemName.Text = publishmentSystemInfo.PublishmentSystemName;

                    ltlPublishmentSystemType.Text = EPublishmentSystemTypeUtils.GetHtml(publishmentSystemInfo.PublishmentSystemType);
                    ltlPublishmentSystemDir.Text  = publishmentSystemInfo.PublishmentSystemDir;
                    ltlAddDate.Text = DateUtils.GetDateString(NodeManager.GetAddDate(publishmentSystemID, publishmentSystemID));

                    var manageUrl = PageUtils.GetLoadingUrl(PageUtils.GetAdminDirectoryUrl(
                                                                $"main.aspx?publishmentSystemID={publishmentSystemID}"));
                    ltlManage.Text = $@"<a href=""{manageUrl}"" target=""top"">管理</a>";

                    var bindingUrl = ConsoleAccountBinding.GetRedirectUrl(publishmentSystemID, PageUtils.GetWXUrl("console_account.aspx"));

                    var accountInfo = WeiXinManager.GetAccountInfo(publishmentSystemID);

                    var isBinding = WeiXinManager.IsBinding(accountInfo);
                    if (isBinding)
                    {
                        ltlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-success"">已绑定微信</a>";
                    }
                    else
                    {
                        ltlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-danger"">未绑定微信</a>";
                    }

                    var urlDelete = PageUtils.GetSTLUrl(
                        $"console_publishmentSystemDelete.aspx?NodeID={publishmentSystemID}");
                    ltlDelete.Text = $@"<a href=""{urlDelete}"">删除</a>";
                }
            }
        }
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                try
                {
                    var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemId);

                    accountInfo.IsWelcome      = CbIsWelcome.Checked;
                    accountInfo.WelcomeKeyword = TbWelcomeKeyword.Text;
                    if (string.IsNullOrEmpty(TbWelcomeKeyword.Text))
                    {
                        accountInfo.IsWelcome = false;
                    }
                    accountInfo.IsDefaultReply      = CbIsDefaultReply.Checked;
                    accountInfo.DefaultReplyKeyword = TbDefaultReplyKeyword.Text;
                    if (string.IsNullOrEmpty(TbDefaultReplyKeyword.Text))
                    {
                        accountInfo.IsDefaultReply = false;
                    }

                    if (!string.IsNullOrEmpty(accountInfo.WelcomeKeyword) && !DataProviderWx.KeywordMatchDao.IsExists(PublishmentSystemId, accountInfo.WelcomeKeyword))
                    {
                        FailMessage($"保存失败,关键词“{accountInfo.WelcomeKeyword}”不存在,请先在关键词回复中添加");
                        return;
                    }
                    if (!string.IsNullOrEmpty(accountInfo.DefaultReplyKeyword) && !DataProviderWx.KeywordMatchDao.IsExists(PublishmentSystemId, accountInfo.DefaultReplyKeyword))
                    {
                        FailMessage($"保存失败,关键词“{accountInfo.DefaultReplyKeyword}”不存在,请先在关键词回复中添加");
                        return;
                    }

                    DataProviderWx.AccountDao.Update(accountInfo);

                    Body.AddSiteLog(PublishmentSystemId, "修改智能回复设置");
                    SuccessMessage("智能回复设置配置成功!");
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "智能回复设置配置失败!");
                }
            }
        }
Beispiel #6
0
        void dgContents_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var publishmentSystemId   = (int)e.Item.DataItem;
                var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemId);
                if (publishmentSystemInfo != null)
                {
                    var ltlPublishmentSystemName = e.Item.FindControl("ltlPublishmentSystemName") as Literal;
                    var ltlPublishmentSystemDir  = e.Item.FindControl("ltlPublishmentSystemDir") as Literal;
                    var ltlAddDate = e.Item.FindControl("ltlAddDate") as Literal;
                    var ltlManage  = e.Item.FindControl("ltlManage") as Literal;
                    var ltlBinding = e.Item.FindControl("ltlBinding") as Literal;
                    var ltlDelete  = e.Item.FindControl("ltlDelete") as Literal;

                    ltlPublishmentSystemName.Text = publishmentSystemInfo.PublishmentSystemName;

                    ltlPublishmentSystemDir.Text = publishmentSystemInfo.PublishmentSystemDir;
                    ltlAddDate.Text = DateUtils.GetDateString(NodeManager.GetAddDate(publishmentSystemId, publishmentSystemId));

                    var manageUrl = PageMain.GetRedirectUrl(publishmentSystemId, string.Empty);
                    ltlManage.Text = $@"<a href=""{manageUrl}"" target=""top"">管理</a>";

                    var bindingUrl = PageAccountBinding.GetRedirectUrl(publishmentSystemId, GetRedirectUrl());

                    var accountInfo = WeiXinManager.GetAccountInfo(publishmentSystemId);

                    var isBinding = WeiXinManager.IsBinding(accountInfo);
                    if (isBinding)
                    {
                        ltlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-success"">已绑定微信</a>";
                    }
                    else
                    {
                        ltlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-danger"">未绑定微信</a>";
                    }

                    var urlDelete = PagePublishmentSystemDelete.GetRedirectUrl(publishmentSystemId);
                    ltlDelete.Text = $@"<a href=""{urlDelete}"">删除</a>";
                }
            }
        }
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("PublishmentSystemId");

            if (!IsPostBack)
            {
                BreadCrumb(AppManager.WeiXin.LeftMenu.IdAccounts, AppManager.WeiXin.LeftMenu.Function.IdSetReply, string.Empty, AppManager.WeiXin.Permission.WebSite.SetReply);

                var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemId);

                CbIsWelcome.Checked   = accountInfo.IsWelcome;
                TbWelcomeKeyword.Text = accountInfo.WelcomeKeyword;
                BtnWelcomeKeywordSelect.Attributes.Add("onclick", ModalKeywordSelect.GetOpenWindowString(PublishmentSystemId, "selectWelcomeKeyword"));

                CbIsDefaultReply.Checked   = accountInfo.IsDefaultReply;
                TbDefaultReplyKeyword.Text = accountInfo.DefaultReplyKeyword;
                BtnDefaultReplyKeywordSelect.Attributes.Add("onclick", ModalKeywordSelect.GetOpenWindowString(PublishmentSystemId, "selectDefaultReplyKeyword"));
            }
        }
Beispiel #8
0
        public void Page_Load(object sender, System.EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            if (!IsPostBack)
            {
                BreadCrumb(AppManager.WeiXin.LeftMenu.ID_Accounts, AppManager.WeiXin.LeftMenu.Function.ID_Info, string.Empty, AppManager.WeiXin.Permission.WebSite.Info);
                ltlWelcome.Text = "欢迎使用 SiteServer WeiXin 微信平台";

                var bindingUrl = ConsoleAccountBinding.GetRedirectUrl(PublishmentSystemID, PageUtils.GetWXUrl(
                                                                          $"background_right.aspx?publishmentSystemID={PublishmentSystemID}"));

                var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);

                var isBinding = WeiXinManager.IsBinding(accountInfo);
                if (isBinding)
                {
                    ltlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-success"">已绑定微信</a>";
                }
                else
                {
                    ltlBinding.Text = $@"<a href=""{bindingUrl}"" class=""btn btn-danger"">未绑定微信</a>";
                }

                ltlURL.Text = PageUtilityWX.API.GetMPUrl(PublishmentSystemID);

                ltlToken.Text = accountInfo.Token;

                var deleteUrl = PageUtils.GetSTLUrl(
                    $"console_publishmentSystemDelete.aspx?nodeID={PublishmentSystemID}&isBackgroundDelete=true");
                ltlDelete.Text = $@"<a href=""{deleteUrl}"" class=""btn btn-danger"">删除当前站点</a>";
            }
        }
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                if (phStep1.Visible)
                {
                    phStep2.Visible = true;
                    phStep3.Visible = phStep1.Visible = false;
                }
                else if (phStep2.Visible)
                {
                    var accountType = EWXAccountTypeUtils.GetEnumType(rblWXAccountType.SelectedValue);
                    if (accountType == EWXAccountType.Subscribe)
                    {
                        var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);

                        accountInfo.AccountType = rblWXAccountType.SelectedValue;
                        accountInfo.WeChatID    = tbWhchatID.Text;

                        try
                        {
                            DataProviderWX.AccountDAO.Update(accountInfo);

                            LogUtils.AddLog(BaiRongDataProvider.AdministratorDao.UserName, "绑定微信公众帐号",
                                            $"站点:{PublishmentSystemInfo.PublishmentSystemName}");

                            SuccessMessage("绑定微信公众帐号成功!");
                            AddWaitAndRedirectScript(returnUrl);
                        }
                        catch (Exception ex)
                        {
                            FailMessage(ex, "绑定微信公众帐号失败!");
                        }
                    }
                    else
                    {
                        phStep3.Visible = true;
                        phStep1.Visible = phStep2.Visible = false;
                    }
                }
                else
                {
                    var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);

                    accountInfo.AccountType = rblWXAccountType.SelectedValue;
                    accountInfo.WeChatID    = tbWhchatID.Text;
                    accountInfo.AppID       = tbAppID.Text;
                    accountInfo.AppSecret   = tbAppSecret.Text;

                    try
                    {
                        DataProviderWX.AccountDAO.Update(accountInfo);

                        LogUtils.AddLog(BaiRongDataProvider.AdministratorDao.UserName, "绑定微信公众帐号",
                                        $"站点:{PublishmentSystemInfo.PublishmentSystemName}");

                        SuccessMessage("绑定微信公众帐号成功!");
                        AddWaitAndRedirectScript(returnUrl);
                    }
                    catch (Exception ex)
                    {
                        FailMessage(ex, "绑定微信公众帐号失败!");
                    }
                }
            }
        }
Beispiel #10
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            menuID   = TranslateUtils.ToInt(GetQueryString("menuID"));
            parentID = TranslateUtils.ToInt(GetQueryString("parentID"));

            if (Request.QueryString["Delete"] != null && menuID > 0)
            {
                DataProviderWX.MenuDAO.Delete(menuID);
                SuccessMessage("菜单删除成功!");
            }
            if (Request.QueryString["Subtract"] != null && menuID > 0)
            {
                DataProviderWX.MenuDAO.UpdateTaxisToUp(parentID, menuID);
                SuccessMessage("菜单排序成功!");
            }
            if (!IsPostBack)
            {
                BreadCrumb(AppManager.WeiXin.LeftMenu.ID_Accounts, AppManager.WeiXin.LeftMenu.Function.ID_Menu, string.Empty, AppManager.WeiXin.Permission.WebSite.Menu);
                var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);
                if (EWXAccountTypeUtils.Equals(accountInfo.AccountType, EWXAccountType.Subscribe))
                {
                    PageUtils.RedirectToErrorPage(@"您的微信公众账号类型为订阅号(非认证),微信目前不支持订阅号自定义菜单。如果您的公众账号类型不是订阅号,请到账户信息中设置微信绑定账号。");
                    return;
                }

                ltlIFrame.Text = @"<iframe frameborder=""0"" id=""menu"" name=""menu"" width=""100%"" height=""500""></iframe>";

                var menuInfoList = DataProviderWX.MenuDAO.GetMenuInfoList(PublishmentSystemID, 0);

                var builder = new StringBuilder();

                foreach (var menuInfo in menuInfoList)
                {
                    var subMenuInfoList = DataProviderWX.MenuDAO.GetMenuInfoList(PublishmentSystemID, menuInfo.MenuID);

                    var subBuilder = new StringBuilder();

                    if (subMenuInfoList.Count < 5)
                    {
                        var addSubUrl = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, menuInfo.MenuID, 0);
                        subBuilder.AppendFormat(@"
                            <dd class=""add"">
                              <a href=""{0}"" target=""menu""><font>新增菜单</font></a>
                            </dd>", addSubUrl);
                    }

                    var i = 0;
                    foreach (var subMenuInfo in subMenuInfoList)
                    {
                        i++;

                        var ddClass        = i == subMenuInfoList.Count ? "last" : string.Empty;
                        var editSubUrl     = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, subMenuInfo.ParentID, subMenuInfo.MenuID);
                        var deleteSubUrl   = GetDeleteRedirectUrl(PublishmentSystemID, subMenuInfo.ParentID, subMenuInfo.MenuID);
                        var subtractSubUrl = GetSubtractRedirectUrl(PublishmentSystemID, subMenuInfo.ParentID, subMenuInfo.MenuID);


                        subBuilder.AppendFormat(@"                                                                   
                            <dd class=""{0}"">
                              <a href=""{1}"" target=""menu""><font>{2}</font></a>
                              <a href=""{3}"" onclick=""javascript:return confirm('此操作将删除子菜单“{2}”,确认吗?');"" class=""delete""><img src=""images/iphone-btn-delete.png""></a>
                              <a href=""{4}"" style='top:20px;' class=""delete""><img src=""images/iphone-btn-up.png""></a>
                            </dd>", ddClass, editSubUrl, subMenuInfo.MenuName, deleteSubUrl, subtractSubUrl);
                    }

                    var editUrl      = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, menuInfo.ParentID, menuInfo.MenuID);
                    var subMenuStyle = parentID == menuInfo.MenuID ? string.Empty : "display:none";
                    var deleteUrl    = GetDeleteRedirectUrl(PublishmentSystemID, menuInfo.ParentID, menuInfo.MenuID);
                    builder.AppendFormat(@"
                    <li class=""secondMenu"">
                        <a href=""{0}"" class=""mainMenu"" target=""menu""><font>{1}</font></a>
                        <dl class=""subMenus"" style=""{2}"">
                            <span>
                                <img width=""9"" height=""6"" src=""images/iphone-btn-tri.png"">
                            </span>
                            {3}
                        </dl>
                        <a href=""{4}"" onclick=""javascript:return confirm('此操作将删除主菜单“{1}”,确认吗?');"" class=""delete""><img src=""images/iphone-btn-delete.png""></a>
                    </li>", editUrl, menuInfo.MenuName, subMenuStyle, subBuilder.ToString(), deleteUrl);
                }

                if (menuInfoList.Count < 3)
                {
                    var addUrl = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, 0, 0);
                    builder.AppendFormat(@"
                    <li class=""secondMenu addMain"">
                        <a href=""{0}"" class=""mainMenu"" target=""menu""><font>新增菜单</font></a>
                    </li>", addUrl);
                }

                ltlMenu.Text = builder.ToString();
            }
        }
Beispiel #11
0
        public void Sync_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                try
                {
                    var isSync       = false;
                    var errorMessage = string.Empty;

                    var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);

                    if (WeiXinManager.IsBinding(accountInfo))
                    {
                        var resultFull = new GetMenuResultFull();
                        resultFull.menu        = new MenuFull_ButtonGroup();
                        resultFull.menu.button = new List <MenuFull_RootButton>();

                        var publishmentSystemUrl = PageUtils.AddProtocolToUrl(PageUtility.GetPublishmentSystemUrl(PublishmentSystemInfo, string.Empty));

                        var menuInfoList = DataProviderWX.MenuDAO.GetMenuInfoList(PublishmentSystemID, 0);
                        foreach (var menuInfo in menuInfoList)
                        {
                            var rootButton = new MenuFull_RootButton();
                            rootButton.name = menuInfo.MenuName;

                            rootButton.sub_button = new List <MenuFull_RootButton>();
                            var subMenuInfoList = DataProviderWX.MenuDAO.GetMenuInfoList(PublishmentSystemID, menuInfo.MenuID);

                            if (subMenuInfoList.Count > 0)
                            {
                                foreach (var subMenuInfo in subMenuInfoList)
                                {
                                    var subButton = new MenuFull_RootButton();

                                    var isExists = false;

                                    subButton.name = subMenuInfo.MenuName;
                                    if (subMenuInfo.MenuType == EMenuType.Site)
                                    {
                                        var pageUrl = string.Empty;
                                        if (subMenuInfo.ContentID > 0)
                                        {
                                            var tableStyle = NodeManager.GetTableStyle(PublishmentSystemInfo, subMenuInfo.ChannelID);
                                            var tableName  = NodeManager.GetTableName(PublishmentSystemInfo, subMenuInfo.ChannelID);

                                            var contentInfo = DataProvider.ContentDAO.GetContentInfoNotTrash(tableStyle, tableName, subMenuInfo.ContentID);
                                            if (contentInfo != null)
                                            {
                                                pageUrl = PageUtility.GetContentUrl(PublishmentSystemInfo, contentInfo, true);
                                            }
                                        }
                                        else
                                        {
                                            var nodeInfo = NodeManager.GetNodeInfo(PublishmentSystemID, subMenuInfo.ChannelID);
                                            if (nodeInfo != null)
                                            {
                                                pageUrl = PageUtility.GetChannelUrl(PublishmentSystemInfo, nodeInfo);
                                            }
                                        }

                                        if (!string.IsNullOrEmpty(pageUrl))
                                        {
                                            isExists       = true;
                                            subButton.type = "view";
                                            subButton.url  = PageUtils.AddProtocolToUrl(pageUrl);
                                        }
                                    }
                                    else if (subMenuInfo.MenuType == EMenuType.Keyword)
                                    {
                                        if (KeywordManager.IsExists(PublishmentSystemID, subMenuInfo.Keyword))
                                        {
                                            isExists       = true;
                                            subButton.type = "click";
                                            subButton.key  = subMenuInfo.Keyword;
                                        }
                                    }
                                    else if (subMenuInfo.MenuType == EMenuType.Url)
                                    {
                                        if (!string.IsNullOrEmpty(subMenuInfo.Url))
                                        {
                                            isExists       = true;
                                            subButton.type = "view";
                                            subButton.url  = subMenuInfo.Url;
                                        }
                                    }

                                    if (!isExists)
                                    {
                                        subButton.type = "view";
                                        subButton.url  = publishmentSystemUrl;
                                    }

                                    rootButton.sub_button.Add(subButton);
                                }
                            }
                            else
                            {
                                var isExists = false;

                                if (menuInfo.MenuType == EMenuType.Site)
                                {
                                    var pageUrl = string.Empty;
                                    if (menuInfo.ContentID > 0)
                                    {
                                        var tableStyle = NodeManager.GetTableStyle(PublishmentSystemInfo, menuInfo.ChannelID);
                                        var tableName  = NodeManager.GetTableName(PublishmentSystemInfo, menuInfo.ChannelID);

                                        var contentInfo = DataProvider.ContentDAO.GetContentInfoNotTrash(tableStyle, tableName, menuInfo.ContentID);
                                        if (contentInfo != null)
                                        {
                                            pageUrl = PageUtility.GetContentUrl(PublishmentSystemInfo, contentInfo, true);
                                        }
                                    }
                                    else
                                    {
                                        var nodeInfo = NodeManager.GetNodeInfo(PublishmentSystemID, menuInfo.ChannelID);
                                        if (nodeInfo != null)
                                        {
                                            pageUrl = PageUtility.GetChannelUrl(PublishmentSystemInfo, nodeInfo);
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(pageUrl))
                                    {
                                        isExists        = true;
                                        rootButton.type = "view";
                                        rootButton.url  = PageUtils.AddProtocolToUrl(pageUrl);
                                    }
                                }
                                else if (menuInfo.MenuType == EMenuType.Keyword)
                                {
                                    if (KeywordManager.IsExists(PublishmentSystemID, menuInfo.Keyword))
                                    {
                                        isExists        = true;
                                        rootButton.type = "click";
                                        rootButton.key  = menuInfo.Keyword;
                                    }
                                }
                                else if (menuInfo.MenuType == EMenuType.Url)
                                {
                                    if (!string.IsNullOrEmpty(menuInfo.Url))
                                    {
                                        isExists        = true;
                                        rootButton.type = "view";
                                        rootButton.url  = menuInfo.Url;
                                    }
                                }

                                if (!isExists)
                                {
                                    rootButton.type = "view";
                                    rootButton.url  = publishmentSystemUrl;
                                }
                            }

                            resultFull.menu.button.Add(rootButton);
                        }

                        isSync = SyncMenu(resultFull, accountInfo, out errorMessage);
                    }
                    else
                    {
                        errorMessage = "您的微信公众号未绑定,请先绑定之后同步菜单";
                    }

                    if (isSync)
                    {
                        SuccessMessage("菜单同步成功,取消关注公众账号后再次关注,可以立即看到创建后的效果");
                    }
                    else
                    {
                        FailMessage($"菜单同步失败:{errorMessage}");
                        var logInfo = new ErrorLogInfo(0, DateTime.Now, errorMessage, string.Empty, "微信同步菜单错误");
                        LogUtils.AddErrorLog(logInfo);
                    }
                }
                catch (Exception ex)
                {
                    FailMessage($"菜单同步失败:{ex.Message}");

                    var logInfo = new ErrorLogInfo(0, DateTime.Now, ex.Message, ex.StackTrace, "微信同步菜单错误");
                    LogUtils.AddErrorLog(logInfo);
                }
            }
        }
Beispiel #12
0
 public static string GetMPToken(int publishmentSystemID)
 {
     return(WeiXinManager.GetAccountInfo(publishmentSystemID).Token);
 }