diff --git a/app/Services/Cron/FreenodeWatch.php b/app/Services/Cron/FreenodeWatch.php new file mode 100755 index 00000000..5c905377 --- /dev/null +++ b/app/Services/Cron/FreenodeWatch.php @@ -0,0 +1,25 @@ +get(); + +// foreach () + + echo "\n - ok"; + } +} diff --git a/app/Services/OpenApi/Telegram.php b/app/Services/OpenApi/Telegram.php index 88465724..0e73d629 100755 --- a/app/Services/OpenApi/Telegram.php +++ b/app/Services/OpenApi/Telegram.php @@ -36,6 +36,8 @@ final class Telegram $sPhotoUrl = $aArg["sPhotoUrl"] ?? ''; $iPhotoWidth = $aArg["iPhotoWidth"] ?? 0; $iPhotoHeight = $aArg["iPhotoHeight"] ?? 0; + $sFileUrl = $aArg["sFileUrl"] ?? ''; + $sFileName = $aArg["sFileName"] ?? ''; $sType = $aArg["sType"] ?? ''; $r = TeleMaster::start() @@ -44,6 +46,7 @@ final class Telegram ->setBotToken($sBotToken) ->setChatId($iChatId) ->setPhotoUrl($sPhotoUrl, $iPhotoWidth, $iPhotoHeight) + ->setFileUrl($sFileUrl, $sFileName) ->setType($sType) ->send($sMsg); diff --git a/app/Services/Tg/Hook/Mod/Freenode.php b/app/Services/Tg/Hook/Mod/Freenode.php new file mode 100755 index 00000000..3d8bee90 --- /dev/null +++ b/app/Services/Tg/Hook/Mod/Freenode.php @@ -0,0 +1,66 @@ +oDog = new Dog(new ModelFreenodePool()); + $this->oDog->_setDogName("Freenode"); + $this->oDog->_setJsonField(["content"]); +// $this->oDog->_setStrField(["content"]); + $this->aUpdate = $aUpdate; + } + + public function __call($sName, $aArg) + { + return $this->oDog->$sName($aArg[0]); + } + + public function show($aParam) + { + $sSiteCode = $aParam["aArg"][1] ?? "cfn"; + $sClient = $aParam["aOption"][1] ?? "clash"; + + if ($sSiteCode === "?") { + return "/show#__[client:clash] [siteCodeShort]"; + } + + $oSite = ModelSiteMap::where("code_short", $sSiteCode)->first(); + + if (!$oSite) { + return "没有这个site"; + } + + $sClientSfx = Map::fnClientToSfx($sClient); + + $sFileName = date("Ymd")."-".$sClient.".".$sClientSfx; + $sFileUrl = "https://".$oSite->url."/sub/".$sFileName; +// $sFileUrl = "https://clashv2rayfree.com/sub/".$sFileName; // test + + $oFlow = TeleSlave::start("admin", "admin") + ->enableSlaveQueue(false) + ->enableAsync(false) + ->enableDetail(false) + ->setFileUrl($sFileUrl, $sSiteCode."的".$sClient.".txt") + ->send(); + + if ($oFlow->isFail()) { + var_dump($oFlow->getResult()); + exit; + } + + } + +} diff --git a/app/Services/Tg/Hook/Mod/Test.php b/app/Services/Tg/Hook/Mod/Test.php index 9311f9ba..9395022c 100755 --- a/app/Services/Tg/Hook/Mod/Test.php +++ b/app/Services/Tg/Hook/Mod/Test.php @@ -6,6 +6,7 @@ use App\Models\BladeJctj as ModelBladeJctj; use App\Services\Tg\Hook\Dog; use App\Services\TomTool\Flow; use App\Services\TomTool\HttpV2; +use App\Services\TomTool\Telegram\Slave as TeleSlave; use App\Services\UrlMap; @@ -28,6 +29,12 @@ class Test extends Base { return $this->oDog->$sName($aArg[0]); } + public function t1() + { + TeleSlave::log()->enableSlaveQueue(false)->setFileUrl("https://master.tomshell.my/freenode/template/clash.txt")->setMsgS("fff")->send(); + echo 1; + } + public function httpJson($aParam) { $sUrl = $aParam["aOption"][1] ?? ''; diff --git a/app/Services/TomTool/Map.php b/app/Services/TomTool/Map.php new file mode 100755 index 00000000..7d68dd3b --- /dev/null +++ b/app/Services/TomTool/Map.php @@ -0,0 +1,26 @@ +sFileUrl = $sFileUrl; + $this->sFileName = $sFileName; + return $this; + } + public function send($sMsg = ''): Flow { if ($sMsg) { @@ -105,7 +115,7 @@ final class Master } if (!$this->sMsg) { - throw new \Exception("未设置msg"); +// throw new \Exception("未设置msg"); } $this->keyBegin(); @@ -119,6 +129,7 @@ final class Master ->setChatId($this->iChatId) ->setMsgS($this->sMsg) ->setPhotoUrl($this->sPhotoUrl, $this->iPhotoWidth, $this->iPhotoHeight) + ->setFileUrl($this->sFileUrl, $this->sFileName) ->setType($this->sType) ->send(); } @@ -155,6 +166,8 @@ final class Master "sPhotoUrl" => $this->sPhotoUrl ?? '', "iPhotoWidth" => $this->iPhotoWidth, "iPhotoHeight" => $this->iPhotoHeight, + "sFileUrl" => $this->sFileUrl, + "sFileName" => $this->sFileName, "sMsg" => $this->sMsg ?? '', "sType" => $this->sType ?? '', ]; diff --git a/app/Services/TomTool/Telegram/Sdk.php b/app/Services/TomTool/Telegram/Sdk.php index 9375fb99..b022dd6d 100755 --- a/app/Services/TomTool/Telegram/Sdk.php +++ b/app/Services/TomTool/Telegram/Sdk.php @@ -21,6 +21,8 @@ class Sdk public $sPhotoUrl = ''; public $iPhotoWidth = 0; public $iPhotoHeight = 0; + public $sFileUrl = ''; + public $sFileName = ''; public $sMsg; public $oApi; @@ -56,7 +58,13 @@ class Sdk $this->sPhotoUrl = $sUrl; $this->iPhotoWidth = $iPhotoWidth; $this->iPhotoHeight = $iPhotoHeight; -// tomd($iPhotoWidth, 1); + return $this; + } + + public function setFileUrl($sFileUrl = '', $sFileName = '') + { + $this->sFileUrl = $sFileUrl; + $this->sFileName = $sFileName; return $this; } @@ -79,6 +87,8 @@ class Sdk if ($this->sPhotoUrl) { $r = $this->oApi->sendPhoto($this->sMsgFormat); + } else if ($this->sFileUrl) { + $r = $this->oApi->sendDocument($this->sMsgFormat); } else { $r = $this->oApi->sendMessage($this->sMsgFormat); } @@ -105,7 +115,7 @@ class Sdk if (!in_array($this->sMsgFormatType, self::ALLOWED_FORMATS, true)) { throw new \RuntimeException("不支持的格式类型: {$this->sMsgFormatType}"); } -// ini_set('memory_limit', '512M'); + $method = 'msgFormat_' . $this->sMsgFormatType; $this->sMsgFormat = $this->$method(); @@ -118,7 +128,7 @@ class Sdk $sImg = file_get_contents($this->sPhotoUrl); $oImage = $oManager->read($sImg); -// tomd($this->iPhotoWidth, 1); + if ($this->iPhotoWidth && $this->iPhotoHeight) { $oImage = $oImage->cover($this->iPhotoWidth, $this->iPhotoHeight); } @@ -131,6 +141,21 @@ class Sdk $this->sMsgFormat["caption"] = $this->sMsgFormat["text"]; unset($this->sMsgFormat["text"]); + + } else if ($this->sFileUrl) { + + if (!$this->sFileName) { + $sFileName = date("Y-m-d H:i:s").'.txt'; + } else { + $sFileName = $this->sFileName; + } + + $sFile = InputFile::create($this->sFileUrl, $sFileName); + + $this->sMsgFormat["document"] = $sFile; + $this->sMsgFormat["caption"] = $this->sMsgFormat["text"]; + unset($this->sMsgFormat["text"]); + } return $this; diff --git a/app/Services/TomTool/Telegram/Slave.php b/app/Services/TomTool/Telegram/Slave.php index b30f9bcd..800b6146 100755 --- a/app/Services/TomTool/Telegram/Slave.php +++ b/app/Services/TomTool/Telegram/Slave.php @@ -61,6 +61,9 @@ class Slave public int $iPhotoWidth = 0; public int $iPhotoHeight = 0; + public string $sFileUrl = ''; + public string $sFileName = ''; + public string $sType = ''; public bool $enableMaster = true; @@ -152,6 +155,14 @@ class Slave return $this; } + // set + public function setFileUrl(string $sFileUrl, string $sFileName = ''): self + { + $this->sFileUrl = $sFileUrl; + $this->sFileName = $sFileName; + return $this; + } + // set public function setType(string $sType): self { @@ -233,7 +244,7 @@ class Slave } if (!$this->sMsg) { - throw new Exception("未设置msg"); +// throw new \Exception("未设置msg"); } if ($this->enableMaster) { @@ -261,7 +272,6 @@ class Slave private function _send_master(): Flow { -// tomd(11111,1); $aData = $this->buildDataTom(); if ($this->enableSlaveQueue) { @@ -272,7 +282,7 @@ class Slave $sUrlMaSterBase = $_ENV["url_master_base"] ?? ""; if (!$sUrlMaSterBase) { - throw new Exception("未设置env的url_master_base"); + throw new \Exception("未设置env的url_master_base"); } $sUrlMasterPost = "https://".$sUrlMaSterBase."/api/telegram/post"; @@ -336,6 +346,8 @@ class Slave "iPhotoWidth" => $this->iPhotoWidth ?? 0, "iPhotoHeight" => $this->iPhotoHeight ?? 0, "sType" => $this->sType ?? '', + "sFileUrl" => $this->sFileUrl ?? '', + "sFileName" => $this->sFileName ?? '', ]; } diff --git a/fn部署.md b/fn部署.md index bcbc80cf..a549a3b1 100755 --- a/fn部署.md +++ b/fn部署.md @@ -10,6 +10,11 @@ master的fn文件夹里加template master加dog_option表 cfn的option里嫁freenode_client +{ + "id": 10, + "key": "freenode_client", + "value": "v2ray,clash" + } cnf加http_queue表 - 不用