修复判断入口文件ip_check.php以及新增复制配置选项

This commit is contained in:
root
2026-06-15 16:53:05 +08:00
parent 8f46a4c1c4
commit 1a52201ec7
23 changed files with 969 additions and 35 deletions
+23 -3
View File
@@ -2,6 +2,8 @@
/**
* IP → 国家码跨请求缓存(Redis 优先,文件降级,默认 TTL 30 天)
*/
require_once __DIR__ . '/CountryCodeNormalizer.php';
class GeoIpCountryCache
{
const REDIS_PREFIX = 'cloak:geoip:cc:';
@@ -28,7 +30,7 @@ class GeoIpCountryCache
if ($value === false || $value === null) {
return false;
}
return $value === self::NONE_SENTINEL ? null : (string) $value;
return self::normalizeCachedValue($value === self::NONE_SENTINEL ? null : (string) $value);
} catch (Throwable $e) {
self::logError('Redis get failed: ' . $e->getMessage());
}
@@ -48,7 +50,12 @@ class GeoIpCountryCache
return;
}
$value = $countryCode !== null && $countryCode !== '' ? strtoupper($countryCode) : self::NONE_SENTINEL;
if ($countryCode !== null && $countryCode !== '') {
$normalized = CountryCodeNormalizer::toAlpha2($countryCode);
$value = $normalized !== null ? $normalized : strtoupper($countryCode);
} else {
$value = self::NONE_SENTINEL;
}
$ttl = self::cacheTtl();
$redis = self::redisClient();
@@ -137,7 +144,20 @@ class GeoIpCountryCache
@unlink($path);
return false;
}
return $data['value'] === self::NONE_SENTINEL ? null : (string) $data['value'];
return self::normalizeCachedValue($data['value'] === self::NONE_SENTINEL ? null : (string) $data['value']);
}
/**
* @param string|null $value
* @return string|null
*/
private static function normalizeCachedValue($value)
{
if ($value === null || $value === '') {
return null;
}
$normalized = CountryCodeNormalizer::toAlpha2($value);
return $normalized !== null ? $normalized : strtoupper((string) $value);
}
/**