no message
This commit is contained in:
parent
89b98e102d
commit
2d7c42c80d
@ -10,15 +10,19 @@ namespace App\Controllers\TomApi\Tg;
|
|||||||
//use Slim\Http\ServerRequest;
|
//use Slim\Http\ServerRequest;
|
||||||
|
|
||||||
use App\Models\Config;
|
use App\Models\Config;
|
||||||
|
use GuzzleHttp\Psr7\ServerRequest;
|
||||||
|
use GuzzleHttp\Psr7\Utils;
|
||||||
|
|
||||||
final class HookController
|
final class HookController
|
||||||
{
|
{
|
||||||
|
|
||||||
public $sApiToken;
|
public $sApiToken;
|
||||||
|
public $sApiChatId;
|
||||||
|
|
||||||
public function cmd()
|
public function cmd()
|
||||||
{
|
{
|
||||||
$this->sApiToken = Config::obtain('telegram_token');
|
$this->sApiToken = Config::obtain('telegram_token');
|
||||||
|
$this->sApiChatId = Config::obtain('telegram_chatid')
|
||||||
|
|
||||||
// 获取更新
|
// 获取更新
|
||||||
$update = json_decode(file_get_contents("php://input"), true);
|
$update = json_decode(file_get_contents("php://input"), true);
|
||||||
@ -36,14 +40,33 @@ final class HookController
|
|||||||
|
|
||||||
// 发送消息到 Telegram
|
// 发送消息到 Telegram
|
||||||
$this->sendMessage($chatId, "服务器时间: " . $serverTime);
|
$this->sendMessage($chatId, "服务器时间: " . $serverTime);
|
||||||
|
|
||||||
|
http_response_code(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($message === "/reply") {
|
||||||
|
|
||||||
|
// 创建一个包含请求体的 ServerRequest 实例
|
||||||
|
$body = ['comment' => 'This is a comment.'];
|
||||||
|
$request = new ServerRequest('PUT', '/ticket/', ['Content-Type' => 'application/json'], json_encode($body));
|
||||||
|
|
||||||
|
// 创建一个 Response 实例
|
||||||
|
$response = new Response();
|
||||||
|
|
||||||
|
// 调用 update 方法
|
||||||
|
$controller = new YourController();
|
||||||
|
$controller->update($request, $response, []);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
http_response_code(200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送消息的函数
|
// 发送消息的函数
|
||||||
public function sendMessage($chatId, $message) {
|
public function sendMessage($chatId, $message) {
|
||||||
|
|
||||||
$url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$chatId&text=" . urlencode($message);
|
$url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($message);
|
||||||
file_get_contents($url);
|
file_get_contents($url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user