1. Go to this page and download the library: Download honkio/honkio-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/ */
honkio / honkio-php example snippets
use Honkio\Exception\ApiException;
use Honkio\Honkio;
$honkio = new Honkio(getenv('HONKIO_API_KEY'));
try {
$message = $honkio->messages->send([
'from' => '+1416XXXXXXX', // one of your HonkIO numbers
'to' => '+1613XXXXXXX', // a Canadian number you hold consent for
'body' => 'Hello from HonkIO!',
], idempotencyKey: 'order-1042');
echo $message['id'], ' ', $message['status'], "\n";
} catch (ApiException $e) {
echo $e->errorCode, ': ', $e->getMessage(), "\n"; // e.g. NO_CONSENT
}
$honkio = new Honkio($key, ['max_retries' => 4, 'max_retry_delay' => 30]);
$noRetries = new Honkio($key, ['max_retries' => 0]);
$limits = $honkio->sendLimit->get();
echo $limits['remaining'], ' of ', $limits['daily_limit'], " left today\n";
foreach ($limits['number_queues'] as $queue) {
// parts_per_minute is 10 for a local number; clears_at is null when nothing is waiting.
echo $queue['phone_number'], ' ', $queue['queued_parts'], ' ', $queue['parts_per_minute'], ' ', $queue['clears_at'] ?? '-', "\n";
}
use Honkio\Exception\SignatureVerificationException;
use Honkio\Webhook;
$rawBody = file_get_contents('php://input');
try {
$event = Webhook::verify($rawBody, getallheaders(), getenv('HONKIO_WEBHOOK_SECRET'));
} catch (SignatureVerificationException $e) {
http_response_code(400);
exit;
}
if ($event['type'] === 'message.delivered') {
// ...
}
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
$mock = new MockHandler([new Response(200, ['Content-Type' => 'application/json'], '{"id":"msg_1"}')]);
$honkio = new Honkio\Honkio('test-key', ['http_client' => new Client(['handler' => HandlerStack::create($mock)])]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.