150 lines
4.7 KiB
PHP
Executable File
150 lines
4.7 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Services\Tg\Hook\Mod;
|
||
|
||
use App\Models\FreenodePool;
|
||
use App\Services\Tg\Hook\Dog;
|
||
use Illuminate\Support\Str;
|
||
|
||
class FnLook extends Base {
|
||
|
||
private $oDog;
|
||
|
||
public function __construct($aUpdate)
|
||
{
|
||
|
||
$this->oDog = new Dog(new FreenodePool());
|
||
$this->oDog->_setDogName("fnLook"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死
|
||
// $this->oDog->_setPrimaryKey("code"); // 可选,默认id
|
||
// $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段
|
||
|
||
}
|
||
|
||
public function __call($sName, $aArg)
|
||
{
|
||
|
||
return $this->oDog->$sName($aArg[0]);
|
||
|
||
}
|
||
|
||
// 筛选生成订阅,比如只生成vmess协议的
|
||
// 暂时只支持v2ray
|
||
public function tichun($aParam)
|
||
{
|
||
$sClient = $aParam["aOption"][1] ?? "v2ray";
|
||
$sXieyi = $aParam["aOption"][2] ?? "all";
|
||
$aLike = $aParam["aArg"] ?? [];
|
||
$sLike = implode("", $aLike);
|
||
|
||
if ($sLike == "?") {
|
||
return "#tichun__[client]__[xieyi,可用all]__[like,可空]";
|
||
}
|
||
|
||
$sDate = date("Y-m-d");
|
||
$sContent = FreenodePool::whereDate("date", $sDate)->first()?->content;
|
||
$aContent = json_decode($sContent, true);
|
||
|
||
$cClientContent = $aContent[$sClient];
|
||
|
||
$cNode = [];
|
||
$sMerge = '';
|
||
if ($sClient == "v2ray") {
|
||
|
||
foreach ($cClientContent as $aClientContent) {
|
||
$sContentXieyi = $aClientContent["protocolType"] ?? '';
|
||
|
||
if ($sXieyi != "all" && $sContentXieyi != $sXieyi) {
|
||
continue;
|
||
}
|
||
|
||
$sNodeName = $aClientContent["country"];
|
||
|
||
if ($sLike) {
|
||
if (!Str::contains($sNodeName, $sLike, true)) {
|
||
continue;
|
||
}
|
||
}
|
||
|
||
$sConfig = $aClientContent["config"];
|
||
|
||
if (is_array($sConfig)) {
|
||
$sConfig["ps"] = "xx".rand(1, 999);
|
||
$sConfig = json_encode($sConfig);
|
||
}
|
||
|
||
// $sNodeName = preg_replace('/ :\[.*?\]:/su', '', $sNodeName);
|
||
//
|
||
// tt($sNodeName);
|
||
$sConfig = base64_encode($sConfig);
|
||
$sNodeTmp = $sContentXieyi."://".$sConfig;
|
||
$cNode[] = $sNodeTmp;
|
||
}
|
||
|
||
// tt($cNode);
|
||
$sMerge = implode("\n", $cNode);
|
||
$sMerge = base64_encode($sMerge);
|
||
|
||
}
|
||
|
||
return $sMerge;
|
||
// tt($sMerge);
|
||
// exit;
|
||
// tt($cClientContent);
|
||
}
|
||
|
||
|
||
// 比较节点数据。目前用于singbox比较原v2ray
|
||
public function duibi($aParam)
|
||
{
|
||
$sClient = $aParam["aOption"][1] ?? "singbox";
|
||
$sXieyi = $aParam["aOption"][2] ?? "all";
|
||
$aLike = $aParam["aArg"] ?? [];
|
||
$sLike = implode(" ", $aLike);
|
||
|
||
if ($sLike == "?") {
|
||
return "#duibi__[client]__[xieyi,可用all]__[like,可空]";
|
||
}
|
||
|
||
$sDate = date("Y-m-d");
|
||
$sContent = FreenodePool::whereDate("date", $sDate)->first()?->content;
|
||
$aContent = json_decode($sContent, true);
|
||
|
||
$cClientContent = $aContent[$sClient];
|
||
|
||
$sNode = "";
|
||
|
||
if ($sClient == "singbox") {
|
||
foreach ($cClientContent as $sMd5 => $aClientContent) {
|
||
|
||
$sContentXieyi = $aClientContent["protocolType"] ?? '';
|
||
|
||
if ($sXieyi != "all" && $sContentXieyi != $sXieyi) {
|
||
continue;
|
||
}
|
||
|
||
$sNodeName = $aClientContent["country"];
|
||
|
||
if ($sLike) {
|
||
if (!Str::contains($sNodeName, $sLike, true)) {
|
||
continue;
|
||
}
|
||
}
|
||
|
||
$sClientContent = json_encode($aClientContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||
|
||
$cV2rayContent = $aContent["v2ray"] ?? [];
|
||
|
||
$aV2rayContent = $cV2rayContent[$sMd5] ?? '';
|
||
$sV2rayContent = json_encode($aV2rayContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||
|
||
$sNode .= "\n\n"."v2ray:\n".$sV2rayContent;
|
||
$sNode .= "\n\n".$sClient.":\n".$sClientContent;
|
||
$sNode .= "\n\n=========================================================================================";
|
||
}
|
||
}
|
||
|
||
return $sNode;
|
||
}
|
||
|
||
}
|