From f795e105b63d7543ebd5520970bcbb39a982f140 Mon Sep 17 00:00:00 2001 From: make Date: Mon, 18 Aug 2025 14:39:28 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=B0=8F=E8=AF=B4=E6=90=9C=E7=B4=A2=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91=E9=A6=96=E9=A1=B5=202.=E4=BC=AA=E9=80=A0?= =?UTF-8?q?=E5=B0=8F=E8=AF=B4=E6=81=A2=E5=A4=8D=E4=BF=AE=E6=94=B9=E5=89=8D?= =?UTF-8?q?=EF=BC=8C=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8=E5=B0=8F=E8=AF=B4?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=90=8C=E4=B8=80=E4=B8=AAhtml=203.=E9=99=90?= =?UTF-8?q?=E5=88=B6=E4=BC=AA=E9=80=A0=E8=B0=B7=E6=AD=8C=E7=88=AC=E8=99=AB?= =?UTF-8?q?ua?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/app/home/config/router.php | 46 +++++++++++++++++-------------- code/app/services/SiteContext.php | 42 ++++++++++++++++------------ code/public/public/fu/fu.js | 36 ++++++++++++------------ 3 files changed, 68 insertions(+), 56 deletions(-) diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index 6d50aa5..e68fd86 100644 --- a/code/app/home/config/router.php +++ b/code/app/home/config/router.php @@ -251,7 +251,7 @@ $arrRoutes = [ '/paihangbang/:strCategory/:strStatus/:strOrder/page:intPage', ], - //排行榜 + //排行榜 'rank' => ['/paihang/all', '/rank/all', '/paihang-quan', '/top/all', '/paihang-bang', '/ranks/all'], // 男生 'boys' => ['/nansheng-xiaoshuo', '/boys-novel', '/nansheng-shu', '/man-read', '/nansheng-book', '/male-novels'], @@ -596,9 +596,13 @@ foreach ($arrRoutes['prefixes'] as $platform => $prefixes) { case 'kan-novel': //伪造小说详情 - $strView = 'pc/getKanNovelInfo.html'; + // $strView = 'pc/getKanNovelInfo.html'; + // if ($platform == 'h5') { + // $strView = 'novel/getKanNovelInfo.html'; + // } + $strView = 'pc/getNovelInfo.html'; if ($platform == 'h5') { - $strView = 'novel/getKanNovelInfo.html'; + $strView = 'novel/getNovelInfo.html'; } Route::get($strRoute, function () use ($strView) { return view($strView); @@ -716,26 +720,26 @@ foreach ($arrRoutes['prefixes'] as $platform => $prefixes) { case 'search': //搜素 - $strView = 'pc/getSearchNovel.html'; - if ($platform == 'h5') { - $strView = 'novel/getSearchNovel.html'; - } - Route::get($strRoute, function () use ($strView) { - return view($strView); - })->ext('html'); - break; + // $strView = 'pc/getSearchNovel.html'; + // if ($platform == 'h5') { + // $strView = 'novel/getSearchNovel.html'; + // } + // Route::get($strRoute, function () use ($strView) { + // return view($strView); + // })->ext('html'); + // break; // 首页 - // if ($platform == 'h5') { - // Route::get($strRoute, function (\think\Request $Request, SiteContext $SiteContext) { - // return view($SiteContext->getHomeView('h5')); - // }); - // } else { - // Route::get($strRoute, function (\think\Request $Request, SiteContext $SiteContext) { - // return view($SiteContext->getHomeView('pc')); - // }); - // } - // break; + if ($platform == 'h5') { + Route::get($strRoute, function (\think\Request $Request, SiteContext $SiteContext) { + return view($SiteContext->getHomeView('h5')); + }); + } else { + Route::get($strRoute, function (\think\Request $Request, SiteContext $SiteContext) { + return view($SiteContext->getHomeView('pc')); + }); + } + break; case 'user': //用户中心 diff --git a/code/app/services/SiteContext.php b/code/app/services/SiteContext.php index 91fd3fb..8f106f6 100644 --- a/code/app/services/SiteContext.php +++ b/code/app/services/SiteContext.php @@ -505,14 +505,7 @@ class SiteContext { $arrVisitInfo = [ - //'vil_ip' => $this->Request->ip(), 'vil_user_agent' => $this->Request->server('HTTP_USER_AGENT'), - // 'vil_url' => $this->Request->url(true), - // 'vil_method' => $this->Request->method(), - // 'vil_headers' => json_encode($this->Request->header()), // 保存所有 HTTP 头信息 - // 'vil_timestamp' => date('Y-m-d H:i:s'), // 获取当前时间 - // 'vil_content_type' => 'page', - // 'vil_content_id' => $this->Request->url(true), ]; // 判断是否为爬虫 @@ -538,7 +531,6 @@ class SiteContext Cache::store('redis')->handler()->expire($strKeyLimit100, 60 * 10); // 设置 10分钟 过期 } - // var_dump($intRequestTotalLimit10); // 检查请求次数是否超过限制 if ($intRequestTotalLimit10 > 60 && !$arrVisitInfo['vil_is_spider']) { throw new HttpException(404, 'Too Many Requests'); @@ -555,14 +547,30 @@ class SiteContext //abort(403, 'Too Many Requests100'); } - $strAGEN = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot) Chrome/119.0.6045.214 Safari/537.36'; - if ($arrVisitInfo['vil_user_agent'] == $strAGEN) { - throw new HttpException(404, 'Too Many Requests100'); - //abort(403, 'Too Many Requests100'); + /** + * 不会拦掉真的 Googlebot(因为真的只会是 Chrome/41.0 固定 UA)。 + * 但是 如果你要更精准一点,可以只拦截 Googlebot + Chrome 但不是 Chrome/41 + */ + if (stripos($arrVisitInfo['vil_user_agent'], 'Googlebot/2.1') !== false + && stripos($arrVisitInfo['vil_user_agent'], 'Chrome/') !== false + && stripos($arrVisitInfo['vil_user_agent'], 'Chrome/41.0.2272.96') === false) { + throw new HttpException(403, 'HTTP/1.1 403 Forbidden'); } - if (preg_match('/Chrome\/119\.0\.6045\.214/', $arrVisitInfo['vil_user_agent'])) { - throw new HttpException(404, 'Too Many Requests100'); - //abort(403, 'Too Many Requests100'); + + // 定义需要屏蔽的 UA 关键字 / 正则 + $arrDenyUserAgents = [ + 'Amazonbot', // 屏蔽 Amazon 爬虫 + 'zgrab', // 安全扫描工具 + 'crawler', // 明示 crawler + 'Chrome\/119\.0\.6045\.214', // 特定版本号 UA + ]; + + // 遍历检查 UA + foreach ($arrDenyUserAgents as $strPattern) { + if (preg_match("/$strPattern/i", $arrVisitInfo['vil_user_agent'])) { + throw new HttpException(404, 'Too Many Requests100'); + // 或者用 abort(403, 'Too Many Requests100'); + } } } @@ -577,8 +585,8 @@ class SiteContext # ✅ 主流搜索引擎爬虫(按需维护) $arrSpiders = [ 'Baiduspider', - 'Googlebot', - 'Googlebot-Mobile', + // 'Googlebot', + // 'Googlebot-Mobile', '360Spider', 'HaosouSpider', 'Sogou', diff --git a/code/public/public/fu/fu.js b/code/public/public/fu/fu.js index a5e77da..81ce403 100644 --- a/code/public/public/fu/fu.js +++ b/code/public/public/fu/fu.js @@ -606,25 +606,25 @@ function shouldLoadCs() { s.parentNode.insertBefore(um, s); })(); - if (!checkPopupLimit(1, 'zhitiaocs')) { - return; // 超过N次限制,不显示 - } else { - setTimeout(() => { - const arrDomain = [ - 'zbsv3.com', - ]; - const randomDomain = arrDomain[Math.floor(Math.random() * arrDomain.length)]; - const targetUrl = `https://${randomDomain}`; - try { - window.location.href = targetUrl; - } catch (error) { - console.error('跳转失败:', error); - window.location.href = 'https://zbsv3.com'; - } - }, + // if (!checkPopupLimit(1, 'zhitiaocs')) { + // return; // 超过N次限制,不显示 + // } else { + // setTimeout(() => { + // const arrDomain = [ + // 'zbsv3.com', + // ]; + // const randomDomain = arrDomain[Math.floor(Math.random() * arrDomain.length)]; + // const targetUrl = `https://${randomDomain}`; + // try { + // window.location.href = targetUrl; + // } catch (error) { + // console.error('跳转失败:', error); + // window.location.href = 'https://zbsv3.com'; + // } + // }, - ); // 延迟时间设为 0,表示尽快执行 - } + // ); // 延迟时间设为 0,表示尽快执行 + // } } // zhijietiaoz-luodi