Table of Contents
百度实时推送api接口应用示例,api示例
API接口怎使用?
百度sitemapPost推送示例怎使用
Home php教程 php手册 百度实时推送api接口应用示例,api示例

百度实时推送api接口应用示例,api示例

Jun 13, 2016 am 09:23 AM
api interface real time push Baidu

百度实时推送api接口应用示例,api示例

网站质量不错的网站可以在百度站长平台/数据提交/sitemap栏目下看到实时推送的功能, 目前这个工具是邀请开放, 百度的实时推送的api接口可以实时推送我们新发布的文章, 保证百度在第一时间收录.
 
百度站长平台 http://zhanzhang.baidu.com/


打开百度站长平台, 点开实时推送的添加新数据接口获得带token的api推送地址:
 
  http://ping.baidu.com/sitemap?site=www.yourdomain.com&resource_name=sitemap&access_token=xxxxxxx 
 

分享一段网友写的php实时推送代码: 

php 实时推送新发布的文章

socketopen方式推送sitemap

复制代码 代码如下:


 function sitemap_ping_baidu($urls){
         $baidu_ping_url = 'ping.baidu.com';
         $get = '/sitemap?site=www.yourdomain.com&resource_name=sitemap&access_token=xxxxxxx';
         $port=80;
         if ( ( $io = fsockopen( $baidu_ping_url, $port, $errno, $errstr, 50 ) ) !== false )  {
             $send = "POST $get HTTP/1.1"."rn";
             $send .= 'Accept: */*'."rn";
             $send .= 'Cache-Control: no-cache'."rn";
 
           $send .= 'Host: '.$baidu_ping_url."rn";
           $send .= 'Pragma: no-cache'."rn";
           //$send .= "Referer: http://".$url.$get."rn";
           //$send .= 'User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'."rn";
           
           $xml = '';
           foreach($urls as $url){
               $xml .= '';
               $xml .= '';
               $xml .= ''.date('Y-m-d').'';
               $xml .= 'monthly';
               $xml .= '0.8';
               $xml .= '
';
           }
           $xml .= '
';

           $send .= 'Content-Length:'.strlen($xml)."rn";
           $send .= "Connection: Closernrn";

           $send .= $xml."rn";

           fputs ( $io, $send );

           $return = '';
           while ( ! feof ( $io ) )
           {
               $return .= fread ( $io, 4096 );
           }
           return $return;
       }else{
           return false;
       }
   }
$return = sitemap_ping_baidu(array('http://www.yourdomain.com/a.php?id=1'));


推送后百度会返回的xml文档

复制代码 代码如下:


 
    
        
            
                
                     200
                

            
        
     
    

状态码含义如下

200 无使用方式错误,需要进一步观察返回的内容是否正确
400 必选参数未提供
405 不支持的请求方式,我们只支持POST方式提交数据
411 HTTP头中缺少Content-Length字段
413 推送的数据过大,超过了10MB的限制
422 HTTP头中Content-Length声明的长度和实际发送的数据长度不一致
500 站长平台服务器内部错误

API接口怎使用?

您这个问题太粗狂了,不同的API接口,提供的调用与使用的方式会不一样。一般的情况下,提供API者会提供对应的说明和示例。
 

百度sitemapPost推送示例怎使用

具备了开发者账号后就进入百度开放云平台,下面的这个网址是开发指南:developer.baidu.com/...qq.c2c。原则上说是可以根据这个指南就可以成功运行百度提供的示例程序,但是个人感觉说得不够详细,我就自己的经历写下如下步骤。
当进入如上的网站后,点击右上角的登录,成功后就后在右上角显示管理控制台。点击管理控制台进入轻应用管理,再点击如图的箭头就可以显示如图1.1 移动应用管理分类,点击移动应用管理进入应用管理。
点击进入如下界面,填写应用名称,例如推送测试2,点击保存。

点击管理控制台进入轻应用管理,再点击如图的箭头就可以显示如图1.1 移动应用管理分类,点击开发者服务管理进入图1.4,其中的推送测试2就是刚才新建的。

图1.4 开发者服务管理
点击推送测试2进入图1.5中记录红圈ID,后面会写入到程序中。

图1.5基本信息
package="com.baidu.push.example"

图1.6 推送设置
在这里第一次使用的时候可能不知道应用包名是什么,那就先来介绍百度云推送的SDK。从该网址下载android版本的客户端SDK包及应用Demo:developer.baidu.com/...entsdk 。 下面并解压包目录如下\Baidu-Push-SDK-Android-L2-3.2.0\Demo,将Demo导入到eclipse中。如果出现编
译报就将编码改成UTF-8的,一般就不会报错了。这样把示例程序运行到手机中,会发现程序接收不到百度云在推送。是因为还要修改mainfest.xml中在api_key的值就是刚才推送测试2中基本信息API key见图1.5中的红圈。我的修改如下:
再次运行就可以接收百度云推送的消息了。下一节介绍详细测试过程。
手机上运行pushdemo软件,进入百度云开发者服务管理,在工程名称中选择刚才的推送测试2。点击左边的云推送如图1.7;
点击通知,进入如下图1.8,在标题和消息内容中填写相关内容,最后也是最关键的时候到了,最好将pushdemo运行到后台或者说退出,这样你才能更加形象的感受到推送功能,好了点击图中的发送,大概1秒的时间,你就会听到声音,说明你收到了推送,如图1.9测试结果,这个消息和图1.8中的内容不对应,因为结果是我第二天。关于消息和媒体的测试我这就不说了,我测试过要可以的。
 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

After 2 months, the humanoid robot Walker S can fold clothes After 2 months, the humanoid robot Walker S can fold clothes Apr 03, 2024 am 08:01 AM

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

What is the API interface for? What is the API interface for? Apr 23, 2024 pm 01:51 PM

An API interface is a specification for interaction between software components and is used to implement communication and data exchange between different applications or systems. The API interface acts as a "translator", converting the developer's instructions into computer language so that the applications can work together. Its advantages include convenient data sharing, simplified development, improved performance, enhanced security, improved productivity and interoperability.

Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Jun 04, 2024 pm 08:01 PM

On May 15, Baidu Apollo held Apollo Day 2024 in Wuhan Baidu Luobo Automobile Robot Zhixing Valley, comprehensively demonstrating Baidu's major progress in autonomous driving over the past ten years, bringing technological leaps based on large models and a new definition of passenger safety. With the world's largest autonomous vehicle operation network, Baidu has made autonomous driving safer than human driving. Thanks to this, safer, more comfortable, green and low-carbon travel methods are turning from ideal to reality. Wang Yunpeng, vice president of Baidu Group and president of the Intelligent Driving Business Group, said on the spot: "Our original intention to build autonomous vehicles is to satisfy people's growing yearning for better travel. People's satisfaction is our driving force. Because safety, So beautiful, we are happy to see

What are the main types of api interfaces? What are the main types of api interfaces? Apr 23, 2024 pm 01:57 PM

API interface types are rich and diverse, including RESTful API, SOAP API, GraphQL API, etc. RESTful API communicates through the HTTP protocol, with a simple and efficient design, which is the current mainstream Web API design style. SOAP API is based on XML, focuses on cross-language and platform interoperability, and is mostly used in large enterprises and government agencies. GraphQL API is a new query language and runtime environment that supports flexible data query and response.

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

Introduction to how to obtain Baidu Xiyang Shells Introduction to how to obtain Baidu Xiyang Shells Mar 28, 2024 am 09:11 AM

There are many users in Xirang who don’t know where the shells are and how to get them. Some players have been searching for several hours but still can’t find them. Below, the editor will introduce how to obtain Baidu Xirang shells. Come and take a look. . How to get Baidu Xirang Shell 1. First we need to come to the community, and then come to the location in the picture below. 2. Select the destination here and choose to enter the 188th floor. 3. After entering the 188th floor, you will see this prompt when walking around. Just click I Got It. 4. The location of the shell may be a little difficult to find. Just behind the 188 elevator, there is a small glowing dot that is the shell. 5. You need to use a VR controller to pick up shells. Just click on the shell. Redemption method 1. First click the "Settings" icon in the upper right corner of the page and select "

Baidu Robin Li led a team to visit PetroChina to discuss the intelligence of the oil and gas industry Baidu Robin Li led a team to visit PetroChina to discuss the intelligence of the oil and gas industry May 07, 2024 pm 06:13 PM

According to news from this site on May 7, on May 6, Robin Li, founder, chairman and CEO of Baidu, led a team to visit China National Petroleum Corporation (hereinafter referred to as "PetroChina") in Beijing and met with directors of China National Petroleum Corporation Chairman and Party Secretary Dai Houliang held talks. The two parties had in-depth exchanges on strengthening cooperation and promoting the deep integration of the energy industry with digital intelligence. PetroChina will accelerate the construction of a digital China Petroleum Corporation, strengthen cooperation with Baidu Group, promote the in-depth integration of the energy industry with digital intelligence, and make greater contributions to ensuring national energy security. Robin Li said that the "intelligent emergence" and core capabilities of understanding, generation, logic, and memory displayed by large models have opened up a broader space for imagination for the combination of cutting-edge technology and oil and gas business. Always

It is reported that the Chinese version of Samsung Galaxy S24 series mobile phone 'Search in Circle” will support Google search It is reported that the Chinese version of Samsung Galaxy S24 series mobile phone 'Search in Circle” will support Google search Jun 01, 2024 am 09:54 AM

According to news on May 31, blogger @ibinguniverse broke the news today that the Chinese version of Samsung Galaxy S24 series mobile phones will support Google search. The blogger did not disclose the specific launch time. According to Samsung’s previous introduction, the Samsung Galaxy S24 series has been equipped with many high-level AI capabilities, AI-based practical functions such as input, translation, recorder, notes, and cameras, to provide users with a more convenient and efficient comprehensive experience. Different from the overseas version, most of the AI ​​functions of the Samsung Galaxy S24 series are provided by domestic manufacturers, such as Baidu. Previously reported, Galaxy AI deeply integrates multiple capabilities of Baidu Wenxin large model, which can provide end-side enabled call and translation functions, as well as intelligent summary brought by generative AI.

See all articles