From: Aleksey Filippov Date: Fri, 4 Jul 2025 16:41:18 +0000 (+0300) Subject: [BC-278] Отправка сообщения в Телеграм X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=212639ee574f65f7831a82b9c5d4b758e5588217;p=erp24_rep%2Fyii-erp24%2F.git [BC-278] Отправка сообщения в Телеграм --- diff --git a/erp24/jobs/SendTelegramPromoMessageJob.php b/erp24/jobs/SendTelegramPromoMessageJob.php index 67331bea..7177eb53 100644 --- a/erp24/jobs/SendTelegramPromoMessageJob.php +++ b/erp24/jobs/SendTelegramPromoMessageJob.php @@ -39,12 +39,9 @@ class SendTelegramPromoMessageJob extends \yii\base\BaseObject implements JobInt if ($result == "OK") { try { -// $result = TelegramService::saveSentMessageToDB($this->messageData); - //TODO - перенос сюда обновления статусов записей когорт - if ($result) { + + if (1) { Yii::warning("Сообщение успешно сохранено для пользователя с ID {$chatId} телефон {$phone}", 'telegram'); - } else { - Yii::warning("Сообщение не удалось сохранить для пользователя с ID {$chatId} телефон {$phone}", 'telegram'); } } catch (\Exception $e) { diff --git a/erp24/services/TelegramService.php b/erp24/services/TelegramService.php index 9058136e..1eb4afd4 100644 --- a/erp24/services/TelegramService.php +++ b/erp24/services/TelegramService.php @@ -203,23 +203,11 @@ class TelegramService Только 7 дней: Скидка 20% на три стильных букета из нашей летней коллекции!'; - $pic1Path = curl_file_create( - __DIR__ . '/../web/images/pic_1.jpg', - 'image/jpg', - 'pic_1.jpg' - ); + $pic1Path =__DIR__ . '/../web/images/pic_1.jpg'; - $pic2Path = curl_file_create( - __DIR__ . '/../web/images/pic_2.jpg', - 'image/jpg', - 'pic_2.jpg' - ); + $pic2Path = __DIR__ . '/../web/images/pic_2.jpg'; - $pic3Path = curl_file_create( - __DIR__ . '/../web/images/pic_3.jpg', - 'image/jpg', - 'pic_3.jpg' - ); + $pic3Path = __DIR__ . '/../web/images/pic_3.jpg'; $result = 'false'; @@ -228,19 +216,47 @@ class TelegramService $buttons = self::getTgShortButtons($chatId); $client = new Client(); + + $media = [ + [ + 'type' => 'photo', + 'media' => 'attach://pic_1.jpg', + 'caption' => $text, + ], + [ + 'type' => 'photo', + 'media' => 'attach://pic_2.jpg', + ], + [ + 'type' => 'photo', + 'media' => 'attach://pic_3.jpg', + ] + ]; + try { - $response1 = $client->post($apiURL1, [ - 'json' => [ - 'chat_id' => $chatId, - 'media' => json_encode([ - ['type' => 'photo', 'media' => 'attach://pic_1.jpg', "caption" => $text], - ['type' => 'photo', 'media' => 'attach://pic_2.jpg' ], - ['type' => 'photo', 'media' => 'attach://pic_3.jpg' ], - ]), - 'pic_1.jpg' => $pic1Path, - 'pic_2.jpg' => $pic2Path, - 'pic_3.jpg' => $pic3Path, - ], + $response1 = $client->post($apiURL1,[ + 'multipart' => [ + [ + 'name' => 'chat_id', + 'contents' => $chatId + ], + [ + 'name' => 'media', + 'contents' => json_encode($media) + ], + [ + 'name' => 'pic_1.jpg', + 'contents' => fopen($pic1Path, 'r') + ], + [ + 'name' => 'pic_2.jpg', + 'contents' => fopen($pic2Path, 'r') + ], + [ + 'name' => 'pic_3.jpg', + 'contents' => fopen($pic3Path, 'r') + ], + ] ]); if ($response1->getStatusCode() !== 200) {