推送接口
接口调用地址: http://data.zz.baidu.com/urls?site=www.zhongyf.com&token=百度申请到的
| 参数名称 | 是否必选 | 参数类型 | 说明 |
|---|---|---|---|
| site | 是 | string | 在搜索资源平台验证的站点,比如www.example.com |
| token | 是 | string | 在搜索资源平台申请的推送用的准入密钥 |
推送代码
$urls = array(
'http://www.example.com/1.html',
'http://www.example.com/2.html',
);
$api = 'http://data.zz.baidu.com/urls?site=www.zhongyf.com&token=f788888UKFXnbHaikU';
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;推送成功反馈
状态码为200,可能返回以下字段:
字段 是否必选 参数类型 说明 success 是 int 成功推送的url条数 remain 是 int 当天剩余的可推送url条数 not_same_site 否 array 由于不是本站url而未处理的url列表 not_valid 否 array 不合法的url列表
推送失败后反馈
状态码为4xx,返回字段有:
| 字段 | 是否必传 | 类型 | 说明 |
|---|---|---|---|
| error | 是 | int | 错误码,与状态码相同 |
| message | 是 | string | 错误描述 |
失败返回示例:
{
"error":401,
"message":"token is not valid"
} js代码推送:
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>