89 lines
1.9 KiB
PHP
89 lines
1.9 KiB
PHP
<?php
|
||
|
||
namespace App\Services\Tg;
|
||
use App\Models\Config;
|
||
use App\Services\IM\Telegram;
|
||
use App\Services\Tg\Http;
|
||
use App\Services\TomTool\Http as TomHttp;
|
||
|
||
class Http {
|
||
|
||
public $sApiToken;
|
||
public $sApiChatId;
|
||
|
||
function __construct()
|
||
{
|
||
$this->sApiToken = Config::obtain('telegram_token');
|
||
$this->sApiChatId = Config::obtain('telegram_chatid');
|
||
}
|
||
|
||
public function send($sMsg = "msg空", $aUpdate = [])
|
||
{
|
||
|
||
$bSendTg = true;
|
||
|
||
$sShell = $aUpdate["shell"] ?? false;
|
||
$bIsDove = $aUpdate["is_dove"] ?? false;
|
||
|
||
if ($sShell == "cmd") {
|
||
$bSendTg = false;
|
||
}
|
||
|
||
if ($bIsDove == true) {
|
||
$bSendTg = false;
|
||
}
|
||
|
||
if ($_ENV['is_loc'] == true) {
|
||
$bSendTg = false;
|
||
}
|
||
|
||
if (is_array($sMsg)) {
|
||
foreach ($sMsg as $sMsgRow) {
|
||
if ($bSendTg) {
|
||
$this->sendTg($sMsgRow);
|
||
} else {
|
||
echo $sMsgRow;
|
||
}
|
||
}
|
||
} else {
|
||
if ($bSendTg) {
|
||
$this->sendTg($sMsg);
|
||
} else {
|
||
echo $sMsg;
|
||
}
|
||
}
|
||
|
||
if ($bSendTg) {
|
||
TomHttp::response(200);
|
||
} else {
|
||
exit;
|
||
}
|
||
|
||
}
|
||
|
||
private function sendTg($sMsg)
|
||
{
|
||
(new Telegram())->send(0, $sMsg);
|
||
}
|
||
|
||
public function sendToTG($sMsg = "没有msg?", $aUpdate = [])
|
||
{
|
||
|
||
if (isset($aUpdate["shell"]) && $aUpdate["shell"] == "cmd") {
|
||
|
||
echo $sMsg;
|
||
|
||
} else if (isset($aUpdate["is_dove"]) && $aUpdate["is_dove"] == true) {
|
||
|
||
echo $sMsg;
|
||
|
||
} else {
|
||
|
||
(new Telegram())->send(0, $sMsg);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|