百度新出了一个熊掌号,有点类似今日头条的头条号,不同之处在于熊掌号支持直接把网站内容改造一下,放在熊掌号上(无需公司,门槛很低),首先需要将页面进行改造,按照熊掌号的指导,分别进行粉丝改造,结构化改造,验证成功后就可以进行资源提交。粉丝改造按照提示,加入两条脚本就可以了。结构化改造也不难,需要加在页面中加入一条json数据。示例图下:
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "https://ziyuan.baidu.com/college/articleinfo?id=1464",
"appid": "1590526829403072",
"title": "百度移动搜索落地页体验白皮书——广告篇2.0",
"images": [
"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png",
"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png",
"https://m.baidu.com/static/index/plus/plus_logo.png"
],
"description": "优质合理的广告作为信息的补充,广受用户喜欢。2017年初百度用户体验部针对用户进行了满意度调研,发现很多恶意低质的广告严重破坏着用户的搜索体验。",
"pubDate": "2017-06-15T08:00:01",
"upDate": "2017-06-16T01:02:03",
"lrDate": "2017-06-17T09:10:11"
}
</script>
json其中每一项在熊掌号都有详细说明,下面是我的实际应用(省略了一些项),自动绑定后台对应字段就可以了。
<script type="application/ld+json">
{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "<%=blogUrl%>",
"appid": "1590*****03072",
"title": "<%=blogTitle%>",
"images": [
"<%=blogImage%>"
],
"pubDate": "<%=blogTime%>"
}
</script>
其中时间格式有点问题,需要处理一下:
blogTime = reader.GetDateTime(2).ToString("yyyy-MM-ddThh:mm:ss"); //格式为DateTime
改造完成后就是自动提交了,下面是我来说一下自动提交Post资源的代码。在第一次写文章的时候调用Post,目前feedback通过邮件发送到邮箱查看。
public static string PostUrl(string url) { string result = ""; try { string BaiduUrl = "http://data.zz.baidu.com/urls?appid=159*****03072&token=gjUzg******&type=realtime"; byte[] postData = System.Text.Encoding.UTF8.GetBytes(url); // 设置提交的相关参数 HttpWebRequest request = WebRequest.Create(BaiduUrl) as HttpWebRequest; Encoding myEncoding = 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; // 提交请求数据 Stream outputStream = request.GetRequestStream(); outputStream.Write(postData, 0, postData.Length); outputStream.Close(); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream myResponseStream = response.GetResponseStream(); using (StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8)) { result = myStreamReader.ReadToEnd(); } } } catch (Exception ex) { return ex.Message; } return result; }