### Install SMSAero PHP SDK Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Use Composer to install the SMSAero PHP SDK. This is the first step before using any of the SDK's functionalities. ```bash composer require smsaero/smsaero_api ``` -------------------------------- ### Get Tariffs Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves information about available tariffs. ```APIDOC ## Get Tariffs ### Description Retrieves information about available tariffs. ### Method `getTariffs()` ### Response Details of the response depend on the API's return. Typically includes a list of available tariffs and their details. ``` -------------------------------- ### Get Balance Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves the current account balance. ```APIDOC ## Get Balance ### Description Retrieves the current account balance. ### Method `getBalance()` ### Response Details of the response depend on the API's return. Typically includes the current balance amount. ``` -------------------------------- ### Initialize SMSAeroClient and Send SMS Source: https://context7.com/smsaero/smsaero_api/llms.txt Initialize the SMSAeroMessage client with your email and API key. This example demonstrates sending a single SMS message. Ensure cURL is available and network connectivity is stable to avoid exceptions. ```php try { $client = new \SmsAero\SmsAeroMessage('user@example.com', 'ваш_api_ключ'); $response = $client->send(['number' => '79991234567', 'text' => 'Привет!', 'sign' => 'SMS Aero']); } catch (\Exception $e) { echo 'Ошибка клиента: ' . $e->getMessage(); } ``` -------------------------------- ### Get Group List Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of all available groups. ```APIDOC ## Get Group List ### Description Retrieves a list of all available groups. ### Method `getList()` ### Response Details of the response depend on the API's return. Typically includes a list of groups. ``` -------------------------------- ### Get Blacklist Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of all contacts currently in the blacklist. ```APIDOC ## Get Blacklist ### Description Retrieves a list of all contacts in the blacklist. ### Method `getBlacklist()` ### Response Details of the response depend on the API's return. Typically includes a list of blacklisted contacts. ``` -------------------------------- ### Get User Cards Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of the user's associated cards. ```APIDOC ## Get User Cards ### Description Retrieves a list of the user's associated cards. ### Method `getCards()` ### Response Details of the response depend on the API's return. Typically includes a list of user cards. ``` -------------------------------- ### Get Contact List Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of all contacts in the address book. ```APIDOC ## Get Contact List ### Description Retrieves a list of all contacts in the address book. ### Method `getList()` ### Response Details of the response depend on the API's return. Typically includes a list of contacts. ``` -------------------------------- ### Get List of Viber Campaigns Source: https://context7.com/smsaero/smsaero_api/llms.txt Retrieve a paginated list of all created Viber campaigns. The 'page' parameter controls which page of results to fetch. ```php $viber = new \SmsAero\SmsAeroViber('user@example.com', 'ваш_api_ключ'); $list = $viber->getList(['page' => 1]); if ($list['success']) { foreach ($list['data'] as $campaign) { echo 'ID: ' . $campaign['id'] . ', статус: ' . $campaign['status'] . PHP_EOL; } } ``` -------------------------------- ### Get All WhatsApp Messages Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of all WhatsApp messages with optional filtering and pagination. ```APIDOC ## Get All WhatsApp Messages ### Description Retrieves a list of all WhatsApp messages. ### Method `getAllMsg(array $params = [])` ### Parameters #### Query Parameters - **offset** (int) - Optional - Number of messages to skip. - **limit** (int) - Optional - Maximum number of messages to return. - **timeFrom** (int) - Optional - Unix timestamp to filter messages from. - **timeTo** (int) - Optional - Unix timestamp to filter messages until. ### Response Details of the response depend on the API's return. Typically includes a list of all WhatsApp messages. ``` -------------------------------- ### Get WhatsApp Dialogues and Messages Source: https://context7.com/smsaero/smsaero_api/llms.txt Retrieve lists of dialogues, messages from a specific dialogue, or all messages with time and address filtering. Use 'limit' and 'offset' for pagination. ```php $wa = new \SmsAero\SmsAeroWhatsapp('user@example.com', 'ваш_api_ключ'); // Открытые диалоги (status=1), по 50 за раз $chats = $wa->getChats(['status' => 1, 'limit' => 50, 'offset' => 0]); $chatId = $chats['data'][0]['id']; // Сообщения конкретного диалога $messages = $wa->getChatMsg($chatId); // Все сообщения за определённый период $all = $wa->getAllMsg([ 'timeFrom' => strtotime('2024-01-01'), 'timeTo' => strtotime('2024-01-31'), 'limit' => 100, 'offset' => 0, 'address' => '79991234567', ]); foreach ($all['data'] as $m) { echo '[' . date('d.m.Y H:i', $m['time']) . '] ' . $m['text'] . PHP_EOL; } ``` -------------------------------- ### Get WhatsApp Chats Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of WhatsApp conversations with optional filtering and pagination. ```APIDOC ## Get WhatsApp Chats ### Description Retrieves a list of WhatsApp conversations. ### Method `getChats(array $params = [])` ### Parameters #### Query Parameters - **status** (int) - Optional - Filter chats by status. - **offset** (int) - Optional - Number of chats to skip. - **limit** (int) - Optional - Maximum number of chats to return. ### Response Details of the response depend on the API's return. Typically includes a list of WhatsApp conversations. ``` -------------------------------- ### Get SMS List Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of all sent SMS messages. ```APIDOC ## Get SMS List ### Description Retrieves a list of all sent SMS messages. ### Method `getList()` ### Response Details of the response depend on the API's return. Typically includes a list of sent SMS messages with their details. ``` -------------------------------- ### Get Viber Message List Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of all Viber message broadcasts. ```APIDOC ## Get Viber Message List ### Description Retrieves a list of all Viber message broadcasts. ### Method `getList()` ### Response Details of the response depend on the API's return. Typically includes a list of Viber message broadcasts. ``` -------------------------------- ### Get WhatsApp Chat Messages Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of messages within a specific WhatsApp conversation. ```APIDOC ## Get WhatsApp Chat Messages ### Description Retrieves a list of messages within a specific WhatsApp conversation. ### Method `getChatMsg(string $chatId)` ### Parameters #### Path Parameters - **chatId** (string) - Required - The unique identifier of the WhatsApp chat. ### Response Details of the response depend on the API's return. Typically includes a list of messages for the specified chat. ``` -------------------------------- ### Get Available Viber Signs Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves a list of available sender names (signs) for Viber messages. ```APIDOC ## Get Available Viber Signs ### Description Retrieves a list of available sender names (signs) for Viber messages. ### Method `getSigns()` ### Response Details of the response depend on the API's return. Typically includes a list of approved sender names for Viber. ``` -------------------------------- ### Get List of Sent SMS Messages Source: https://context7.com/smsaero/smsaero_api/llms.txt Fetch a list of sent SMS messages using SmsAeroMessage::getList(). Supports filtering by phone number, text content, and pagination. Useful for reviewing message history. ```php $msg = new \SmsAero\SmsAeroMessage('user@example.com', 'ваш_api_ключ'); // Все сообщения (первая страница) $response = $msg->getList(); // Фильтрация по номеру и тексту $response = $msg->getList([ 'number' => '79991234567', 'text' => 'код подтверждения', 'page' => 2, ]); if ($response['success']) { foreach ($response['data'] as $sms) { echo $sms['id'] . ': ' . $sms['text'] . ' → ' . $sms['status'] . PHP_EOL; } } ``` -------------------------------- ### Manage Contact Groups: Create, Delete, and List Source: https://context7.com/smsaero/smsaero_api/llms.txt This code snippet demonstrates how to manage contact groups, including creating new groups with specified names, listing all existing groups with pagination, and deleting groups by their ID. Ensure the API key is correctly set. ```php $group = new \SmsAero\SmsAeroGroup('user@example.com', 'ваш_api_ключ'); // Создание группы $response = $group->create(['name' => 'Постоянные клиенты']); $groupId = $response['data']['id']; // Список всех групп (с пагинацией) $list = $group->getList(['page' => 1]); foreach ($list['data'] as $g) { echo $g['id'] . ': ' . $g['name'] . PHP_EOL; } // Удаление группы $group->delete($groupId); ``` -------------------------------- ### Manage User Profile: Balance, Tariffs, Cards, and Charging Source: https://context7.com/smsaero/smsaero_api/llms.txt This section provides methods to interact with the user's account, including fetching the current balance, retrieving available tariffs, listing associated bank cards, and charging the balance from a specified card. A valid API key is required. ```php $user = new \SmsAero\SmsAeroUser('user@example.com', 'ваш_api_ключ'); // Баланс $balance = $user->getBalance(); echo 'Баланс: ' . $balance['data']['balance'] . ' руб.' . PHP_EOL; // Тарифы $tariffs = $user->getTariffs(); print_r($tariffs['data']); // Список карт $cards = $user->getCards(); $cardId = $cards['data'][0]['id']; // Пополнение баланса на 500 рублей $charge = $user->charge(['cardId' => $cardId, 'sum' => 500]); if ($charge['success']) { echo 'Баланс пополнен на 500 руб.'; } ``` -------------------------------- ### Initialize and Send Telegram Message Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Instantiate the Telegram client and send a verification code. Ensure your email and API key are correctly configured. ```php $smsAeroTelegram = new \SmsAero\SmsAeroTelegram('Ваш E-mail на сайте', 'apiKey можно посмотреть в личном кабинете в разделе настройки -> API и SMPP'); // Отправка кода в Telegram $response = $smsAeroTelegram->send(['number' => 'номер абонента', 'code' => 1234]); ``` -------------------------------- ### Create Contact Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Adds a new contact to the address book. ```APIDOC ## Create Contact ### Description Adds a new contact to the address book. ### Method `create(array $params)` ### Parameters #### Request Body - **number** (string) - Required - The phone number of the contact. ### Request Example ```php $smsAeroContact->create(['number' => 'contact_number']); ``` ### Response Details of the response depend on the API's return. Typically confirms the creation of the contact. ``` -------------------------------- ### Charge Balance Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Initiates a balance charge using a specified card and amount. ```APIDOC ## Charge Balance ### Description Initiates a balance charge using a specified card and amount. ### Method `charge(array $params)` ### Parameters #### Request Body - **cardId** (string) - Required - The ID of the card to use for charging. - **sum** (float) - Required - The amount to charge. ### Request Example ```php $smsAeroUser->charge(['cardId' => 'your_card_id', 'sum' => 100.00]); ``` ### Response Details of the response depend on the API's return. Typically confirms the balance charge operation. ``` -------------------------------- ### Create Group Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Creates a new group for organizing contacts. ```APIDOC ## Create Group ### Description Creates a new group for organizing contacts. ### Method `create(array $params)` ### Parameters #### Request Body - **name** (string) - Required - The name of the new group. ### Request Example ```php $smsAeroGroup->create(['name' => 'new_group_name']); ``` ### Response Details of the response depend on the API's return. Typically confirms the creation of the group. ``` -------------------------------- ### SmsAeroViber::getList() Source: https://context7.com/smsaero/smsaero_api/llms.txt Retrieves a list of all created Viber broadcasts with pagination. ```APIDOC ## SmsAeroViber::getList() ### Description Returns a list of all created Viber broadcasts, supporting pagination. ### Method GET (assumed, as it retrieves data) ### Endpoint `/viber/list` (assumed) ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number to retrieve. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **data** (array) - An array of broadcast objects. - **id** (string) - The unique identifier for the broadcast. - **status** (string) - The current status of the broadcast. ``` -------------------------------- ### Get HLR Status Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves the status of an HLR check request using its ID. ```APIDOC ## Get HLR Status ### Description Retrieves the status of an HLR check request. ### Method `status(string $id)` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the HLR check request. ### Response Details of the response depend on the API's return. Typically includes the HLR status information. ``` -------------------------------- ### Initialize SMS Aero Telegram Client Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Initializes the SMS Aero Telegram client with your email and API key. ```APIDOC ## Initialize SMS Aero Telegram Client ### Description Initializes the SMS Aero Telegram client with your email and API key. ### Method ```php new \SmsAero\SmsAeroTelegram('Ваш E-mail на сайте', 'apiKey можно посмотреть в личном кабинете в разделе настройки -> API и SMPP'); ``` ``` -------------------------------- ### API Response Handling Source: https://context7.com/smsaero/smsaero_api/llms.txt This section explains the general structure of API responses returned by the SDK methods and provides a utility function for handling these responses, including success and error cases. ```APIDOC ## API Response Handling All SDK methods return an associative array. The `success` field contains a boolean result, `data` contains the payload on success, and `message` contains an error description on failure. ```php // Universal response handling pattern function handleResponse(array $response, string $action): void { if ($response['success']) { echo "[OK] {$action}" . PHP_EOL; print_r($response['data']); } else { echo "[ERR] {$action}: "; // $response['message'] can be a string or an array of validation errors if (is_array($response['message'])) { foreach ($response['message'] as $field => $errors) { echo " {$field}: " . implode(', ', (array)$errors) . PHP_EOL; } } else { echo $response['message'] . PHP_EOL; } } } $msg = new \SmsAero\SmsAeroMessage('user@example.com', 'your_api_key'); try { $response = $msg->send([ 'number' => '79991234567', 'text' => 'Test message', 'sign' => 'SMS Aero', ]); handleResponse($response, 'Sending SMS'); } catch (\Exception $e) { // Network error or curl unavailable echo 'Exception: ' . $e->getMessage(); } ``` ``` -------------------------------- ### Get Viber Message Statistics Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves statistics for a specific Viber message broadcast using its ID. ```APIDOC ## Get Viber Message Statistics ### Description Retrieves statistics for a specific Viber message broadcast. ### Method `getStat(string $id)` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the Viber message broadcast. ### Response Details of the response depend on the API's return. Typically includes statistics for the Viber message. ``` -------------------------------- ### SmsAeroWhatsapp::getChats() Source: https://context7.com/smsaero/smsaero_api/llms.txt Retrieves a list of open WhatsApp chats with pagination. ```APIDOC ## SmsAeroWhatsapp::getChats() ### Description Retrieves a list of open WhatsApp chats, with options for filtering and pagination. ### Method GET (assumed, as it retrieves data) ### Endpoint `/whatsapp/chats` (assumed) ### Parameters #### Query Parameters - **status** (integer) - Optional - Filter chats by status (e.g., 1 for open). - **limit** (integer) - Optional - Number of chats to return per page (default 50). - **offset** (integer) - Optional - Number of chats to skip for pagination. ### Response #### Success Response (200) - **data** (array) - An array of chat objects. - **id** (string) - The unique identifier for the chat. ``` -------------------------------- ### SmsAeroWhatsapp::send() Source: https://context7.com/smsaero/smsaero_api/llms.txt Sends text, media, and template messages via WhatsApp. Supports buttons of three types (QUICK_REPLY, URL, PHONE), headers (text, image, video, document), and captions. ```APIDOC ## SmsAeroWhatsapp::send() ### Description Sends text, media, and template messages via WhatsApp. Template messages support buttons of three types (`QUICK_REPLY`, `URL`, `PHONE`), a header (text, image, video, document), and a caption. ### Method POST (assumed, as it sends data) ### Endpoint `/whatsapp/send` (assumed) ### Parameters #### Request Body - **sign** (string) - Required - Sender signature. - **address** (string) - Required - Recipient phone number. - **contentType** (string) - Required - Type of content ('text', 'media', etc.). - **text** (string) - Required - Message text. - **header** (object) - Optional - Message header details (e.g., `imageUrl`). - **footer** (object) - Optional - Message footer text. - **buttons** (array) - Optional - Array of button objects, each with `buttonType`, `text`, and relevant URL or phone number. ### Request Example ```json { "sign": "МойМагазин", "address": "79991234567", "contentType": "text", "text": "Ваш заказ #4521 отправлен!", "header": {"imageUrl": "https://example.com/logo.png"}, "footer": {"text": "МойМагазин — лучшие цены"}, "buttons": [ {"buttonType": "URL", "text": "Перейти в каталог", "url": "https://example.com/catalog"}, {"buttonType": "PHONE", "text": "Позвонить нам", "phone": "+78005557550"} ] } ``` ### Response #### Success Response (200) - **data** (object) - Contains message details. - **id** (string) - The unique identifier for the sent message. ``` -------------------------------- ### Get Telegram Message Status Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Retrieves the status of a previously sent Telegram message using its ID. ```APIDOC ## Get Telegram Message Status ### Description Retrieves the status of a previously sent Telegram message using its ID. ### Method ```php $smsAeroTelegram->getStatus($id) ``` ``` -------------------------------- ### Manage User Profile with SMSAero PHP SDK Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Interact with user account details using the SmsAeroUser class. This includes checking balance, retrieving tariffs, managing user cards, and processing balance top-ups. ```php $response = $smsAeroUser = new \SmsAero\SmsAeroUser('Ваш E-mail на сайте', 'apiKey можно посмотреть в личном кабинете в разделе настройки -> API и SMPP'); // Запрос баланса $response = $smsAeroUser->getBalance(); // Запрос тарифа $response = $smsAeroUser->getTariffs(); // Карты пользователя $response = $smsAeroUser->getCards(); // Пополнение баланса $response = $smsAeroUser->charge(['cardId' => $cardId, 'sum' => $sum]); ``` -------------------------------- ### SmsAeroContact::create() - Add Contact Source: https://context7.com/smsaero/smsaero_api/llms.txt Creates a contact in the address book, supporting phone number, full name, gender, birthday, group, and custom parameters. ```APIDOC ## SmsAeroContact::create() ### Description Creates a contact in the address book. In addition to the phone number, it supports saving the full name, gender, birthday, group, and three custom user parameters. ### Method POST ### Endpoint /contact/create ### Parameters #### Request Body - **number** (string) - Required - The phone number of the contact. - **fname** (string) - Optional - The first name of the contact. - **lname** (string) - Optional - The last name of the contact. - **sname** (string) - Optional - The patronymic (middle name) of the contact. - **sex** (string) - Optional - The gender of the contact ('male' or 'female'). - **birthday** (integer) - Optional - The birthday of the contact in unixtime format. - **groupId** (integer) - Optional - The ID of the group to which the contact belongs. - **param1** (string) - Optional - A custom parameter. - **param2** (string) - Optional - A custom parameter. - **param3** (string) - Optional - A custom parameter. ### Request Example ```php $contact = new \SmsAero\SmsAeroContact('user@example.com', 'your_api_key'); $response = $contact->create([ 'number' => '79991234567', 'fname' => 'Ivan', 'lname' => 'Petrov', 'sname' => 'Sergeevich', 'sex' => 'male', 'birthday' => mktime(0, 0, 0, 5, 15, 1990), 'groupId' => 42, 'param1' => 'VIP-client', ]); ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **data** (object) - Contains the response data. - **id** (integer) - The ID of the created contact. #### Error Response - **success** (boolean) - Indicates if the operation was successful. - **message** (string) - Error message description. ``` -------------------------------- ### SmsAeroUser::getBalance(), getTariffs(), getCards(), charge() — User Profile Management Source: https://context7.com/smsaero/smsaero_api/llms.txt Provides methods for account management, including querying current balance and active tariff, retrieving a list of linked bank cards, and topping up the balance using a specified card. ```APIDOC ## SmsAeroUser::getBalance() / getTariffs() / getCards() / charge() ### Description Provides methods for account management: requesting current balance and active tariff, getting a list of linked bank cards, and topping up the balance from a specified card. ### Methods - `getBalance()`: Retrieves the current account balance. - `getTariffs()`: Retrieves the list of available tariffs. - `getCards()`: Retrieves a list of linked bank cards. - `charge(array $data)`: Tops up the account balance using a specified card. ### Parameters for charge #### Request Body - **cardId** (string) - Required - The ID of the card to use for charging. - **sum** (int) - Required - The amount to charge in the smallest currency unit (e.g., kopecks). ### Request Example (getBalance) ```php $user = new \SmsAero\SmsAeroUser('user@example.com', 'your_api_key'); $balance = $user->getBalance(); ``` ### Request Example (getTariffs) ```php $user = new \SmsAero\SmsAeroUser('user@example.com', 'your_api_key'); $tariffs = $user->getTariffs(); ``` ### Request Example (getCards) ```php $user = new \SmsAero\SmsAeroUser('user@example.com', 'your_api_key'); $cards = $user->getCards(); ``` ### Request Example (charge) ```php $user = new \SmsAero\SmsAeroUser('user@example.com', 'your_api_key'); $cardId = $cards['data'][0]['id']; // Assuming $cards is from getCards() $charge = $user->charge(['cardId' => $cardId, 'sum' => 500]); ``` ### Response Example (getBalance) ```json { "success": true, "data": { "balance": 1000.50 } } ``` ### Response Example (getTariffs) ```json { "success": true, "data": [ { "id": 1, "name": "Basic Tariff", "price": 500 } ] } ``` ### Response Example (getCards) ```json { "success": true, "data": [ { "id": "card_abc123", "last4": "1234", "type": "Visa" } ] } ``` ### Response Example (charge) ```json { "success": true } ``` ``` -------------------------------- ### Get SMS Message Status Source: https://context7.com/smsaero/smsaero_api/llms.txt Retrieve the current status of a specific SMS message using its ID with the SmsAeroMessage::getStatus() method. Possible statuses include 'in queue' (0), 'delivered' (1), and 'undelivered' (2). ```php $msg = new \SmsAero\SmsAeroMessage('user@example.com', 'ваш_api_ключ'); $response = $msg->getStatus(123456789); if ($response['success']) { // Возможные статусы: 0 — в очереди, 1 — доставлено, 2 — не доставлено и др. echo 'Статус сообщения: ' . $response['data']['status']; } ``` -------------------------------- ### SmsAeroViber::getSigns() Source: https://context7.com/smsaero/smsaero_api/llms.txt Retrieves a list of available sender signatures for Viber. ```APIDOC ## SmsAeroViber::getSigns() ### Description Retrieves a list of all available sender signatures that can be used for Viber messages. ### Method GET (assumed, as it retrieves data) ### Endpoint `/viber/signs` (assumed) ### Response #### Success Response (200) - **data** (array) - An array of available Viber sender signatures. ``` -------------------------------- ### SmsAeroMobileId: Send, GetStatus, Verify Source: https://context7.com/smsaero/smsaero_api/llms.txt Implement authorization via Mobile ID (silent verification with the operator without code entry). Send a request to the operator, receive the result at callbackUrl, then verify the code with verify(). ```php $mobileId = new \SmsAero\SmsAeroMobileId('user@example.com', 'ваш_api_ключ'); // Отправка запроса на авторизацию $response = $mobileId->send([ 'number' => '79991234567', 'sign' => 'МойСервис', 'callbackUrl' => 'https://example.com/mobile-id-callback', ]); $requestId = $response['data']['id']; // Проверка текущего статуса запроса $status = $mobileId->getStatus($requestId); echo 'Статус Mobile ID: ' . $status['data']['status'] . PHP_EOL; // Верификация кода, полученного через callback $verify = $mobileId->verify([ 'id' => $requestId, 'code' => 'код_из_callback', ]); if ($verify['success']) { echo 'Авторизация подтверждена'; } else { echo 'Ошибка верификации: '; print_r($verify['message']); } ``` -------------------------------- ### SmsAeroWhatsapp::getStatus() Source: https://context7.com/smsaero/smsaero_api/llms.txt Retrieves the delivery status of a WhatsApp message using its ID. ```APIDOC ## SmsAeroWhatsapp::getStatus() ### Description Retrieves the delivery status of a WhatsApp message using its unique message ID. ### Method GET (assumed, as it retrieves data) ### Endpoint `/whatsapp/status/{msgId}` (assumed, where {msgId} is the message ID) ### Parameters #### Path Parameters - **msgId** (string) - Required - The unique identifier of the message. ### Response #### Success Response (200) - **data** (object) - Contains status details. - **status** (string) - The current delivery status of the message. ``` -------------------------------- ### Manage Contacts with SMSAero PHP SDK Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Use the SmsAeroContact class to add, delete, and list contacts. It also supports managing blacklists, checking HLR status, and identifying mobile operators. ```php $smsAeroContact = new \SmsAero\SmsAeroContact('Ваш E-mail на сайте', 'apiKey можно посмотреть в личном кабинете в разделе настройки -> API и SMPP'); // Добавление контакта $response = $smsAeroContact->create(['number' => 'номер абонента']); // Удаление контакта $response = $smsAeroContact->delete($id); // Список контактов $response = $smsAeroContact->getList(); // Добавление в черный список $response = $smsAeroContact->toBlacklist(['number' => 'номер абонента']); // Удаление из черного списка $response = $smsAeroContact->deleteFromBlacklist($id); // Список контактов в черном списке $response = $smsAeroContact->getBlacklist(); // Создание запроса на проверку HLR $response = $smsAeroContact->check(['number' => 'номер абонента']); // Получение статуса HLR $response = $smsAeroContact->status($id); // Определение оператора $response = $smsAeroContact->getOperator(['number' => 'номер абонента']); ``` -------------------------------- ### Send WhatsApp Messages with SMSAero PHP SDK Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Utilize the SmsAeroWhatsapp class for sending WhatsApp messages. Supports text, template messages with buttons, headers, and footers. Also includes functions to check status and manage chats. ```php $response = $smsAeroWhatsapp = new \SmsAero\SmsAeroWhatsapp('Ваш E-mail на сайте', 'apiKey можно посмотреть в личном кабинете в разделе настройки -> API и SMPP'); // Отправка WhatsApp-сообщений $response = $smsAeroWhatsapp->send([ 'sign' => 'ваша одобренная подпись', 'address' => 'номер абонента', 'contentType' => 'text', 'text' => 'текст сообщения', // Параметры ниже поддерживаются только для шаблонных сообщений 'buttons' => [ [ 'buttonType' => 'URL', 'text' => 'Как начать работу?', 'url' => 'ссылка для кнопки' ], [ 'buttonType' => 'PHONE', 'text' => 'Позвонить', 'phone' => '+78005557550' ] ], 'header' => [ 'imageUrl' => 'ссылка на изображения' ], 'footer' => [ 'text' => 'текст подписи для сообщения' ] ]); // Проверка статуса Whatsapp сообщения $response = $smsAeroWhatsapp->getStatus('ID сообщения, который вернул сервис при отправке'); // Получение списка диалогов $response = $smsAeroWhatsapp->getChats(['status' => 1, 'offset' => 100, 'limit' => 100]); // Список сообщений по диалогу $response = $smsAeroWhatsapp->getChatMsg('Идентификатор диалога, который вернул сервис при получении списка диалогов'); // Список всех сообщений $response = $smsAeroWhatsapp->getAllMsg(['offset' => 100, 'limit' => 100, 'timeFrom' => 1672527600, 'timeTo' => 1701385200]); ``` -------------------------------- ### Manage Contacts: Delete and List with Filters Source: https://context7.com/smsaero/smsaero_api/llms.txt Use this to delete a contact by ID or retrieve a list of contacts filtered by number, group, gender, operator, or full name. Ensure you have the correct API key. ```php $contact = new \SmsAero\SmsAeroContact('user@example.com', 'ваш_api_ключ'); // Получение списка с фильтрами $response = $contact->getList([ 'sex' => 'female', 'operator' => 'MTS', // MEGAFON, MTS, BEELINE, TELE2, OTHER 'groupId' => 42, ]); foreach ($response['data'] as $c) { echo $c['number'] . ' — ' . $c['fname'] . PHP_EOL; } // Удаление контакта $deleteResponse = $contact->delete(123); if ($deleteResponse['success']) { echo 'Контакт удалён'; } ``` -------------------------------- ### Manage Groups with SMSAero PHP SDK Source: https://github.com/smsaero/smsaero_api/blob/main/README.md The SmsAeroGroup class allows you to create, delete, and retrieve a list of contact groups. Use this to organize your contacts effectively. ```php $smsAeroGroup = new \SmsAero\SmsAeroGroup('Ваш E-mail на сайте', 'apiKey можно посмотреть в личном кабинете в разделе настройки -> API и SMPP'); // Добавление группы $response = $smsAeroGroup->create(['name' => 'название новой группы']); // Удаление группы $response = $smsAeroGroup->delete($id); // Получение списка групп $response = $smsAeroGroup->getList(); ``` -------------------------------- ### Send WhatsApp Messages Source: https://context7.com/smsaero/smsaero_api/llms.txt Use this method to send text, media, and template messages via WhatsApp. Template messages support various button types, headers, and footers. ```php $wa = new \SmsAero\SmsAeroWhatsapp('user@example.com', 'ваш_api_ключ'); // Простое текстовое сообщение $response = $wa->send([ 'sign' => 'МойМагазин', 'address' => '79991234567', 'contentType' => 'text', 'text' => 'Ваш заказ #4521 отправлен!', ]); // Шаблонное сообщение с кнопками и заголовком $response = $wa->send([ 'sign' => 'МойМагазин', 'address' => '79991234567', 'contentType' => 'text', 'text' => 'Добро пожаловать! Выберите действие:', 'header' => ['imageUrl' => 'https://example.com/logo.png'], 'footer' => ['text' => 'МойМагазин — лучшие цены'], 'buttons' => [ ['buttonType' => 'URL', 'text' => 'Перейти в каталог', 'url' => 'https://example.com/catalog'], ['buttonType' => 'PHONE', 'text' => 'Позвонить нам', 'phone' => '+78005557550'], ], ]); $msgId = $response['data']['id']; // Проверка статуса $status = $wa->getStatus($msgId); echo 'Статус WA: ' . $status['data']['status']; ``` -------------------------------- ### API Response Handling Pattern Source: https://context7.com/smsaero/smsaero_api/llms.txt A universal pattern for handling API responses. The 'success' field contains a boolean result, 'data' is the payload on success, and 'message' describes errors on failure. Handles both string and array error messages. ```php // Универсальный паттерн обработки ответа function handleResponse(array $response, string $action): void { if ($response['success']) { echo "[OK] {$action}" . PHP_EOL; print_r($response['data']); } else { echo "[ERR] {$action}: "; // $response['message'] может быть строкой или массивом ошибок валидации if (is_array($response['message'])) { foreach ($response['message'] as $field => $errors) { echo " {$field}: " . implode(', ', (array)$errors) . PHP_EOL; } } else { echo $response['message'] . PHP_EOL; } } } $msg = new \SmsAero\SmsAeroMessage('user@example.com', 'ваш_api_ключ'); try { $response = $msg->send([ 'number' => '79991234567', 'text' => 'Тестовое сообщение', 'sign' => 'SMS Aero', ]); handleResponse($response, 'Отправка SMS'); } catch (\Exception $e) { // Сетевая ошибка или curl недоступен echo 'Исключение: ' . $e->getMessage(); } ``` -------------------------------- ### Send SMS Messages with SMSAero PHP SDK Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Initialize the SmsAeroMessage class with your email and API key to send SMS messages. You can also check message status or retrieve a list of sent messages. ```php $smsAeroMessage = new \SmsAero\SmsAeroMessage('Ваш E-mail на сайте', 'apiKey можно посмотреть в личном кабинете в разделе настройки -> API и SMPP'); // Отправка SMS сообщений $response = $smsAeroMessage->send(['number' => 'номер абонента', 'text' => 'текст сообщения', 'sign' => 'подпись отправителя(можно получить в личном кабинете smsaero.ru или использовать подпись: SMS Aero)']); // Проверка статуса SMS сообщения $response = $smsAeroMessage->getStatus($id); // Получение списка отправленных сообщений $response = $smsAeroMessage->getList(); ``` -------------------------------- ### SmsAeroMobileId Authorization Source: https://context7.com/smsaero/smsaero_api/llms.txt This section covers the Mobile ID authorization flow using the SmsAero PHP SDK. It includes sending an authorization request, checking its status, and verifying the authorization code. ```APIDOC ## SmsAeroMobileId::send() / getStatus() / verify() Implements authorization via Mobile ID (silent subscriber verification with the operator without entering a code). A request is sent to the operator, the result arrives at `callbackUrl`, after which the code is verified using the `verify()` method. ```php $mobileId = new \SmsAero\SmsAeroMobileId('user@example.com', 'your_api_key'); // Sending an authorization request $response = $mobileId->send([ 'number' => '79991234567', 'sign' => 'MyService', 'callbackUrl' => 'https://example.com/mobile-id-callback', ]); $requestId = $response['data']['id']; // Checking the current request status $status = $mobileId->getStatus($requestId); echo 'Mobile ID Status: ' . $status['data']['status'] . PHP_EOL; // Verifying the code received via callback $verify = $mobileId->verify([ 'id' => $requestId, 'code' => 'code_from_callback', ]); if ($verify['success']) { echo 'Authorization confirmed'; } else { echo 'Verification error: '; print_r($verify['message']); } ``` ``` -------------------------------- ### SmsAeroGroup::create(), delete(), getList() — Group Management Source: https://context7.com/smsaero/smsaero_api/llms.txt Allows for the creation, deletion, and listing of contact groups, which are used for targeted mass mailings. ```APIDOC ## SmsAeroGroup::create() / delete() / getList() ### Description Creates, deletes, and lists contact groups. Groups are used for mass mailings to audience segments. ### Methods - `create(array $data)`: Creates a new contact group. - `delete(int $id)`: Deletes a group by its ID. - `getList(array $params = [])`: Retrieves a list of all groups. ### Parameters for create #### Request Body - **name** (string) - Required - The name of the group to create. ### Parameters for delete #### Path Parameters - **id** (int) - Required - The ID of the group to delete. ### Parameters for getList #### Query Parameters - **page** (int) - Optional - The page number for pagination. ### Request Example (create) ```php $group = new \SmsAero\SmsAeroGroup('user@example.com', 'your_api_key'); $response = $group->create(['name' => 'Permanent Clients']); $groupId = $response['data']['id']; ``` ### Request Example (getList) ```php $group = new \SmsAero\SmsAeroGroup('user@example.com', 'your_api_key'); $list = $group->getList(['page' => 1]); ``` ### Request Example (delete) ```php $group = new \SmsAero\SmsAeroGroup('user@example.com', 'your_api_key'); $group->delete($groupId); ``` ### Response Example (create) ```json { "success": true, "data": { "id": 1, "name": "Permanent Clients" } } ``` ### Response Example (getList) ```json { "success": true, "data": [ { "id": 1, "name": "Permanent Clients" } ] } ``` ### Response Example (delete) ```json { "success": true } ``` ``` -------------------------------- ### Send WhatsApp Message Source: https://github.com/smsaero/smsaero_api/blob/main/README.md Sends a WhatsApp message. Supports text, template messages with buttons, headers, and footers. ```APIDOC ## Send WhatsApp Message ### Description Sends a WhatsApp message. Supports text, template messages with buttons, headers, and footers. ### Method `send(array $params)` ### Parameters #### Request Body - **sign** (string) - Required - Your approved sender signature. - **address** (string) - Required - The recipient's phone number. - **contentType** (string) - Required - Type of content, e.g., 'text'. - **text** (string) - Required - The message text. - **buttons** (array) - Optional - Array of buttons for template messages. Each button can have `buttonType`, `text`, and `url` or `phone`. - **header** (array) - Optional - Header for template messages, can include `imageUrl`. - **footer** (array) - Optional - Footer for template messages, can include `text`. ### Request Example ```php $smsAeroWhatsapp->send([ 'sign' => 'your_signature', 'address' => 'recipient_number', 'contentType' => 'text', 'text' => 'Your message here', 'buttons' => [ ['buttonType' => 'URL', 'text' => 'Learn More', 'url' => 'https://example.com'] ] ]); ``` ### Response Details of the response depend on the API's return. Typically includes status and message ID. ```