<%@ WebHandler Language="C#" Class="server" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using Model;
using System.Text.RegularExpressions;
public class server : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
try
{
//获取调用该页面的“方法名”
string MethodName = HttpContext.Current.Request.PathInfo.Substring(1);
//通过方法名找到该方法对象
System.Reflection.MethodInfo method = this.GetType().GetMethod(MethodName);
if (method != null)
//反射
HttpContext.Current.Response.Write(method.Invoke(this, null));
}
catch (Exception)
{
HttpContext.Current.Response.Write("该服务不显示对外开放,需提供需要调用的方法和参数");
}
}
//获取所有栏目
public string GetColumn()
{
string code = HttpContext.Current.Request.QueryString["code"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39")
{
string sql = "select * from columnInfo";
List<columnInfo> list = new List<columnInfo>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text))
{
while (dr.Read())
{
columnInfo Model = new columnInfo();
Model.cid = Convert.ToInt32(dr["cid"]);
Model.columnNmae = dr["columnNmae"].ToString();
Model.note = dr["note"].ToString();
list.Add(Model);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<columnInfo>>(list);
return xml;
}
else
{
return "非法请求";
}
}
//根据栏目获取文章列表
public string GetArticleBycid()
{
string code = HttpContext.Current.Request.QueryString["code"];
string cid = HttpContext.Current.Request.QueryString["cid"];
string index = HttpContext.Current.Request.QueryString["index"];
string count = HttpContext.Current.Request.QueryString["count"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && cid != null && index != null && count != null)
{
string sql = "select top " + count + " * from articleInfo where cid=@cid and articleType=1 and id not in(select top " + index + " id from articleInfo where cid=@cid and articleType=1 order by articleTime desc) order by articleTime desc";
SqlParameter[] sqlp = new SqlParameter[] {
new SqlParameter("@cid",cid),
};
List<articleTitleInfo> list = new List<articleTitleInfo>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text, sqlp))
{
while (dr.Read())
{
articleTitleInfo Model = new articleTitleInfo();
Model.articleTitle = dr["articleTitle"].ToString();
Model.id = Convert.ToInt32(dr["id"]);
Model.articleTime = Convert.ToDateTime(dr["articleTime"]);
string[] imgs = GetHtmlImageUrlList(dr["articleContent"].ToString());
if (imgs.Length > 0)
{
if (imgs[0].Trim().Length > 7 && imgs[0].Trim().Substring(0, 7).ToLower() == "http://")
{
Model.imgUrl = imgs[0].Trim();
}
else
{
//处理
string url = HttpContext.Current.Request.Url.AbsoluteUri;
url = url.Substring(0, url.LastIndexOf("webserver"));
string sa = imgs[0].Trim();
if (sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] > 96 && sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] < 123)
{
//不需要转换
Model.imgUrl = url + sa;
}
else
{
Model.imgUrl = url + sa.Substring(sa.IndexOf("/") + 1);
}
}
}
else
{
Model.imgUrl = "";
}
//文字处
string co = StripHT(dr["articleContent"].ToString());
if (co.Trim().Length > 30)
{
co = co.Substring(0, 30);
}
Model.articleContent = co;
list.Add(Model);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<articleTitleInfo>>(list);
return xml;
}
else
{
return "非法请求";
}
}
//根据栏目获取文章列表(图片)
public string GetImagArticleList()
{
string code = HttpContext.Current.Request.QueryString["code"];
string cid = HttpContext.Current.Request.QueryString["cid"];
string index = HttpContext.Current.Request.QueryString["index"];
string count = HttpContext.Current.Request.QueryString["count"];
try
{
Convert.ToInt32(index);
Convert.ToInt32(count);
}
catch (Exception)
{
return "非法请求";
}
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && cid !=null&& index != null && count != null)
{
string sql = "select top " + count + " * from articleInfo where articleType=2 and cid=" + cid + " and id not in(select top " + index + " id from articleInfo where articleType=2 and cid=" + cid + " order by articleTime desc) order by articleTime desc";
List<ImagearticleInfo> list = new List<ImagearticleInfo>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text))
{
while (dr.Read())
{
ImagearticleInfo Model = new ImagearticleInfo();
Model.articleTitle = dr["articleTitle"].ToString();
Model.id = Convert.ToInt32(dr["id"]);
Model.articleTime = Convert.ToDateTime(dr["articleTime"]);
string[] imgs = GetHtmlImageUrlList(dr["articleContent"].ToString());
Model.imgCount = imgs.Length;
//第一张图
if (imgs.Length > 0)
{
if (imgs[0].Trim().Length > 7 && imgs[0].Trim().Substring(0, 7).ToLower() == "http://")
{
Model.imgUrl1 = imgs[0].Trim();
}
else
{
//处理
Model.imgUrl1 = GetImgUrlHtpp(imgs[0]);
}
}
else
{
Model.imgUrl1 = "";
}
//第二章图片
if (imgs.Length > 1)
{
if (imgs[1].Trim().Length > 7 && imgs[1].Trim().Substring(0, 7).ToLower() == "http://")
{
Model.imgUrl2 = imgs[1].Trim();
}
else
{
//处理
Model.imgUrl2 = GetImgUrlHtpp(imgs[1]);
}
}
else
{
Model.imgUrl2 = "";
}
//文字处
string co = StripHT(dr["articleContent"].ToString());
if (co.Trim().Length > 30)
{
co = co.Substring(0, 30);
}
//Model.articleContent = co;
list.Add(Model);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<ImagearticleInfo>>(list);
return xml;
}
else
{
return "非法请求";
}
}
public string GetImgUrlHtpp(string http)
{
string url = HttpContext.Current.Request.Url.AbsoluteUri;
url = url.Substring(0, url.LastIndexOf("webserver"));
string sa = http.Trim();
if (sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] > 96 && sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] < 123)
{
//不需要转换
return url + sa;
}
else
{
return url + sa.Substring(sa.IndexOf("/") + 1);
}
}
//提取html中的文本
private string StripHT(string Htmlstring) //从html中提取纯文本
{
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
return Htmlstring;
}
public string[] GetHtmlImageUrlList(string sHtmlText)
{
// 定义正则表达式用来匹配 img 标签
Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
// 搜索匹配的字符串
MatchCollection matches = regImg.Matches(sHtmlText);
int i = 0;
string[] sUrlList = new string[matches.Count];
// 取得匹配项列表
foreach (Match match in matches)
sUrlList[i++] = match.Groups["imgUrl"].Value;
return sUrlList;
}
//根据栏目获取文章
public string GetArticleById()
{
string code = HttpContext.Current.Request.QueryString["code"];
string id = HttpContext.Current.Request.QueryString["id"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && id != null)
{
string sql = "select *,(select columnNmae from columnInfo where columnInfo.cid=articleInfo.cid) as cname from articleInfo,userInfo where articleInfo.uid=userInfo.uid and id=@id order by articleTime desc";
SqlParameter sqlp = new SqlParameter("@id", id);
articleInfo Model = new articleInfo();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text, sqlp))
{
while (dr.Read())
{
Model.articleAuthor = dr["articleAuthor"].ToString();
Model.articleContent = dr["articleContent"].ToString();
Model.articleSource = dr["articleSource"].ToString();
Model.articleTime = Convert.ToDateTime(dr["articleTime"]);
Model.articleTitle = dr["articleTitle"].ToString();
Model.articleType = Convert.ToInt32(dr["articleType"]);
Model.cid = Convert.ToInt32(dr["cid"]);
Model.cname = dr["cname"].ToString();
Model.clickCount = Convert.ToInt32(dr["clickCount"]);
Model.id = Convert.ToInt32(dr["id"]);
Model.uid = Convert.ToInt32(dr["uid"]);
Model.uname = dr["uname"].ToString();
Model.indexIn = Convert.ToInt32(dr["indexIn"]);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<articleInfo>(Model);
return xml;
}
else
{
return "非法请求";
}
}
//获取轮换新闻
public string GetRotateArticle()
{
string code = HttpContext.Current.Request.QueryString["code"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39")
{
string sql = "select top 5 * from rotateArticle order by id desc";
List<rotateArticle> list = new List<rotateArticle>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text))
{
while (dr.Read())
{
rotateArticle Model = new rotateArticle();
//Model.articleUrl = dr["articleUrl"].ToString();
if (dr["articleUrl"].ToString().Trim().Length > 7 && dr["articleUrl"].ToString().Trim().Substring(0, 7).ToLower() == "http://")
{
Model.articleUrl = dr["articleUrl"].ToString().Trim();
}
else
{
//处理
Model.articleUrl = GetImgUrlHtpp(dr["articleUrl"].ToString());
}
Model.id = Convert.ToInt32(dr["id"]);
Model.imageTitle = dr["imageTitle"].ToString();
//Model.imageUrl = dr["imageUrl"].ToString();
if (dr["imageUrl"].ToString().Trim().Length > 7 && dr["imageUrl"].ToString().Trim().Substring(0, 7).ToLower() == "http://")
{
Model.imageUrl = dr["imageUrl"].ToString().Trim();
}
else
{
//处理
Model.imageUrl = GetImgUrlHtpp(dr["imageUrl"].ToString());
}
if (dr["articleUrlPhone"].ToString().Trim().Length > 7 && dr["articleUrlPhone"].ToString().Trim().Substring(0, 7).ToLower() == "http://")
{
Model.articleUrlPhone = dr["articleUrlPhone"].ToString().Trim();
}
else
{
//处理
Model.articleUrlPhone = GetImgUrlHtpp(dr["articleUrlPhone"].ToString());
}
//Model.articleUrlPhone = dr["articleUrlPhone"].ToString();
list.Add(Model);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<rotateArticle>>(list);
return xml;
}
else
{
return "非法请求";
}
}
//------------------------------------------------------------意见的提交-
//测试意见
public string PostYijian()
{
string txt = HttpContext.Current.Request.Form["content"].ToString();
string code = HttpContext.Current.Request.Form["code"].ToString();
if (code == "5666DFA2C1D11E39" && txt.Trim().Length > 0)
{
string sql = "insert into opinionInfo(opinionContent,userIp) values(@opinionContent,@userIp)";
try
{
SqlParameter[] sqlp = new SqlParameter[]{
new SqlParameter("@opinionContent", txt),
new SqlParameter("@userIp", GetMacHelp.GetIp(HttpContext.Current.Request))
};
if (sysSqlHelp.SqlHelp.ExecuteNonQuery(sql, CommandType.Text, sqlp) > 0)
{
return "1";
}
else
{
return "0";
}
}
catch (Exception)
{
return "2";
}
}
else
{
return "3";
}
}
//-------------------------------------------------------------检察长信箱
public string EmailSent()
{
string emalil = HttpContext.Current.Request.Form["emalil"].ToString();
string theme = HttpContext.Current.Request.Form["theme"].ToString();
string content = HttpContext.Current.Request.Form["content"].ToString();
string code = HttpContext.Current.Request.Form["code"].ToString();
if (code != "5666DFA2C1D11E39")
{
return "3";
}
try
{
string sql = "insert into EmailSent(Emalil, theme, [content],uip) values(@Emalil, @theme, @content,@uip)";
SqlParameter[] sqlps = new SqlParameter[] {
new SqlParameter("@Emalil",emalil),
new SqlParameter("@theme",theme),
new SqlParameter("@content",content),
new SqlParameter("@uip",GetMacHelp.GetIp(HttpContext.Current.Request))
};
if (sysSqlHelp.SqlHelp.ExecuteNonQuery(sql, CommandType.Text, sqlps) > 0)
{
return "1";
}
else
{
return "0";
}
}
catch (Exception)
{
return "2";
}
}
//------------------------------------------------------法律资讯
public string lawSent()
{
string emalil = HttpContext.Current.Request.Form["emalil"].ToString();
string theme = HttpContext.Current.Request.Form["theme"].ToString();
string content = HttpContext.Current.Request.Form["content"].ToString();
string code = HttpContext.Current.Request.Form["code"].ToString();
if (code != "5666DFA2C1D11E39")
{
return "3";
}
try
{
string sql = "insert into lawSent(Emalil, theme, [content],uip) values(@Emalil, @theme, @content,@uip)";
SqlParameter[] sqlps = new SqlParameter[] {
new SqlParameter("@Emalil",emalil),
new SqlParameter("@theme",theme),
new SqlParameter("@content",content),
new SqlParameter("@uip",GetMacHelp.GetIp(HttpContext.Current.Request))
};
if (sysSqlHelp.SqlHelp.ExecuteNonQuery(sql, CommandType.Text, sqlps) > 0)
{
return "1";
}
else
{
return "0";
}
}
catch (Exception)
{
return "2";
}
}
//---------------------------------------------------------------图片新闻
//读取图片文章的具体类容
//根据栏目获取文章列表(图片)
public string GetImagArticleById()
{
string code = HttpContext.Current.Request.QueryString["code"];
string id = HttpContext.Current.Request.QueryString["id"];
//16位MD5加密wuhansiwen
string xml = "";
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && id != null)
{
string sql = "select * from articleInfo,userInfo where articleInfo.uid=userInfo.uid and id=@id order by articleTime desc";
SqlParameter sqlp = new SqlParameter("@id", id);
DataTable dt = sysSqlHelp.SqlHelp.GetDataTable(sql, CommandType.Text, sqlp);
if (dt.Rows.Count > 0)
{
string artCount = dt.Rows[0]["articleContent"].ToString();
string[] img = GetHtmlImageUrlListImgArt(ref artCount);
artCount = StripHTImgArt(artCount);
string[] title = artCount.Split('|');
List<imageArtcle> list = new List<imageArtcle>();
for (int i = 0; i < img.Length; i++)
{
imageArtcle model = new imageArtcle();
model.imgUrl = img[i];
if (img[i].Trim().Length > 7 && img[i].Trim().Substring(0, 7).ToLower() == "http://")
{
model.imgUrl = img[i].Trim();
}
else
{
//处理
model.imgUrl = GetImgUrlHtpp(img[i]);
}
if (i < title.Length)
{
model.imgTitle = title[i];
}
list.Add(model);
}
//创建对象
imageArtcleInfoPage imagPage = new imageArtcleInfoPage();
imagPage.articleAuthor = dt.Rows[0]["articleAuthor"].ToString();
imagPage.imageList = list;
imagPage.articleSource = dt.Rows[0]["articleSource"].ToString();
imagPage.articleTime = Convert.ToDateTime(dt.Rows[0]["articleTime"]);
imagPage.articleTitle = dt.Rows[0]["articleTitle"].ToString();
imagPage.articleType = Convert.ToInt32(dt.Rows[0]["articleType"]);
imagPage.cid = Convert.ToInt32(dt.Rows[0]["cid"]);
imagPage.clickCount = Convert.ToInt32(dt.Rows[0]["clickCount"]);
imagPage.id = Convert.ToInt32(dt.Rows[0]["id"]);
imagPage.uid = Convert.ToInt32(dt.Rows[0]["uid"]);
imagPage.uname = dt.Rows[0]["uname"].ToString();
imagPage.indexIn = Convert.ToInt32(dt.Rows[0]["indexIn"]);
xml = Help.XmlSerialize<imageArtcleInfoPage>(imagPage);
}
}
return xml;
}
public string GetImagArticleByIdT()
{
string code = HttpContext.Current.Request.QueryString["code"];
string id = HttpContext.Current.Request.QueryString["id"];
//16位MD5加密wuhansiwen
string xml = "";
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && id != null)
{
string sql = "select * from articleInfo,userInfo where articleInfo.uid=userInfo.uid and id=@id order by articleTime desc";
SqlParameter sqlp = new SqlParameter("@id", id);
DataTable dt = sysSqlHelp.SqlHelp.GetDataTable(sql, CommandType.Text, sqlp);
if (dt.Rows.Count > 0)
{
string artCount = dt.Rows[0]["articleContent"].ToString();
string[] img = GetHtmlImageUrlListImgArt(ref artCount);
artCount = StripHTImgArt(artCount);
string[] title = artCount.Split('|');
List<imageArtcle> list = new List<imageArtcle>();
for (int i = 0; i < img.Length; i++)
{
imageArtcle model = new imageArtcle();
model.imgUrl = img[i];
if (img[i].Trim().Length > 7 && img[i].Trim().Substring(0, 7).ToLower() == "http://")
{
model.imgUrl = img[i].Trim();
}
else
{
//处理
model.imgUrl = GetImgUrlHtpp(img[i]);
}
if (i < title.Length)
{
model.imgTitle = title[i];
}
list.Add(model);
}
//创建对象
xml = Help.XmlSerialize<List<imageArtcle>>(list);
}
}
return xml;
}
//提取html中的文本
private string StripHTImgArt(string Htmlstring) //从html中提取纯文本
{
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
return Htmlstring;
}
public string[] GetHtmlImageUrlListImgArt(ref string sHtmlText)
{
// 定义正则表达式用来匹配 img 标签
Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
// 搜索匹配的字符串
MatchCollection matches = regImg.Matches(sHtmlText);
int i = 0;
string[] sUrlList = new string[matches.Count];
// 取得匹配项列表
foreach (Match match in matches)
{
sUrlList[i++] = match.Groups["imgUrl"].Value;
sHtmlText = sHtmlText.Replace(match.ToString(), "|");
}
return sUrlList;
}
//-------------------------------------------------------视频
public string GetVideoList()
{
string code = HttpContext.Current.Request.QueryString["code"];
string index = HttpContext.Current.Request.QueryString["index"];
string count = HttpContext.Current.Request.QueryString["count"];
try
{
Convert.ToInt32(index);
Convert.ToInt32(count);
}
catch (Exception)
{
return "非法请求";
}
string xml = "";
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && index != null && count != null)
{
string sql = "select top " + count + " * from articleInfo where articleType=3 and id not in(select top " + index + " id from articleInfo where articleType=3 order by articleTime desc) order by articleTime desc";
DataTable dt = sysSqlHelp.SqlHelp.GetDataTable(sql, CommandType.Text);
List<videoInfo> list = new List<videoInfo>();
foreach (DataRow item in dt.Rows)
{
videoInfo model = new videoInfo();
model.articleTitle = item["articleTitle"].ToString();
model.articleTime = Convert.ToDateTime(item["articleTime"]);
string sa = GetImagToStr(item["articleContent"].ToString()).Count > 0 ? GetImagToStr(item["articleContent"].ToString())[0].imgUrl : "";
if (sa.Trim().Length > 7 && sa.Trim().Substring(0, 7).ToLower() == "http://")
{
model.videoImgUrl = sa.Trim();
}
else
{
//处理
model.videoImgUrl = GetImgUrlHtpp(sa);
}
model.videoUrl = GetImagToStr(item["articleContent"].ToString()).Count > 0 ? GetImagToStr(item["articleContent"].ToString())[0].imgTitle : "#";
list.Add(model);
}
xml = Help.XmlSerialize<List<videoInfo>>(list);
}
return xml;
}
public List<imageArtcle> GetImagToStr(string html)
{
// 定义正则表达式用来匹配 img 标签
Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
// 搜索匹配的字符串
MatchCollection matches = regImg.Matches(html);
//string[] sUrlList = new string[matches.Count];
List<imageArtcle> list = new List<imageArtcle>();
// 取得匹配项列表
foreach (Match match in matches)
{
imageArtcle model = new imageArtcle();
model.imgUrl = match.Groups["imgUrl"].Value;
string[] title = GetTitle(match.ToString());
if (title.Length > 0)
{
model.imgTitle = title[0];
}
//其它属性
list.Add(model);
}
return list;
}
public string[] GetTitle(string title)
{
// 定义正则表达式用来匹配 img 标签
Regex regImg = new Regex(@"<img\b[^<>]*?\btitle[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
// 搜索匹配的字符串
MatchCollection matches = regImg.Matches(title);
int i = 0;
string[] sUrlList = new string[matches.Count];
// 取得匹配项列表
foreach (Match match in matches)
{
sUrlList[i++] = match.Groups["imgUrl"].Value;
}
return sUrlList;
}
/// <summary>
/// ////////////////////////////////////////////////////////////////////专题
/// </summary>
/// //获取专题列表
public string GetsubjectInfoList()
{
string code = HttpContext.Current.Request.QueryString["code"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39")
{
string sql = "select * from subjectInfo order by SubTime desc";
List<subjectInfo> list = new List<subjectInfo>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text))
{
while (dr.Read())
{
subjectInfo Model = new subjectInfo();
Model.sid = Convert.ToInt32(dr["sid"]);
Model.indexIn = Convert.ToInt32(dr["indexIn"]);
Model.SubImgUrl = dr["SubImgUrl"].ToString();
if (Model.SubImgUrl.Trim().Length > 7 && Model.SubImgUrl.Trim().Substring(0, 7).ToLower() == "http://")
{
Model.SubImgUrl = Model.SubImgUrl.Trim();
}
else
{
//处理
Model.SubImgUrl = GetImgUrlHtpp(Model.SubImgUrl);
}
Model.SubLogUrl = dr["SubLogUrl"].ToString();
if (Model.SubLogUrl.Trim().Length > 7 && Model.SubLogUrl.Trim().Substring(0, 7).ToLower() == "http://")
{
Model.SubLogUrl = Model.SubLogUrl.Trim();
}
else
{
//处理
Model.SubLogUrl = GetImgUrlHtpp(Model.SubLogUrl);
}
Model.SubName = dr["SubName"].ToString();
Model.SubTime = Convert.ToDateTime(dr["SubTime"]);
list.Add(Model);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<subjectInfo>>(list);
return xml;
}
else
{
return "非法请求";
}
}
//获取专题下的所有栏目
public string GetsubColumn()
{
string code = HttpContext.Current.Request.QueryString["code"];
string sid = HttpContext.Current.Request.QueryString["sid"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39"&&sid!=null)
{
string sql = "select * from subColumn where sid=@sid";
SqlParameter sqlp = new SqlParameter("@sid",sid);
List<subColumn> list = new List<subColumn>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text, sqlp))
{
while (dr.Read())
{
subColumn Model = new subColumn();
Model.sid = Convert.ToInt32(dr["sid"]);
Model.note = dr["sid"].ToString();
Model.cid = Convert.ToInt32(dr["cid"]);
Model.SubCName = dr["SubCName"].ToString();
list.Add(Model);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<subColumn>>(list);
return xml;
}
else
{
return "非法请求";
}
}
//获取专题中的文章
public string GetsubArticleList()
{
string code = HttpContext.Current.Request.QueryString["code"];
string sid = HttpContext.Current.Request.QueryString["sid"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && sid != null)
{
string sql = "select * from subColumn where sid=@sid";
SqlParameter sqlp = new SqlParameter("@sid", sid);
//List<subColumn> list = new List<subColumn>();
List<SubArticle> list = new List<SubArticle>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text, sqlp))
{
while (dr.Read())
{
//subColumn Model = new subColumn();
//Model.sid = Convert.ToInt32(dr["sid"]);
//Model.note = dr["sid"].ToString();
//Model.cid = Convert.ToInt32(dr["cid"]);
//Model.SubCName = dr["SubCName"].ToString();
//list.Add(Model);
SubArticle Mode=new SubArticle();
Mode.sid=Convert.ToInt32(dr["sid"]);
Mode.SubCName = dr["SubCName"].ToString();
Mode.list = GetsubArticleBycid(Convert.ToInt32(dr["cid"]).ToString());
list.Add(Mode);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<SubArticle>>(list);
return xml;
}
else
{
return "非法请求";
}
}
//根据栏目获取文章
//根据栏目获取文章列表
public string GetsubArticleBycid()
{
string code = HttpContext.Current.Request.QueryString["code"];
string cid = HttpContext.Current.Request.QueryString["cid"];
string index = HttpContext.Current.Request.QueryString["index"];
string count = HttpContext.Current.Request.QueryString["count"];
//16位MD5加密wuhansiwen
if (code != null && code.Trim().ToUpper() == "5666DFA2C1D11E39" && cid != null && index != null && count != null)
{
string sql = "select top " + count + " * from subArticle where cid=@cid and articleType=1 and id not in(select top " + index + " id from subArticle where cid=@cid and articleType=1 order by articleTime desc) order by articleTime desc";
SqlParameter[] sqlp = new SqlParameter[] {
new SqlParameter("@cid",cid),
};
List<articleTitleInfo> list = new List<articleTitleInfo>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text, sqlp))
{
while (dr.Read())
{
articleTitleInfo Model = new articleTitleInfo();
Model.articleTitle = dr["articleTitle"].ToString();
Model.id = Convert.ToInt32(dr["id"]);
Model.articleTime = Convert.ToDateTime(dr["articleTime"]);
string[] imgs = GetHtmlImageUrlList(dr["articleContent"].ToString());
if (imgs.Length > 0)
{
if (imgs[0].Trim().Length > 7 && imgs[0].Trim().Substring(0, 7).ToLower() == "http://")
{
Model.imgUrl = imgs[0].Trim();
}
else
{
//处理
string url = HttpContext.Current.Request.Url.AbsoluteUri;
url = url.Substring(0, url.LastIndexOf("webserver"));
string sa = imgs[0].Trim();
if (sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] > 96 && sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] < 123)
{
//不需要转换
Model.imgUrl = url + sa;
}
else
{
Model.imgUrl = url + sa.Substring(sa.IndexOf("/") + 1);
}
}
}
else
{
Model.imgUrl = "";
}
//文字处
string co = StripHT(dr["articleContent"].ToString());
if (co.Trim().Length > 30)
{
co = co.Substring(0, 30);
}
Model.articleContent = co;
list.Add(Model);
}
}
}
catch (Exception)
{ }
string xml = Help.XmlSerialize<List<articleTitleInfo>>(list);
return xml;
}
else
{
return "非法请求";
}
}
//根据栏目获取文章列表
public List<articleTitleInfo> GetsubArticleBycid(string cid)
{
//16位MD5加密wuhansiwen
if (cid != null)
{
string sql = "select * from subArticle where cid=@cid and articleType=1 order by articleTime desc";
SqlParameter[] sqlp = new SqlParameter[] {
new SqlParameter("@cid",cid),
};
List<articleTitleInfo> list = new List<articleTitleInfo>();
try
{
using (SqlDataReader dr = sysSqlHelp.SqlHelp.ExecuteReader(sql, System.Data.CommandType.Text, sqlp))
{
while (dr.Read())
{
articleTitleInfo Model = new articleTitleInfo();
Model.articleTitle = dr["articleTitle"].ToString();
Model.id = Convert.ToInt32(dr["id"]);
Model.articleTime = Convert.ToDateTime(dr["articleTime"]);
string[] imgs = GetHtmlImageUrlList(dr["articleContent"].ToString());
if (imgs.Length > 0)
{
if (imgs[0].Trim().Length > 7 && imgs[0].Trim().Substring(0, 7).ToLower() == "http://")
{
Model.imgUrl = imgs[0].Trim();
}
else
{
//处理
string url = HttpContext.Current.Request.Url.AbsoluteUri;
url = url.Substring(0, url.LastIndexOf("webserver"));
string sa = imgs[0].Trim();
if (sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] > 96 && sa.ToLower().Trim().Substring(0, 1).ToCharArray()[0] < 123)
{
//不需要转换
Model.imgUrl = url + sa;
}
else
{
Model.imgUrl = url + sa.Substring(sa.IndexOf("/") + 1);
}
}
}
else
{
Model.imgUrl = "";
}
//文字处
string co = StripHT(HttpUtility.HtmlDecode(dr["articleContent"].ToString()));
co = co.Replace(" ", "");
if (co.Trim().Length > 60)
{
co = co.Substring(0, 60);
}
Model.articleContent = co;
list.Add(Model);
}
}
}
catch (Exception)
{ }
return list;
}
else
{
return null;
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
2019-03-26
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 3.19-3.25周计划 一、挪威的森林看完。完成情况:看到200页。 二、沉默和老了各看2个小时。完成情况:没看...