PHP SDK
Installation
Using Composer is the recommended way to install the Unimatrix SDK for PHP, which is available on Packagist.
Run the following command to add unimtx/uni-sdk
as a dependency to your project:
composer require unimtx/uni-sdk
Usage
The following example shows how to use the Unimatrix PHP SDK to interact with Unimatrix services.
Send SMS
Send a text message to a single recipient.
use Uni\UniClient;
use Uni\UniException;
// initialization
$client = new UniClient([
'accessKeyId' => 'your access key id',
'accessKeySecret' => 'your access key secret' // if you use the simple auth mode, just delete this line
]);
// send the message
try {
$resp = $client->messages->send([
'to' => 'your phone number', // in E.164 format
'text' => 'Your verification code is 2048.'
]);
var_dump($resp->data);
} catch (UniException $e) {
print_r($e);
}
Send a message using a template with variables.
$client->messages->send([
'to' => '+1650253xxxx',
'signature' => 'Unimatrix',
'templateId' => 'pub_verif_en_basic2',
'templateData' => [
'code' => '2048'
]
]);