no message
This commit is contained in:
parent
e69efe1de0
commit
d3a27ddbb5
@ -34,30 +34,23 @@ final class HookController
|
||||
$this->sApiToken = Config::obtain('telegram_token');
|
||||
$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;
|
||||
|
||||
// 获取更新
|
||||
@$update = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
// 假设 $test 是你要检查的变量
|
||||
// $test = 1;
|
||||
|
||||
// if ($test == 1) {
|
||||
// 将 $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"];
|
||||
if (!isset($aUpdate["message"]["text"])) {
|
||||
http_response_code(200);
|
||||
echo "not have text";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 检查消息是否为 /test
|
||||
if ($message === "/test") {
|
||||
$sText = $aUpdate["message"]["text"];
|
||||
|
||||
if ($sText === "/test") {
|
||||
|
||||
$serverTime = date("Y-m-d H:i:s");
|
||||
|
||||
@ -66,9 +59,9 @@ final class HookController
|
||||
http_response_code(200);exit;
|
||||
}
|
||||
|
||||
if (strpos($message, '/reply') === 0) {
|
||||
if (strpos($sText, '/reply') === 0) {
|
||||
// 去掉 /reply 字符串
|
||||
$responseText = str_replace('/reply', '', $message); // 直接去掉 /reply
|
||||
$responseText = str_replace('/reply', '', $sText); // 直接去掉 /reply
|
||||
$responseText = trim($responseText); // 去掉前后的空格
|
||||
|
||||
// 使用空格分割内容
|
||||
@ -98,8 +91,6 @@ final class HookController
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
var_dump($message);
|
||||
var_dump($sText);
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user