网站首页 >> 源码 >> 正文
标题

百度API网站推送提交源码

逍遥   12月23日 19:36   11℃   0
内容

百度API网站推送提交源码,image.png,百度API推送,第1张

1. 环境要求

  • 服务器 / 本地需安装 PHP 7.0+(推荐 7.4/8.0);

  • PHP 启用 cURL 扩展(绝大部分主机默认启用,若未启用参考下方「常见问题」);

  • 有可访问的 Web 服务器(Apache/Nginx/PHP 内置服务器均可)。

2. 部署步骤

  1. 将 bAIdu_push.html 和 baidu_push_api.php 上传到同一 Web 目录(如:wwwroot/baidu_push/);

  2. 登录「百度站长平台」:

    • 添加并验证你的站点(文件验证 / CNAME 验证 / HTML 标签验证);

    • 进入「链接提交 → 主动推送」,复制你的专属 Token;

  3. 打开浏览器 ,访问 http://你的域名/baidu_push/baidu_push.html

  4. 填写参数:

    • Token:粘贴百度站长平台复制的 Token;

    • 站点域名:填写已验证的域名(如 https://www.example.com);

    • URL 列表:粘贴待推送的 URL(每行一个,可批量粘贴);

  5. 点击「提交推送」,等待页面显示推送结果 。

三、关键注意事项

  1. Token 有效性:Token 与站点一一对应 ,若更换站点需重新获取 Token;

  2. 域名一致性:填写的域名必须与百度验证的域名完全一致(如验证的是https://www.example.com,则不能填http://example.com);

  3. URL 规范

    • 必须是完整 URL(包含http/https);

    • 必须属于填写的站点域名;

    • 单次最多 2000 条,每日默认额度 10 万条;

  4. 安全建议

    • 生产环境可给工具加密码验证(避免他人滥用你的 Token);

    • 不要将 Token 泄露给无关人员;

  5. 重复推送:百度 API 会自动过滤已推送的 URL ,重复推送不影响额度。

废话不多说直接代码

<!DOCTYPE html> <html> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>百度链接主动推送工具</title>     <style>         * {             margin: 0;             padding: 0;             box-sizing: border-box;             font-family: "Microsoft Yahei", sans-serif;         }         body {             background-color: #f5f7fa;             padding: 20px 0;         }         .container {             max-width: 800px;             margin: 0 auto;             padding: 30px;             background: #fff;             border-radius: 12px;             box-shadow: 0 2px 20px rgba(0,0,0,0.08);         }         h1 {             text-align: center;             color: #2d3748;             margin-bottom: 30px;             font-size: 24px;         }         .form-group {             margin-bottom: 25px;         }         label {             display: block;             margin-bottom: 10px;             font-weight: 600;             color: #4a5568;             font-size: 15px;         }         input[type="text"], textarea {             width: 100%;             padding: 12px 15px;             border: 1px solid #e2e8f0;             border-radius: 6px;             font-size: 14px;             resize: vertical;             transition: border-color 0.3s;         }         input[type="text"]:focus, textarea:focus {             outline: none;             border-color: #2f54eb;             box-shadow: 0 0 0 3px rgba(47, 84, 235, 0.1);         }         textarea {             min-height: 220px;             line-height: 1.6;             white-space: pre-wrap;         }         button {             display: block;             width: 100%;             padding: 14px;             background-color: #2f54eb;             color: white;             border: none;             border-radius: 6px;             font-size: 16px;             cursor: pointer;             transition: background-color 0.3s;         }         button:hover {             background-color: #1d39c4;         }         button:disabled {             background-color: #94a3b8;             cursor: not-allowed;         }         .result {             margin-top: 30px;             padding: 20px;             border-radius: 6px;             display: none;             font-size: 14px;             line-height: 1.8;         }         .success {             background-color: #f0f9ff;             border: 1px solid #bae6fd;             color: #0369a1;         }         .error {             background-color: #fef2f2;             border: 1px solid #fecdd3;             color: #b91c1c;         }         .tips {             font-size: 12px;             color: #94a3b8;             margin-top: 8px;             line-height: 1.5;         }         .url-count {             text-align: right;             font-size: 12px;             color: #64748b;             margin-top: 5px;         }     </style> </head> <body>     <div>         <h1>百度链接主动推送工具</h1>                  <div>             <label for="token">百度站长Token</label>             <input type="text" id="token" placeholder="从「百度站长平台→链接提交→主动推送」复制Token">             <div>Token是站点专属密钥,请勿泄露给他人</div>         </div>                  <div>             <label for="domain">站点域名</label>             <input type="text" id="domain" placeholder="示例:https://www.yourdomain.com(需与百度验证域名一致)">             <div>必须包含http/https,且与百度站长平台验证的域名完全一致</div>         </div>                  <div>             <label for="urls">待推送URL列表(每行一个)</label>             <textarea id="urls" placeholder="https://www.yourdomain.com/index.html https://www.yourdomain.com/article/1.html https://www.yourdomain.com/article/2.html"></textarea>             <div id="urlCount">当前URL数量:0</div>             <div>单次最多推送2000条	,URL必须属于上述站点域名,重复URL不影响推送结果</div>         </div>                  <button id="submitBtn">提交推送</button>                  <div id="result"></div>     </div>     <script>         // 实时统计URL数量         const urlsTextarea = document.getElementById('urls');         const urlCountDom = document.getElementById('urlCount');         urlsTextarea.addEventListener('input', function() {             const urlList = this.value.trim().split('\n').map(url => url.trim()).filter(url => url);             urlCountDom.innerText = `当前URL数量:${urlList.length}`;         });         // 提交按钮点击事件         document.getElementById('submitBtn').addEventListener('click', async function() {             const token = document.getElementById('token').value.trim();             const domain = document.getElementById('domain').value.trim();             const urlsText = document.getElementById('urls').value.trim();             const resultDom = document.getElementById('result');                          // 清空结果区域             resultDom.style.display = 'none';             resultDom.className = 'result';                          // 前端参数校验             if (!token) {                 showResult('error', '❌ 请输入百度站长Token!');                 return;             }             if (!domain || !/^https?:\/\/[a-zA-Z0-9\-_.]+(:\d+)?\/?$/.test(domain)) {                 showResult('error', '❌ 请输入有效的站点域名(如:https://www.example.com)!');                 return;             }             if (!urlsText) {                 showResult('error', '❌ 请输入待推送的URL列表!');                 return;             }                          // 拆分URL列表(按行拆分,过滤空行)             const urlList = urlsText.split('\n').map(url => url.trim()).filter(url => url);             if (urlList.length > 2000) {                 showResult('error', '❌ 单次推送URL数量不能超过2000条	,请删减后重试!');                 return;             }                          // 禁用按钮,防止重复提交             this.disabled = true;             this.innerText = '推送中... 🚀';                          try {                 // 调用后端PHP接口                 const response = await fetch('baidu_push_api.php', {                     method: 'POST',                     headers: {                         'Content-Type': 'application/json',                     },                     body: JSON.stringify({                         token: token,                         domain: domain,                         urls: urlList                     })                 });                                  // 处理非JSON响应                 if (!response.ok) {                     throw new Error(`HTTP请求失败,状态码:${response.status}`);                 }                                  const result = await response.json();                                  // 展示结果                 if (result.status === 'success') {                     const data = result.data;                     showResult('success', ` ✅ 推送成功!<br> ├─ HTTP状态码:${result.code}<br> ├─ 成功推送数量:${data.success || 0}<br> ├─ 当日剩余推送额度:${data.remain || 0}<br> └─ 错误数量:${data.error || 0}                     `);                 } else {                     showResult('error', `❌ 推送失败:${result.msg}`);                 }             } catch (e) {                 showResult('error', `❌ 请求异常:${e.message}`);             } finally {                 // 恢复按钮状态                 this.disabled = false;                 this.innerText = '提交推送';             }         });                  // 展示结果的辅助函数         function showResult(type, msg) {             const resultDom = document.getElementById('result');             resultDom.className = `result ${type}`;             resultDom.innerHTML = msg.replace(/\n/g, '<br>');             resultDom.style.display = 'block';             // 滚动到结果区域             resultDom.scrollIntoView({ behavior: 'smooth' });         }         // 初始化URL数量统计         urlsTextarea.dispatchEvent(new Event('input'));     </script> </body> </html>

后端代码

支付5元,才能查看本内容!立即支付
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
随机标签