no message

This commit is contained in:
hellcat 2025-10-17 15:21:52 +08:00
parent f3bc2fc001
commit 18f03ab6a3
6 changed files with 99 additions and 38 deletions

View File

@ -31,6 +31,14 @@ final class HookController
} }
// 预设客户hook
public function cmd_open()
{
$bOpen = ture;
return $this->cmd($bOpen);
}
public function cmd() public function cmd()
{ {
@ -47,8 +55,22 @@ final class HookController
@file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT)); @file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT));
$aData['chatId'] = $aUpdate["message"]["chat"]["id"]; $aData['chatId'] = $aUpdate["message"]["chat"]["id"] ?? false;
$aData['fromId'] = $aUpdate["message"]["from"]["id"]; $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"])) { if (!isset($aUpdate["message"]["text"])) {
throw new \Exception(""); throw new \Exception("");
@ -80,6 +102,7 @@ final class HookController
unset($aOption[0]); unset($aOption[0]);
unset($aArg[0]); unset($aArg[0]);
// 进入方法的参数
$aParams['aOption'] = $aOption; $aParams['aOption'] = $aOption;
$aParams['aArg'] = $aArg; $aParams['aArg'] = $aArg;
$aParams['aUpdate'] = $aUpdate; $aParams['aUpdate'] = $aUpdate;

View File

@ -44,7 +44,7 @@ final class UserController extends BaseController
$captcha = Captcha::generate(); $captcha = Captcha::generate();
} }
$oAnn = (new Ann())->orderBy('date', 'desc')->first(); $oAnn = Ann::where("sort", ">=", 1)->orderBy('date', 'desc')->first();
// $oHuodong = Huodong::DateHit(); // $oHuodong = Huodong::DateHit();

View File

@ -24,16 +24,16 @@ final class TgAdmin implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{ {
$sChatId = $request->getParam('chatId'); // $sChatId = $request->getParam('chatId');
//
$sChatIdConfig = Config::obtain('telegram_chatid'); // $sChatIdConfig = Config::obtain('telegram_chatid');
//
if ($sChatIdConfig != $sChatId) { // if ($sChatIdConfig != $sChatId) {
echo json_encode([ // echo json_encode([
'status' => 0, // 'status' => 0,
'data' => 'key error' // 'data' => 'key error'
]);exit; // ]);exit;
} // }
return $handler->handle($request); return $handler->handle($request);
} }

View File

@ -22,24 +22,19 @@ final class TgHookAdmin implements MiddlewareInterface
*/ */
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 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'); // $sChatIdConfig = Config::obtain('telegram_chatid');
//
$sChatId = @$update["message"]["chat"]["id"];
// if (@$update['chatId']) {
// $sChatId = @$update['chatId'];
// } else {
// $sChatId = @$update["message"]["chat"]["id"]; // $sChatId = @$update["message"]["chat"]["id"];
// }
if ($sChatIdConfig != $sChatId) {
echo json_encode([ // if ($sChatIdConfig != $sChatId) {
'status' => 0, // echo json_encode([
'data' => 'key error' // 'status' => 0,
]);exit; // 'data' => 'key error'
} // ]);exit;
// }
return $handler->handle($request); return $handler->handle($request);
} }

View File

@ -17,13 +17,13 @@ final class TelegramV2
public $sToken; public $sToken;
public $sMsgType = false; 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) public function setMsgType($sMsgType)
@ -53,6 +53,8 @@ final class TelegramV2
} }
$this->sToken = $sToken; $this->sToken = $sToken;
$this->bot = new Api($this->sToken);
} }
public function send($sMsg, $sMsgType = 'str') public function send($sMsg, $sMsgType = 'str')
@ -74,7 +76,7 @@ final class TelegramV2
$sendMessage = [ $sendMessage = [
'chat_id' => $this->iTo, 'chat_id' => $this->iTo,
'text' => strip_tags( 'text' => strip_tags(
$msg, $sMsg,
['b', 'strong', 'i', 'em', 'u', 'ins', 's', 'strike','del', 'span','tg-spoiler', 'a', 'tg-emoji', ['b', 'strong', 'i', 'em', 'u', 'ins', 's', 'strike','del', 'span','tg-spoiler', 'a', 'tg-emoji',
'code', 'pre', 'code', 'pre',
] ]
@ -87,7 +89,7 @@ final class TelegramV2
} else if ($this->sMsgType === "markdown") { } else if ($this->sMsgType === "markdown") {
$sendMessage = [ $sendMessage = [
'chat_id' => $this->iTo, 'chat_id' => $this->iTo,
'text' => $msg, 'text' => $sMsg,
'parse_mode' => 'Markdown', 'parse_mode' => 'Markdown',
'disable_web_page_preview' => false, 'disable_web_page_preview' => false,
'reply_to_message_id' => null, 'reply_to_message_id' => null,
@ -96,7 +98,7 @@ final class TelegramV2
} else if ($this->sMsgType === "markdownV2") { } else if ($this->sMsgType === "markdownV2") {
$sendMessage = [ $sendMessage = [
'chat_id' => $this->iTo, 'chat_id' => $this->iTo,
'text' => $msg, 'text' => $sMsg,
'parse_mode' => 'MarkdownV2', 'parse_mode' => 'MarkdownV2',
'disable_web_page_preview' => false, 'disable_web_page_preview' => false,
'reply_to_message_id' => null, 'reply_to_message_id' => null,

View File

@ -4,6 +4,7 @@ namespace App\Services\Tg\Hook\Mod;
use App\Models\Ann as ModelAnn; use App\Models\Ann as ModelAnn;
use App\Services\Tg\Hook\Dog; use App\Services\Tg\Hook\Dog;
use App\Services\IM\TelegramV2;
class Ann extends Base { class Ann extends Base {
@ -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";
}
} }