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

@ -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;

View File

@ -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();

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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,

View File

@ -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";
}
}