
废话不多说直接代码
<!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>后端代码