废话不多说直接上代码 dtcms交流群 464033697
1,新增推送方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTcms.Common
{
/// <summary>
/// 百度相关类
/// </summary>
public class BaiDu
{
/// <summary>
/// 推送链接至百度
/// </summary>
/// <param name="urls">链接集合</param>
/// <returns></returns>
public static string sendUrlToBaidu(string[] urls)
{
try
{
string formUrl = "http://data.zz.baidu.com/urls?site=www.luyixian.cn&token=youToken";
string formData = "";
foreach (string url in urls)
{
formData += url + "\n";
}
byte[] postData = System.Text.Encoding.UTF8.GetBytes(formData);
// 设置提交的相关参数
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(formUrl) as System.Net.HttpWebRequest;
System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
request.Method = "POST";
request.KeepAlive = false;
request.AllowAutoRedirect = true;
request.ContentType = "text/plain";
request.UserAgent = "curl/7.12.1";
request.ContentLength = postData.Length;
// 提交请求数据
System.IO.Stream outputStream = request.GetRequestStream();
outputStream.Write(postData, 0, postData.Length);
outputStream.Close();
System.Net.HttpWebResponse response;
System.IO.Stream responseStream;
System.IO.StreamReader reader;
string srcString;
response = request.GetResponse() as System.Net.HttpWebResponse;
responseStream = response.GetResponseStream();
reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("UTF-8"));
srcString = reader.ReadToEnd();
string result = srcString; //返回值赋值
reader.Close();
return result;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
2,新增文章返回文章id
articleid = bll.Add(model);
if (articleid > 0)
{
AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加" + this.channel_name + "频道内容:" + model.title); //记录日志
}
return articleid;
3,新增文章成功之后生成url链接调用推送方法推送给百度
//获取频道模板名称
string channelTemp = new BLL.channel().GetModel(this.channel_id).name.ToString();
string articleUrl = new BasePage().linkurl(channelTemp + "_show", articleid);
string[] url=new string[100];
url[1] = "http://www.luyixian.cn"+articleUrl;
string info = DTcms.Common.BaiDu.sendUrlToBaidu(url);
//string info = sendUrlToBaidu(new string[] { "http://www.luyixian.cn/down/show-261.aspx", "http://www.luyixian.cn/index.aspx"};
JscriptMsg("添加信息成功!", "article_list.aspx?channel_id=" + this.channel_id);
ok看看你返回的推送代码是否推送给了百度
共有条评论 网友评论