97 lines
2.6 KiB
PHP
Executable File
97 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
use App\Models\FreenodePool;
|
|
use App\Services\Freenode\Pipeline;
|
|
use RuntimeException;
|
|
|
|
final class CountrySpeedService
|
|
{
|
|
static $aCountry = [
|
|
"美国",
|
|
"美国",
|
|
"日本",
|
|
"日本",
|
|
"新加坡",
|
|
"新加坡",
|
|
"香港",
|
|
"香港",
|
|
"台湾",
|
|
"台湾",
|
|
"越南",
|
|
"越南",
|
|
"俄罗斯",
|
|
"新西兰",
|
|
"瑞士",
|
|
"荷兰",
|
|
"冰岛",
|
|
"爱尔兰",
|
|
"乌克兰",
|
|
"泰国",
|
|
"阿根廷",
|
|
"葡萄牙",
|
|
"美国",
|
|
"日本",
|
|
"新加坡",
|
|
"台湾",
|
|
"香港",
|
|
"韩国",
|
|
"德国",
|
|
"土耳其",
|
|
"法国",
|
|
"加拿大",
|
|
"加拿大",
|
|
];
|
|
|
|
|
|
public static function fn_b()
|
|
{
|
|
//// 地区
|
|
$iCountryLimit = rand(5, 12);
|
|
$aCountryKey = array_rand(self::$aCountry, $iCountryLimit);
|
|
|
|
$aCountry = [];
|
|
foreach ($aCountryKey as $sCountryKey) {
|
|
$aCountry[] = self::$aCountry[$sCountryKey];
|
|
}
|
|
|
|
$sNodeZone = implode("、", $aCountry);
|
|
|
|
//// 速度
|
|
$iNodeSpeed = rand(config("freenode.speed_min"), config("freenode.speed_max"));
|
|
|
|
$iNodeCount = self::nodeCount();
|
|
|
|
$sContent = "本次更新共<b style='color:pink'>".$iNodeCount."</b>个可用节点,最高速度".$iNodeSpeed."M/S。
|
|
覆盖".$sNodeZone."等多个区域。";
|
|
|
|
return $sContent;
|
|
}
|
|
|
|
public static function nodeCount(): int
|
|
{
|
|
if (Pipeline::enabled()) {
|
|
$store = Pipeline::store();
|
|
return $store->locked(function () use ($store): int {
|
|
$release = $store->current();
|
|
if (!$release || ($release['validated'] ?? false) !== true
|
|
|| ($release['date'] ?? '') !== date('Y-m-d')
|
|
|| time() - ($release['created_at'] ?? 0) > 86400) {
|
|
throw new RuntimeException('no_today_published_release_for_article');
|
|
}
|
|
$count = $release['counts']['v2ray'] ?? null;
|
|
if (!is_int($count) || $count < 1) {
|
|
throw new RuntimeException('invalid_published_node_count');
|
|
}
|
|
return $count;
|
|
}, false);
|
|
}
|
|
$pool = FreenodePool::whereDate('date', date('Y-m-d'))->first();
|
|
$content = json_decode($pool->content ?? '[]', true);
|
|
return count($content['v2ray'] ?? []);
|
|
}
|
|
|
|
}
|