Example #1
0
        protected bool VerifyRedirectToken(string novelId, out int code, out Constants.Novel.ChapterDirection direction, int timeout = 0)
        {
            if (ChapterContext.IsToken)
            {
                code      = 0;
                direction = Constants.Novel.ChapterDirection.none;
                string token     = UrlParameterHelper.GetParams("t");
                string timeStamp = UrlParameterHelper.GetParams("s");
                string random    = UrlParameterHelper.GetParams("r");

                if (string.IsNullOrEmpty(token) ||
                    string.IsNullOrEmpty(timeStamp) ||
                    string.IsNullOrEmpty(random))
                {
                    return(false);
                }

                return(ChapterContext.VerifyRedirectToken(token, novelId, timeStamp, random, out code, out direction, timeout));
            }
            else
            {
                code = StringHelper.ToInt(UrlParameterHelper.GetParams("chapterCode"));
                if (!EnumHelper.TryParsebyName <Constants.Novel.ChapterDirection>(UrlParameterHelper.GetParams("direction"), out direction))
                {
                    direction = Constants.Novel.ChapterDirection.none;
                }
                return(true);
            }
        }
Example #2
0
        /// <summary>
        /// 获取章节信息(上一章/本章/下一章)
        /// </summary>
        /// <param name="novelId">小说Id</param>
        /// <param name="chapterCode">章节编号</param>
        /// <param name="direction">向前/当前/向后</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        public Chapter GetChapter(int novelId, int chapterCode, Constants.Novel.ChapterDirection direction, int status = 1)
        {
            if (novelId <= 0 || chapterCode < 0)
            {
                return(null);
            }

            Chapter model = null;

            using (var conn = DbConnection(DbOperation.Read))
            {
                using (var tran = BeginTransaction(conn))
                {
                    var repo = new Repository.ChapterRepo(conn, tran);
                    if ((model = repo.GetChapter(novelId, chapterCode, direction, status)).IsNullOrEmpty <Chapter>() && direction != Constants.Novel.ChapterDirection.none)
                    {
                        model = repo.GetTopChapter(novelId, chapterCode, direction, status);
                    }

                    tran.Commit();
                }
            }

            return(model);
        }
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            NovelId = StringHelper.ToInt(UrlParameterHelper.GetParams("novelId"));

            if (!VerifyRedirectToken(StringHelper.ToString(NovelId), out ChapterCode, out ChapterDirection) || NovelId <= 0 || ChapterCode < 0)
            {
                ChapterCode      = 0;
                ChapterDirection = Constants.Novel.ChapterDirection.none;
            }
        }
Example #4
0
        public ChapterRedirectManage(int chapterRedirectTimeout = 0)
        {
            string nid = UrlParameterHelper.GetParams("novelId");

            if (!string.IsNullOrEmpty(nid) &&
                !VerifyRedirectToken(nid, out _chapterCode, out _chapterDirection, chapterRedirectTimeout) || _chapterCode < 0)
            {
                _chapterCode      = 0;
                _chapterDirection = Constants.Novel.ChapterDirection.none;
            }

            _novelId = StringHelper.ToInt(nid);
        }
Example #5
0
        public ActionResult Content(int novelId = 0, int chapterCode = 0, Constants.Novel.ChapterDirection chapterDirection = Constants.Novel.ChapterDirection.none)
        {
            StringBuilder sb = new StringBuilder();

            //Novel novel = _bookService.GetNovel(novelId);
            //if (novel != null && novel.Id > 0)
            //{
            //    Chapter chapter = _chapterService.GetChapter(novelId, chapterCode, chapterDirection, out chapterCode);
            //    if (chapter != null && chapter.Id > 0 && IsRead(_orderService))
            //    {
            //        sb.Append("{\"Content\": \"" + GetContent(novel.ContentType, chapter.ChapterName, novel.FilePath, chapter.FileName) + "\"}");
            //    }
            //}
            return(Json(sb.ToString(), JsonRequestBehavior.AllowGet));
        }
Example #6
0
        /// <summary>
        /// 获取章节信息(上一章/本章/下一章)
        /// </summary>
        /// <param name="novelId">小说Id</param>
        /// <param name="chapterCode">章节编号</param>
        /// <param name="status">状态</param>
        /// <param name="direction">向前/当前/向后</param>
        /// <param name="tChapterCode">章节编号(上一章/本章/下一章)</param>
        /// <returns></returns>
        public Chapter GetChapter(int novelId, int chapterCode, Constants.Novel.ChapterDirection direction, out int tChapterCode, int status = 1)
        {
            tChapterCode = chapterCode;

            if (novelId <= 0 || chapterCode < 0)
            {
                return(null);
            }

            Chapter model = GetChapter(novelId, chapterCode, direction, status);

            if (!model.IsNullOrEmpty <Chapter>() && model.Id > 0)
            {
                tChapterCode = model.ChapterCode;
            }

            return(model);
        }
Example #7
0
        /// <summary>
        /// 获取章节信息(上一章/本章/下一章)
        /// </summary>
        /// <param name="novelId">小说Id</param>
        /// <param name="chapterCode">章节编号</param>
        /// <param name="direction">向前/当前/向后</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        public Chapter GetTopChapter(int novelId, int chapterCode, Constants.Novel.ChapterDirection direction, int status)
        {
            if (novelId <= 0 || chapterCode < 0 || direction == Constants.Novel.ChapterDirection.none)
            {
                return(null);
            }

            string sql = "select top 1 * from dbo.Chapter with (nolock) where NovelId = @NovelId and Status = @Status and OnlineTime < @OnlineTime";

            switch (direction)
            {
            case Constants.Novel.ChapterDirection.pre:
                sql += " and ChapterCode < @ChapterCode order by chaptercode desc";
                break;

            case Constants.Novel.ChapterDirection.next:
                sql += " and ChapterCode > @ChapterCode order by chaptercode asc";
                break;
            }

            return(DbManage.Query <Chapter>(sql, new { NovelId = novelId, ChapterCode = chapterCode, Status = status, OnlineTime = DateTime.Now }).FirstOrDefault());
        }
Example #8
0
        /// <summary>
        /// 获取章节信息(上一章/本章/下一章)
        /// </summary>
        /// <param name="novelId">小说Id</param>
        /// <param name="chapterCode">章节编号</param>
        /// <param name="status">状态</param>
        /// <param name="direction">向前/当前/向后</param>
        /// <returns></returns>
        public Chapter GetChapter(int novelId, int chapterCode, Constants.Novel.ChapterDirection direction, int status)
        {
            if (novelId <= 0 || chapterCode < 0)
            {
                return(null);
            }

            string sql = "select * from dbo.Chapter with (nolock) where NovelId = @NovelId and ChapterCode = @ChapterCode and Status = @Status and OnlineTime < @OnlineTime";

            switch (direction)
            {
            case Constants.Novel.ChapterDirection.pre:
                chapterCode = chapterCode > 0 ? (chapterCode - 1) : 0;
                break;

            case Constants.Novel.ChapterDirection.next:
                chapterCode += 1;
                break;
            }

            return(DbManage.Query <Chapter>(sql, new { NovelId = novelId, ChapterCode = chapterCode, Status = status, OnlineTime = DateTime.Now }).FirstOrDefault());
        }
Example #9
0
        public static string CreateRedirectToken(int id, int code, Constants.Novel.ChapterDirection direction, out int timeStamp, out int random)
        {
            timeStamp = 0;
            random    = 0;

            if (id <= 0 || code < 0)
            {
                return("");
            }

            timeStamp = StringHelper.ConvertTimeStamp(DateTime.Now);
            random    = rd.Next(1000, 10000);
            string txt    = string.Concat(code, "_", StringHelper.ToString(direction), "_", StringHelper.ToString(id), "_", string.Concat(random, timeStamp));
            string result = SecurityHelper.EncryptBase64XorBase64Url(txt, RedirectKey);

            if (!string.IsNullOrEmpty(result))
            {
                result = UrlParameterHelper.UrlEncode(result);
            }

            return(result);
        }
Example #10
0
        public static bool VerifyRedirect(int novelId, int chapterCode, Constants.Novel.ChapterDirection direction, out string hideUrl, bool IsRedirectWechat = false)
        {
            hideUrl = "";

            bool flag = false;

            if (//StringHelper.GetUserAgent().ToLower().Contains("micromessenger") &&
                novelId > 0 &&
                IsRedirectWechat)
            {
                long   timeout     = 86400; //单位:秒,24小时
                string cookieName  = string.Concat("cdwh_", novelId);
                string cookieValue = CookieHelper.Get(cookieName);
                if (string.IsNullOrEmpty(cookieValue) || (DateTime.Now - StringHelper.ToDateTime(cookieValue)).TotalSeconds > timeout)
                {
                    int curChapterCode = chapterCode;
                    if (direction == Constants.Novel.ChapterDirection.next)
                    {
                        curChapterCode += 1;
                    }
                    else if (direction == Constants.Novel.ChapterDirection.pre)
                    {
                        curChapterCode -= 1;
                    }

                    IChapterRedirectService service = DataContext.ResolveService <IChapterRedirectService>();
                    ChapterRedirect         model   = service.Get(novelId);
                    if (flag = (model != null && model.Id > 0 && model.ChapterCode <= curChapterCode && !string.IsNullOrEmpty(model.HideChapterUrl)))
                    {
                        CookieHelper.Set(cookieName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.AddSeconds(timeout));
                        hideUrl = model.HideChapterUrl;
                    }
                }
            }

            return(flag);
        }
Example #11
0
        public static string GetUrl(string url, int id, int code = 0, Constants.Novel.ChapterDirection direction = Constants.Novel.ChapterDirection.none, string channelId = "")
        {
            if (string.IsNullOrEmpty(url) || id <= 0 || code < 0)
            {
                return("");
            }

            if (!string.IsNullOrEmpty(channelId))
            {
                url = url.GetChannelRouteUrl(channelId);
            }

            IDictionary <string, object> dict = new Dictionary <string, object>();

            if (IsToken)
            {
                int timeStamp = 0;
                int random    = 0;

                string token = CreateRedirectToken(id, code, direction, out timeStamp, out random);
                if (!string.IsNullOrEmpty(token))
                {
                    dict.Add("novelId", id);
                    dict.Add("t", token);
                    dict.Add("s", timeStamp);
                    dict.Add("r", random);
                }
            }
            else
            {
                dict.Add("novelId", id);
                dict.Add("chapterCode", code);
                dict.Add("direction", StringHelper.ToString(direction));
            }

            return(StringHelper.SpliceUrl(url, dict));
        }
Example #12
0
        private void ResetChapterCode(Constants.Novel.ChapterDirection chapterDirection)
        {
            if (MaxChapterCode >= MinChapterCode && MinChapterCode >= 0)
            {
                int min = MinChapterCode;
                int max = MaxChapterCode;

                switch (chapterDirection)
                {
                case Constants.Novel.ChapterDirection.pre:
                    min += 1;
                    max += 1;
                    break;

                case Constants.Novel.ChapterDirection.next:
                    min = ((min > 0) ? (min - 1) : 0);
                    max = ((max > 0) ? (max - 1) : 0);
                    break;
                }

                ChapterCode = ChapterCode < min ? min : ChapterCode;
                ChapterCode = ChapterCode > max ? max : ChapterCode;
            }
        }
Example #13
0
        public static bool VerifyRedirectToken(string token, string id, string timeStamp, string random, out int code, out Constants.Novel.ChapterDirection direction, int timeout = 0)
        {
            code      = 0;
            direction = Constants.Novel.ChapterDirection.none;

            if (string.IsNullOrEmpty(token) ||
                string.IsNullOrEmpty(id) ||
                string.IsNullOrEmpty(timeStamp) ||
                string.IsNullOrEmpty(random))
            {
                return(false);
            }

            bool flag = false;

            try
            {
                token = UrlParameterHelper.UrlDecode(token);
                string txt = SecurityHelper.DecryptBase64XorBase64Url(token, RedirectKey);
                if (!string.IsNullOrEmpty(txt))
                {
                    string[] list = txt.Split('_');
                    if (!StringHelper.IsNullOrEmpty(list))
                    {
                        if (timeout == 0 || ((DateTime.Now - StringHelper.ConvertDateTime(timeStamp)).TotalMinutes < timeout))
                        {
                            code = StringHelper.ToInt(list[0]);
                            if (list.Length <= 3)
                            {
                                flag = (string.Compare(id, list[1], true) == 0 &&
                                        string.Compare(string.Concat(random, timeStamp), list[2], true) == 0);
                            }
                            else
                            {
                                flag = (EnumHelper.TryParsebyName <Constants.Novel.ChapterDirection>(list[1], out direction) &&
                                        string.Compare(id, list[2], true) == 0 &&
                                        string.Compare(string.Concat(random, timeStamp), list[3], true) == 0);
                            }
                        }
                    }
                }
            }
            catch { }
            finally
            {
                //if (!flag)
                //{
                //    code = 0;
                //    direction = Constants.ChapterDirection.none;
                //    flag = true;
                //}
            }

            return(flag);
        }