From: fomichev Date: Mon, 20 Jan 2025 20:03:32 +0000 (+0300) Subject: Токен для прода X-Git-Tag: 1.7~60^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ad87a8805f1a24421120fb87b20e53035dc7c1eb;p=erp24_rep%2Fyii-erp24%2F.git Токен для прода --- diff --git a/erp24/services/TelegramService.php b/erp24/services/TelegramService.php index 94592ef5..457099cf 100644 --- a/erp24/services/TelegramService.php +++ b/erp24/services/TelegramService.php @@ -10,8 +10,8 @@ class TelegramService { - const TELEGRAM_API_URL = "8063257458:AAGnMf4cxwJWlYLF1wS_arn4PrOaLs9ERQQ"; - + const TELEGRAM_BOT_DEV = "8063257458:AAGnMf4cxwJWlYLF1wS_arn4PrOaLs9ERQQ"; + const TELEGRAM_BOT_PROD = "5456741805:AAG7xOSiYDwUdV5NMb2v9vh8CWzEczDP4yU"; const TARGET_PROD_URL = "erp.erp-flowers.ru"; const CHAT_CHANNEL_ID = "-1001861631125"; const CHAT_CHANNEL_ERP_ID = "-1002338329426"; @@ -26,21 +26,21 @@ class TelegramService return $client->request('GET', $url); } - public static function isDevelopmentEnvironment($urlString = null) : bool - { - try { + public static function isDevelopmentEnvironment($urlString = null): bool + { + try { $ip = Yii::$app->request->getHostInfo(); - } catch (\Exception $exception) { + } catch (\Exception $exception) { $ip = 'console'; - } + } $currentUrl = empty($urlString) ? $ip : $urlString; return !str_contains($currentUrl, self::TARGET_PROD_URL); - } + } public static function sendErrorToTelegramMessage($message, $disableNotification, $isDev) { - $botToken = self::TELEGRAM_API_URL; + $botToken = self::TELEGRAM_BOT_DEV; $chatIdDefault = self::CHAT_CHANNEL_ID; $chatIdErp = self::CHAT_CHANNEL_ERP_ID; $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage"; @@ -69,7 +69,12 @@ class TelegramService public static function sendMessageToTelegramClient($chatId, $message) { - $botToken = self::TELEGRAM_API_URL; // Токен вашего Telegram-бота + if (self::isDevelopmentEnvironment()) { + $botToken = self::TELEGRAM_BOT_DEV; + } else { + $botToken = self::TELEGRAM_BOT_PROD; + } + $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage"; $client = new Client();