", "~", "+", "=", ",", "." )); } $charsLen = count($chars) - 1; shuffle($chars); $str = ''; for ($i = 0; $i < $len; $i++) { $str .= $chars[mt_rand(0, $charsLen)]; } return $str; } public static function multiPasswordVerify($algo, $salt, $password, $hash) { switch($algo) { case 'md5': return md5($password) === $hash; case 'sha256': return hash('sha256', $password) === $hash; case 'md5salt': return md5($password . $salt) === $hash; default: return password_verify($password, $hash); } } public static function emailSuffixVerify($email, $suffixs) { $suffix = preg_split('/@/', $email)[1]; if (!$suffix) return false; if (!is_array($suffixs)) { $suffixs = preg_split('/,/', $suffixs); } if (!in_array($suffix, $suffixs)) return false; return true; } public static function trafficConvert(int $byte) { $kb = 1024; $mb = 1048576; $gb = 1073741824; if ($byte > $gb) { return round($byte / $gb, 2) . ' GB'; } else if ($byte > $mb) { return round($byte / $mb, 2) . ' MB'; } else if ($byte > $kb) { return round($byte / $kb, 2) . ' KB'; } else if ($byte < 0) { return 0; } else { return round($byte, 2) . ' B'; } } public static function getSubscribeUrl(string $token, $subscribeUrl = null) { $path = route('client.subscribe', ['token' => $token], false); if(!$subscribeUrl){ $subscribeUrls = explode(',', admin_setting('subscribe_url')); $subscribeUrl = \Arr::random($subscribeUrls); $subscribeUrl = self::replaceByPattern($subscribeUrl); } return $subscribeUrl ? rtrim($subscribeUrl, '/') . $path : url($path); } public static function randomPort($range): int { $portRange = explode('-', $range); return random_int($portRange[0], $portRange[1]); } public static function base64EncodeUrlSafe($data) { $encoded = base64_encode($data); return str_replace(['+', '/', '='], ['-', '_', ''], $encoded); } /** * 根据规则替换域名中对应的字符串 * * @param string $input 用户输入的字符串 * @return string 替换后的字符串 */ 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) ?: []; } public static function getRandFingerprint() { $fingerprints = ['chrome', 'firefox', 'safari', 'ios', 'edge', 'qq']; return \Arr::random($fingerprints); } }