PHP code example of waix / waix-php

1. Go to this page and download the library: Download waix/waix-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

waix / waix-php example snippets



x = new Waix\Client(getenv('WAIX_API_KEY'));
// $eventId — UUID, уже сохранённый в записи заказа или очереди уведомлений.
$result = $waix->messages->send([
    'connection_id' => getenv('WAIX_CONNECTION_ID'),
    'to' => '+77071234567',
    'type' => 'template',
    'template' => [
        'name' => 'order_ready',
        'language' => ['code' => 'ru'],
        'components' => [['type' => 'body', 'parameters' => [['type' => 'text', 'text' => '42']]]],
    ],
], $eventId);

$otp = new Waix\Client(getenv('WAIX_OTP_PROJECT_KEY'));
$sent = $otp->otp->send(['to' => '+77071234567', 'ttl' => 300], $eventId);
// Сохраните $sent['data']['id'] в серверной сессии пользователя.
$status = $otp->otp->status($sent['data']['id']);
// $suppliedCode — код, введённый пользователем в той же сессии.
$verified = $otp->otp->verify($sent['data']['id'], $suppliedCode);

$waix = new Waix\Client(getenv('WAIX_API_KEY'), timeoutMs: 30000);

$waix = new Waix\Client(getenv('WAIX_API_KEY'), timeoutMs: 30000, maxResponseBytes: 2097152);
foreach ($waix->messages->iterate(['connection_id' => $connectionId, 'limit' => 100], maxPages: 100) as $message) {
    saveStatus($message['id'], $message['status']);
}

try {
    $result = $waix->messages->get($savedMessageId);
} catch (Waix\WaixError $error) {
    error_log(json_encode($error, JSON_THROW_ON_ERROR)); // только безопасные метаданные
    $delayMs = $error->retryDelayMs(); // миллисекунды или null
    // Решение о повторе принимает ваша очередь.
}
sh
composer