no message

This commit is contained in:
hellcat 2025-03-22 18:23:54 +08:00
parent e69efe1de0
commit d3a27ddbb5

View File

@ -34,30 +34,23 @@ final class HookController
$this->sApiToken = Config::obtain('telegram_token'); $this->sApiToken = Config::obtain('telegram_token');
$this->sApiChatId = Config::obtain('telegram_chatid'); $this->sApiChatId = Config::obtain('telegram_chatid');
$sUpdate = file_get_contents("php://input");
file_put_contents('/www/_tg/bot_log.txt', $sUpdate);
$aUpdate = json_decode($sUpdate, true);
$aData['chatId'] = $this->sApiChatId; $aData['chatId'] = $this->sApiChatId;
// 获取更新
@$update = json_decode(file_get_contents("php://input"), true);
// 假设 $test 是你要检查的变量 if (!isset($aUpdate["message"]["text"])) {
// $test = 1; http_response_code(200);
echo "not have text";
// if ($test == 1) { exit;
// 将 $update 转换为 JSON 格式 }
$json_data = json_encode($update, JSON_PRETTY_PRINT);
// 将 JSON 数据写入当前目录下的 gettghook.txt 文件
file_put_contents('/www/wwwroot/fuuu.cloud/public/gettghook.txt', $json_data);
// }
// 获取聊天 ID
// $chatId = $update["message"]["chat"]["id"];
// 获取消息文本
$message = $update["message"]["text"];
// 检查消息是否为 /test $sText = $aUpdate["message"]["text"];
if ($message === "/test") {
if ($sText === "/test") {
$serverTime = date("Y-m-d H:i:s"); $serverTime = date("Y-m-d H:i:s");
@ -66,9 +59,9 @@ final class HookController
http_response_code(200);exit; http_response_code(200);exit;
} }
if (strpos($message, '/reply') === 0) { if (strpos($sText, '/reply') === 0) {
// 去掉 /reply 字符串 // 去掉 /reply 字符串
$responseText = str_replace('/reply', '', $message); // 直接去掉 /reply $responseText = str_replace('/reply', '', $sText); // 直接去掉 /reply
$responseText = trim($responseText); // 去掉前后的空格 $responseText = trim($responseText); // 去掉前后的空格
// 使用空格分割内容 // 使用空格分割内容
@ -98,8 +91,6 @@ final class HookController
} }
http_response_code(200);exit; http_response_code(200);exit;
} }
@ -108,12 +99,12 @@ final class HookController
} }
// 发送消息的函数 // 发送消息的函数
public function sendMessage($message) { public function sendMessage($sText) {
if ($_ENV['is_loc'] === true) { if ($_ENV['is_loc'] === true) {
var_dump($message); var_dump($sText);
} else { } else {
$url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($message); $url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sText);
file_get_contents($url); file_get_contents($url);
} }