PHP code example of justcommunication-ru / wiracle-api-php-sdk

1. Go to this page and download the library: Download justcommunication-ru/wiracle-api-php-sdk 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/ */

    

justcommunication-ru / wiracle-api-php-sdk example snippets


$client = new WiracleClient('email', 'token');

$token = WiracleClient::getToken($email, $password);

print_r($token);

$account = $client->getAccount();

print_r($account);

$response = $client->sendChannelsRequest(new ChannelsRequest($profile_id));

print_r($response->getChannels());

$response = $client->sendChannelsAvailableRequest(new ChannelsAvailableRequest($profile_id));

print_r($response->getProfiles());

$response = $client->sendMessageCreateRequest(MessageCreateRequest::withPlainText($profile_id, $channel_id, $text));

// идентификатор нового сообщения
print_r($response->getId());

// $width, $height не обязательные поля
$response = $client->sendMessageCreateRequest(MessageCreateRequest::withImage($profile_id, $channel_id, $src, $width, $height));

// идентификатор нового сообщения
print_r($response->getId());

$message = new Message([
    new HeaderPart('Header'),
    new TextPart('Text')
]);

$message
    ->addPart(new ImagePart('https://wiracle.ru/images/app_banner/512x512.png', 512, 512))
    ->addPart(new CutlinePart())
    ->addPart(new TextPart('Text 2'))
;

$response = $client->sendMessageCreateRequest(MessageCreateRequest::withMessage($profile_id, $channel_id, $message));

// идентификатор нового сообщения
print_r($response->getId());

try {
    $client->sendMessageCreateRequest(MessageCreateRequest::withPlainText($profile_id, $channel_id, $text));
} catch (WiracleAPIException $e) {
    $logger->error('Wiracle ERROR: ' . $e->getMessage());
}

$client = new WiracleClient('email', 'token', [
    'proxy' => 'tcp://localhost:8125',
    'timeout' => 6,
    'connect_timeout' => 4
]);

// Http клиент с логгированием всех запросов

$stack = HandlerStack::create();
$stack->push(Middleware::log($logger, new MessageFormatter(MessageFormatter::DEBUG)));

$httpClient = new \GuzzleHttp\Client([
    'handler' => $stack,
    'timeout' => 6
]);

$client = new WiracleClient('email', 'token', $httpClient);

$client = new WiracleClient('email', 'token');
$client->setHttpClient($httpClient);

$client->setLogger($someLogger);