马上注册,免费下载更多dz插件网资源。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
研究了一个晚上,大家拿去用吧。帝国cms 易优 等php程序都可以用,
- <?php// ========== 配置项 ==========$host = 'www.domain.com'; // 替换为你的域名$apiKey = '你的apikey'; // 替换为你的 Bing IndexNow API Key$logFile = '/www/wwwroot/domain/indexnow_push.log'; // 日志路径(可自定义)// 多个 sitemap 地址(根据你的实际数量增减)$sitemapUrls = [ '你的网址/sitemap/news_6.xml', '你的网址/sitemap/news_5.xml', '你的网址/sitemap/news_4.xml', '你的网址/sitemap/news_3.xml', '你的网址/sitemap/news_2.xml', '你的网址/sitemap/news_1.xml', // 添加更多...];echo "🌐 正在准备解析多个 sitemap 文件...\n";$urlList = [];foreach ($sitemapUrls as $sitemapUrl) { echo "📥 正在下载 sitemap: $sitemapUrl\n"; $xmlContent = @file_get_contents($sitemapUrl); if (!$xmlContent) { echo "⚠️ 无法获取 sitemap 内容: $sitemapUrl\n"; continue; } $xml = simplexml_load_string($xmlContent); if (!$xml) { echo "⚠️ 无法解析 XML 内容: $sitemapUrl\n"; continue; } foreach ($xml->url as $url) { $loc = (string)$url->loc; if (filter_var($loc, FILTER_VALIDATE_URL)) { $urlList[] = $loc; } }}if (empty($urlList)) { echo "⚠️ 没有解析到任何有效的 URL。\n"; file_put_contents($logFile, date("Y-m-d H:i:s") . " - ⚠️ 没有解析到任何有效的 URL。\n", FILE_APPEND); exit;}echo "✅ 共解析到 " . count($urlList) . " 条链接,开始去重...\n";// ========== 去重 & 分批推送(IndexNow 每次最多 10000)==========$uniqueUrls = array_values(array_unique($urlList));$chunks = array_chunk($uniqueUrls, 10000); // 每批最多 10000 条$totalPushed = 0;foreach ($chunks as $index => $chunk) { echo "📤 正在推送第 " . ($index + 1) . " 批 (" . count($chunk) . " 条)...\n"; $payload = [ 'host' => $host, 'key' => $apiKey, 'urlList' => $chunk ]; $ch = curl_init('https://api.indexnow.org/indexnow'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); echo "📡 HTTP 状态码: $httpCode\n"; echo "📦 响应内容: $response\n"; $totalPushed += count($chunk); // 记录日志 $logMsg = sprintf( "批次: %d | 数量: %d | HTTP状态: %d | 响应: %s\n", $index + 1, count($chunk), $httpCode, $response ); file_put_contents($logFile, date("Y-m-d H:i:s") . " - " . $logMsg, FILE_APPEND);}echo "🎉 推送完成,共推送 {$totalPushed} 条链接。\n";
复制代码
©DZ插件网所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 本站内容为站长个人技术研究记录或网络,不提供用户交互功能,所有内容版权归原作者所有。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,得到更好的正版服务。 您在本站任何的赞助购买、下载、查阅、回复等行为等均表示接受并同意签订《DZ插件网免责声明协议》。 如有侵权请邮件与我们联系处理: discuzaddons@vip.qq.com 并出示相关证明以便删除。敬请谅解!
|