diff --git a/src/Controllers/TomApi/Tg/HookController.php b/src/Controllers/TomApi/Tg/HookController.php index 6b8c3799b..6e9f071e2 100755 --- a/src/Controllers/TomApi/Tg/HookController.php +++ b/src/Controllers/TomApi/Tg/HookController.php @@ -30,6 +30,14 @@ final class HookController { } + + // 预设客户hook + public function cmd_open() + { + $bOpen = ture; + + return $this->cmd($bOpen); + } public function cmd() @@ -47,8 +55,22 @@ final class HookController @file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT)); - $aData['chatId'] = $aUpdate["message"]["chat"]["id"]; - $aData['fromId'] = $aUpdate["message"]["from"]["id"]; + $aData['chatId'] = $aUpdate["message"]["chat"]["id"] ?? false; + $aData['fromId'] = $aUpdate["message"]["from"]["id"] ?? false; + + // 非sakai都拒绝,与客户hook分开 + if ($aData['fromId'] != $_ENV['tgId']['base']) { + Http::response(200, 'ok'); + exit; + } + + // base群只处理sakai_bot的信息 +// if ($aData['chatId'] == $_ENV['tgChat']['base']) { +// if ($aData['fromId'] != $_ENV['tgId']['sakai_bot']) { +// Http::response(200, 'ok'); +// exit; +// } +// } if (!isset($aUpdate["message"]["text"])) { throw new \Exception("?"); @@ -80,6 +102,7 @@ final class HookController unset($aOption[0]); unset($aArg[0]); + // 进入方法的参数 $aParams['aOption'] = $aOption; $aParams['aArg'] = $aArg; $aParams['aUpdate'] = $aUpdate; diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 70885e998..75e497d0d 100755 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -44,7 +44,7 @@ final class UserController extends BaseController $captcha = Captcha::generate(); } - $oAnn = (new Ann())->orderBy('date', 'desc')->first(); + $oAnn = Ann::where("sort", ">=", 1)->orderBy('date', 'desc')->first(); // $oHuodong = Huodong::DateHit(); diff --git a/src/Middleware/TgAdmin.php b/src/Middleware/TgAdmin.php index 8dc391c7b..b701ef22d 100755 --- a/src/Middleware/TgAdmin.php +++ b/src/Middleware/TgAdmin.php @@ -24,16 +24,16 @@ final class TgAdmin implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $sChatId = $request->getParam('chatId'); - - $sChatIdConfig = Config::obtain('telegram_chatid'); - - if ($sChatIdConfig != $sChatId) { - echo json_encode([ - 'status' => 0, - 'data' => 'key error' - ]);exit; - } +// $sChatId = $request->getParam('chatId'); +// +// $sChatIdConfig = Config::obtain('telegram_chatid'); +// +// if ($sChatIdConfig != $sChatId) { +// echo json_encode([ +// 'status' => 0, +// 'data' => 'key error' +// ]);exit; +// } return $handler->handle($request); } diff --git a/src/Middleware/TgHookAdmin.php b/src/Middleware/TgHookAdmin.php index 26e630678..7d8b815a1 100755 --- a/src/Middleware/TgHookAdmin.php +++ b/src/Middleware/TgHookAdmin.php @@ -22,25 +22,20 @@ final class TgHookAdmin implements MiddlewareInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - @$update = json_decode(file_get_contents("php://input"), true); +// @$update = json_decode(file_get_contents("php://input"), true); +// +// $sChatIdConfig = Config::obtain('telegram_chatid'); +// +// $sChatId = @$update["message"]["chat"]["id"]; - $sChatIdConfig = Config::obtain('telegram_chatid'); - - $sChatId = @$update["message"]["chat"]["id"]; - -// if (@$update['chatId']) { -// $sChatId = @$update['chatId']; -// } else { -// $sChatId = @$update["message"]["chat"]["id"]; + +// if ($sChatIdConfig != $sChatId) { +// echo json_encode([ +// 'status' => 0, +// 'data' => 'key error' +// ]);exit; // } - if ($sChatIdConfig != $sChatId) { - echo json_encode([ - 'status' => 0, - 'data' => 'key error' - ]);exit; - } - return $handler->handle($request); } } diff --git a/src/Services/IM/TelegramV2.php b/src/Services/IM/TelegramV2.php index c001cefff..3ab7718a0 100755 --- a/src/Services/IM/TelegramV2.php +++ b/src/Services/IM/TelegramV2.php @@ -17,13 +17,13 @@ final class TelegramV2 public $sToken; public $sMsgType = false; - public function __construct() + public function __construct($sToken = "base", $sTo = "base") { - $this->setToken("base"); + $this->setToken($sToken); - $this->setTo("base"); + $this->setTo($sTo); - $this->bot = new Api($this->sToken); +// $this->bot = new Api($this->sToken); } public function setMsgType($sMsgType) @@ -53,6 +53,8 @@ final class TelegramV2 } $this->sToken = $sToken; + + $this->bot = new Api($this->sToken); } public function send($sMsg, $sMsgType = 'str') @@ -74,7 +76,7 @@ final class TelegramV2 $sendMessage = [ 'chat_id' => $this->iTo, 'text' => strip_tags( - $msg, + $sMsg, ['b', 'strong', 'i', 'em', 'u', 'ins', 's', 'strike','del', 'span','tg-spoiler', 'a', 'tg-emoji', 'code', 'pre', ] @@ -87,7 +89,7 @@ final class TelegramV2 } else if ($this->sMsgType === "markdown") { $sendMessage = [ 'chat_id' => $this->iTo, - 'text' => $msg, + 'text' => $sMsg, 'parse_mode' => 'Markdown', 'disable_web_page_preview' => false, 'reply_to_message_id' => null, @@ -96,7 +98,7 @@ final class TelegramV2 } else if ($this->sMsgType === "markdownV2") { $sendMessage = [ 'chat_id' => $this->iTo, - 'text' => $msg, + 'text' => $sMsg, 'parse_mode' => 'MarkdownV2', 'disable_web_page_preview' => false, 'reply_to_message_id' => null, diff --git a/src/Services/Tg/Hook/Mod/Ann.php b/src/Services/Tg/Hook/Mod/Ann.php index ed22877d9..a9d300f21 100644 --- a/src/Services/Tg/Hook/Mod/Ann.php +++ b/src/Services/Tg/Hook/Mod/Ann.php @@ -4,17 +4,18 @@ namespace App\Services\Tg\Hook\Mod; use App\Models\Ann as ModelAnn; use App\Services\Tg\Hook\Dog; +use App\Services\IM\TelegramV2; class Ann extends Base { private $oDog; - + public function __construct($aUpdate) { $this->oDog = new Dog(new ModelAnn()); $this->oDog->_setDogName("ann"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 -// $this->oDog->_setPrimaryKey("code"); // 可选,默认id + // $this->oDog->_setPrimaryKey("code"); // 可选,默认id $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段 $this->oDog->_setInFormat(["date"]); } @@ -26,4 +27,44 @@ class Ann extends Base { } + public function post($aParam) + { + $iId = $aParam["aArg"][1] ?? false; + $sConfirm = $aParam["aOption"][1] ?? "n"; + + if (!$iId) { + return "需要id"; + } + + if ($aParam["aArg"][1] == "?") { + return "/ann#post__[:n,y] id | n发私有群测试"; + } + + $oAnn = ModelAnn::where("id", $iId)->first(); + + if (!$oAnn) { + return "没有这个数据"; + } + + $oTelegramV2 = new TelegramV2("fuuuuCloud_bot"); + $oTelegramV2->setMsgType("html"); + + if ($sConfirm == "n") { + + $oTelegramV2->setTo("base"); + + $oTelegramV2->send($oAnn->content, "str"); + + } else if ($sConfirm == "y") { + + $oTelegramV2->setTo("tongzhiqun"); + + $oTelegramV2->send($oAnn->content, "str"); + + } + + return "ok"; + + } + }