dd/app/Services/TG/Http.php
2025-05-11 10:46:36 +08:00

44 lines
1.1 KiB
PHP

<?php
namespace App\Services\TG;
use App\Services\TomTool\Http as TomHttp;
class Http {
public $sApiToken;
public $sApiChatId;
function __construct()
{
$this->sApiToken = env('telegram_token');
$this->sApiChatId = env('telegram_chatid');
}
public function sendToTG($sMsg)
{
if (env('is_loc') == true) {
echo "<pre>";
echo($sMsg);
} else {
// $url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sMsg);
// file_get_contents($url);
$oHttp = new TomHttp();
$oHttp->sMethod = "post";
$oHttp->sToUrl = "https://api.telegram.org/bot$this->sApiToken/sendMessage";
// $oHttp->bIsJson = true;
$oHttp->aData = [
"chat_id" => $this->sApiChatId,
"text" => $sMsg
];
$r = $oHttp->send();
//
tomd($r);
}
}
}