feat: Singbox、clash订阅增加绕过服务器地址规则

1、优化订阅下发代码
2、singbox、clash、meta订阅下发增加绕过服务器地址规则,防止重复代理
This commit is contained in:
xboard
2024-07-19 06:29:35 +08:00
parent 3f264c17ba
commit 163d09c71b
5 changed files with 216 additions and 152 deletions
+25 -16
View File
@@ -129,25 +129,34 @@ class Helper
}
/**
* 替换字符串中的 [num1-num2] 格式为介于 num1 和 num2 之间的随机数字
* 根据规则替换域名中对应的字符串
*
* @param string $input 用户输入的字符串
* @return string 替换后的字符串
*/
public static function replaceRandomNumber($input) {
// 匹配 [1-4999] 格式的正则表达式
$pattern = '/\[(\d+)-(\d+)\]/';
// 使用 preg_replace_callback 替换匹配到的内容
$result = preg_replace_callback($pattern, function ($matches) {
// 提取最小和最大值
$min = intval($matches[1]);
$max = intval($matches[2]);
// 生成随机数
$randomNumber = rand($min, $max);
return $randomNumber;
}, $input);
return $result;
public static function replaceByPattern($input)
{
$patterns = [
'/\[(\d+)-(\d+)\]/' => function ($matches) {
$min = intval($matches[1]);
$max = intval($matches[2]);
if ($min > $max) {
list($min, $max) = [$max, $min];
}
$randomNumber = rand($min, $max);
return $randomNumber;
},
'/\[uuid\]/' => function () {
return self::guid(true);
}
];
foreach ($patterns as $pattern => $callback) {
$input = preg_replace_callback($pattern, $callback, $input);
}
return $input;
}
public static function getIpByDomainName($domain) {
return gethostbynamel($domain) ?: [];
}
}