/// <summary> /// 获得某条新闻的详细内容 /// </summary> /// <param name="rData"></param> /// <returns></returns> public Stream NewsContent_Selectbync_n_gid(NewsContentInfo_RD rData) { WebOperationContext context = WebOperationContext.Current; context.OutgoingResponse.ContentType = "application/json;charset=utf-8"; string json = ""; // 获取某条新闻的详细内容 List <NewsContentInfo> list = DataAccess_News.GetNewsContent(rData.n_gid); if (list.Count == 0) { json = string.Format("{{\"contents\":{0},\"shareUrl\":\"{1}\",\"imgs\":{2}}}", string.Empty, string.Empty, string.Empty); } else { string shareUrl = ""; // 分享文章的地址 NewsCateInfo cateInfo = null; string n_gid = ""; // 获取文章分类的相关字段信息,并拼接得到文章分享地址 if (list != null && list.Count > 0) { // 分类ID string cat_id = rData.vl_cateId.ToSafety(); // 根据分类ID获取分类信息 cateInfo = CacheMarker.GetNewsCatesBycat_id(cat_id); string cat_ctrl = (cateInfo != null) ? cateInfo.cat_ctrl : ""; n_gid = list[0].nc_n_gid; shareUrl = "http://qiye.qianzhan.com/show/detail/" + rData.n_gid + ".html"; //ServiceHandler.GetDetailURL(cat_ctrl, cat_id, n_gid, 1, false); } // 存放图片数据 List <ImgsInfo> imgs = new List <ImgsInfo>(); // 自定义文章内容 list = CustomContent(list, n_gid, "News_" + cateInfo.cat_tableIndex, out imgs, rData.vl_screenSize); // 插入浏览记录 int logIndex = VisitLog_Insert(rData, shareUrl); if (logIndex == -1) { return(null); } var jsonSerialiser = new JavaScriptSerializer(); json = string.Format("{{\"contents\":{0},\"shareUrl\":\"{1}\",\"imgs\":{2}}}", jsonSerialiser.Serialize(list), shareUrl, jsonSerialiser.Serialize(imgs)); } return(new MemoryStream(Encoding.UTF8.GetBytes(json))); }
/// <summary> /// 插入访问日志或分享日志 /// </summary> /// <param name="rData"></param> /// <param name="shareUrl"></param> /// <param name="preTableName"></param> /// <returns></returns> private int VisitLog_Insert(NewsContentInfo_RD rData, string shareUrl, string preTableName = "VisitLog_") { WebOperationContext context = WebOperationContext.Current; context.OutgoingResponse.ContentType = "application/json; charset=utf-8"; VisitLogInfo vlog = new VisitLogInfo(); IncomingWebRequestContext inContext = context.IncomingRequest; UserAgent ua = UserAgentCache.CreateOrGetCacheItem(inContext.UserAgent); vlog.vl_browser = ua.GetBrowser(); vlog.vl_cookieId = string.Empty; vlog.vl_createTime = DateTime.Now; vlog.vl_gid = rData.n_gid; vlog.vl_id = 0; vlog.vl_ip = Util.Get_RemoteIp(); vlog.vl_remoteAddr = vlog.vl_ip; vlog.vl_osName = ua.GetPlatform(); // todo 操作系统的获取可能需要重新实现 //UserAgent.KeyItem ki = ua.Spider(); vlog.vl_spiderName = rData.vl_spiderName != null?ShareFlatform(rData.vl_spiderName) : string.Empty; vlog.vl_referrer = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.OriginalString + "/" + rData.n_gid; vlog.vl_url = shareUrl;// 拼接成PC端地址 vlog.vl_cateId = rData.vl_cateId; //vlog.vl_screenSize = string.Empty; vlog.vl_totalTime = 0; vlog.vl_type = rData.vl_type; string userName = rData.vl_userId; vlog.vl_userName = (userName == "|") ? "" : userName; vlog.vl_screenSize = rData.vl_screenSize; vlog.vl_host = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.Host; // 主域名 string tblName = preTableName + vlog.vl_createTime.ToString("yyyyMMdd"); // 插入表的表名 // 插入浏览记录 int logIndex = DataAccess_News.VisitLog_Insert(vlog, tblName); return(logIndex); }