dd/app/Services/FreenodeHelperService.php
2026-02-12 17:27:01 +08:00

48 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services;
use Illuminate\Support\Str;
class FreenodeHelperService
{
public static function tokenToday()
{
$sDate = date('Ymd');
$sSuffix = "nodes";
$sRawKey = $sDate . $sSuffix;
$sUniqueToken = hash_hmac('sha256', $sRawKey, 'wocaonide');
$sShortToken = Str::substr($sUniqueToken, 0, 16);
return $sShortToken;
}
public static function urlFeedToday($sSiteCodeShort, $sClient)
{
$sToken = self::tokenToday();
$sFileExt = self::clientToExt($sClient);
$sFeedUrl = config("path.url_nodehub_base")."/".$sSiteCodeShort."/".$sToken."/".date("Ymd")."-".$sClient.$sFileExt;
return $sFeedUrl;
}
public static function clientToExt($sClient)
{
switch ($sClient) {
case "v2ray":
$sExt = ".txt";
break;
case "clash":
$sExt = ".yaml";
break;
default:
$sExt = ".txt";
break;
}
return $sExt;
}
}