Exemple #1
0
        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="key"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public List <SearchBook> SearchBook(string key, BookSearchType type, int pageSize, int pageIndex, ResourceFromSite siteType)
        {
            var bookCache = MemoryCacheProvider.Cache.Get(key + siteType + pageIndex) as List <SearchBook>;

            if (bookCache != null)
            {
                return(bookCache);
            }
            var rst = new List <SearchBook>();

            switch (siteType)
            {
            case ResourceFromSite.起点:
                var qRst = SearchQiDian(key, type, pageSize, pageIndex);
                if (qRst != null)
                {
                    foreach (var item in qRst)
                    {
                        var temp = new SearchBook()
                        {
                            ResourceId  = item.bookid,
                            AuthorName  = item.authorname,
                            BookName    = item.bookname,
                            BookUrl     = item.bookurl,
                            Description = item.description,
                            LastChapter = item.lastchaptername,
                            ImgUrl      = item.coverurl
                        };
                        var vip    = "http://vipreader.qidian.com/BookReader/vip,";
                        var putong = "http://read.qidian.com/BookReader/";

                        if (item.lastvipchapter == null || item.lastvipchapter == "0" || item.lastvipchapter == "")
                        {
                            temp.LastChapterUrl = putong + item.bookid + "," + item.lastchapter + ".aspx";
                        }
                        else
                        {
                            temp.LastChapterUrl = vip + item.bookid + "," + item.lastchapter + ".aspx";
                        }
                        MemoryCacheProvider.Cache.Add(item.bookid + ResourceFromSite.起点.ToString(), temp, DateTimeOffset.Now.AddHours(1));
                        rst.Add(temp);
                    }
                }
                break;

            case ResourceFromSite.十七K:
                break;

            default:
                break;
            }
            MemoryCacheProvider.Cache.Add(key + siteType + pageIndex, rst, DateTimeOffset.Now.AddHours(1));
            return(rst);
        }
Exemple #2
0
        /// <summary>
        /// 检索起点
        /// </summary>
        /// <param name="key"></param>
        /// <param name="type"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        private List <QiDianResponseBook> SearchQiDian(string key, BookSearchType type, int pageSize, int pageIndex)
        {
            var encodeKey  = System.Web.HttpUtility.HtmlEncode(key);
            var searchType = "";

            if (type == BookSearchType.书名)
            {
                searchType = "bookname";
            }
            else if (type == BookSearchType.作者)
            {
                searchType = "authorname";
            }
            var url = "http://sosu.qidian.com/ajax/search.ashx?method=Search&keyword=" + encodeKey + "&range=&ranker=&n=" + pageSize + "&start=" + pageSize * pageIndex + "&internalsiteid=&categoryid=&action_status=&authortagid=&sign_status=&pricetypeid=&rpid=10&groupbyparams=&impression=&roleinfo=&searchtype=" + searchType + "&timespan=&noec";

            string responseString = BookHttpHelper.GetHtml(url, HttpRefer.QiDian);

            return(GetBooksOfJaon(responseString));
        }