Vigiar
1
0
Derivar
Você já tinha feito uma derivação do repositório api-php-sdk, anteriormente
0
api-php-sdk/examples/ping-account-sms.php
2026-11-27 22:29:26 +02:00

30 linhas
1,2 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/../autoload.php'; // with Composer: require 'vendor/autoload.php';
use MozOutMz\Client;
use MozOutMz\ApiException;
// Key from MOZOUT_API_KEY.
$client = new Client();
// Quick check: ping, account and one SMS in Sandbox (only with a sandbox_ key).
try {
$ping = $client->status->pingGet();
echo 'ping: ', $ping['data']['status'], ' ', $ping['data']['version'], "\n";
$client->account->get();
echo 'account: OK, mode ', $client->lastResponse['mode'], "\n";
$key = (string) (getenv(Client::envVarFor($client->brand)) ?: getenv('API_CENTER_KEY'));
if (strpos($key, 'sandbox_') !== 0) {
echo "SMS skipped: this example only sends with a sandbox_ key.\n";
} else {
$sms = $client->sms->messagesCreate(['number' => '+258841234567', 'text' => 'Test from the PHP SDK.']);
echo 'sms: ', $sms['data']['status'] ?? '?', ' simulated: ', $client->lastResponse['simulated'] ? 'true' : 'false', "\n";
}
} catch (ApiException $e) {
echo 'API error: ', $e->getStatus(), ' ', $e->getApiCode(), ' ', $e->getMessage(), ' correlation: ', $e->getCorrelationId(), "\n";
exit(1);
}