Web site automatically push Baidu API source code (PHP source code)


<?php
//baidu push api
//https://ziyuan.baidu.com/linksubmit/index 这里提供的 api 接口,普通收录,主动提交,php代码
$api = 'http://data.zz.baidu.com/urls?site=网址&token=秘钥';
 
 
//get site urls
function GetUrls($api):string{
    $site = "网站地图";
    //获取 xml 信息
    $XmlUrls = curl($site,null);
    //将 xml 转为数组
    $resource = xml_parser_create();
    xml_parse_into_struct($resource,$XmlUrls,$value,$index);
    xml_parser_free($resource);

    //$urlArr 即为接受所有 url 的数组
    $urlArr = [];
    foreach ($value as $content){
        if ($content["tag"] === "LOC"){
            $urlArr[] = $content["value"];
        }
 
    }
    //开始上传
    $response = curl($api,$urlArr,1);
    //将响应 json 转为 对象
    $result = json_decode($response);
    if ($result->success != 0){
        return "主动提交成功!";
    }else{
        return  "主动提交失败!";
    }
}
 
function curl($url,$params,$is_post = 0){
    $ch = curl_init();
 
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,60);
    curl_setopt($ch,CURLOPT_TIMEOUT,60);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);//禁止验证对等证书,默认为true
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//检查服务器SSL证书中是否存在一个公用名,值0|2,
    if($is_post){
        curl_setopt($ch,CURLOPT_POST,true);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
        curl_setopt($ch,CURLOPT_URL,$url);
    }else{
        if($params){
            curl_setopt($ch,CURLOPT_URL,$url.'?'.$params);
        }else{
            curl_setopt($ch,CURLOPT_URL,$url);
        }
    }
    $response = curl_exec($ch);
    return $response;
}
echo GetUrls($api);

Web site automatically push Baidu API source code (PHP source code)

Peng Yue (1938-), Taiwanese calligrapher

SEO front-runner, has been responsible for the daily IP of more than a million large-scale site. Seo optimisation has been done in domestic Baidu, Bing, 360 and other search engines, and now open Google, Bing overseas, Yandex and other overseas search engine optimisation study and research.

Recommended

SEO Methodology (seo from beginner to master)

  从事 SEO 行业多年,从刚开始的 SEO 编辑到现在操盘多个业务/网站,我想梳理下自己的 SEO 方法论,给刚入行的同学提供一些参考,也当作自己的一个总结。 注:我主要是做大型网站 SEO 这个方向,不一定适用于其 ...

Google Seo Tools

网站SEO分析工具 1.GoogleWebmasterTools:网站管理监测工具    2.GoogleAnalytics:网站流量监测工具    3.Botify:站点审核工具    4.BrightLocal:本化SEO监测工具    5.AdsPower:谷歌账号安全工具,可开多个账号 ...

How to Install Google Analytics 4 with GTM

Google Tag Manager(谷歌代码管理器)又称GTM,是一款非常方便我们工作的工具,只需在网页中插入一次GTM代码,你就可以在GTM中创建无数个追踪代码,刚好最近有个网站新上线,芃越使用GTM安装GA4,今天便记录一 ...

en_AUEnglish (Australia)