60 lines
1.4 KiB
PHP
60 lines
1.4 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;
|
||
}
|
||
|
||
// 应该是没用上的,按理应该有code和groupcode映射
|
||
public static function getClients()
|
||
{
|
||
$aClients = [
|
||
"clash",
|
||
"v2ray",
|
||
"singbox",
|
||
];
|
||
|
||
return $aClients;
|
||
}
|
||
|
||
public static function clientToExt($sClient)
|
||
{
|
||
switch ($sClient) {
|
||
case "v2ray":
|
||
$sExt = ".txt";
|
||
break;
|
||
case "clash":
|
||
$sExt = ".yaml";
|
||
break;
|
||
default:
|
||
$sExt = ".txt";
|
||
break;
|
||
}
|
||
|
||
return $sExt;
|
||
}
|
||
|
||
}
|