Execute: composer require smsapi/php-client
Depending on which of SMSAPI service your account is, you should pick it calling one of a method from examples below:
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
$apiToken = '0000000000000000000000000000000000000000';
$service = (new SmsapiHttpClient())
->smsapiComService($apiToken);
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
$apiToken = '0000000000000000000000000000000000000000';
$service = (new SmsapiHttpClient())
->smsapiPlService($apiToken);
All following examples consider you have a account on SMSAPI.COM.
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
$apiToken = '0000000000000000000000000000000000000000';
$uri = 'http://example.com';
$service = (new SmsapiHttpClient())
->smsapiComServiceWithUri($apiToken, $uri);
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
$apiToken = '0000000000000000000000000000000000000000';
$service = (new SmsapiHttpClient())
->smsapiComService($apiToken);
$result = $service->pingFeature()
->ping();
if ($result->smsapi) {
echo 'SMSAPI active';
} else {
echo 'SMSAPI not active';
}
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
use Smsapi\Client\Feature\Sms\Bag\SendSmsBag;
$apiToken = '0000000000000000000000000000000000000000';
$sms = SendSmsBag::withMessage('someone phone number', 'some message');
$service = (new SmsapiHttpClient())
->smsapiComService($apiToken);
$service->smsFeature()
->sendSms($sms);
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
use Smsapi\Client\Feature\Sms\Bag\SendSmsBag;
$apiToken = '0000000000000000000000000000000000000000';
$sms = SendSmsBag::withMessage('someone phone number', 'some message');
$sms->from = 'Test';
$service = (new SmsapiHttpClient())
->smsapiComService($apiToken);
$service->smsFeature()
->sendSms($sms);
For more usage examples take a look at client test suite.
Request parameters are represented in a form of data transfer object. DTOs can be found by searching for 'bag' postfixed classes. Each bag may contain required and optional parameters. Required parameters are that class public properties, usually accessible via some form of a setter or named constructor. Optional parameters are described by docblock's '@property' annotation.
Each parameter can be also set directly by setting bag property, as in example:
<?php
declare(strict_types=1);
use Smsapi\Client\Feature\Sms\Bag\SendSmsBag;
$sms = SendSmsBag::withMessage('someone phone number', 'some message');
$sms->encoding = 'utf-8';
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
$proxyUrl = 'https://example.org';
(new SmsapiHttpClient())->setProxy($proxyUrl);
Set logger to SmsapiHttpClient
instance.
<?php
declare(strict_types=1);
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
require_once 'vendor/autoload.php';
use Smsapi\Client\SmsapiHttpClient;
$logger = new class() implements LoggerInterface
{
use LoggerTrait;
public function log($level, $message, array $context = [])
{
var_dump($level, $message, $context);
}
};
(new SmsapiHttpClient())->setLogger($logger);
- Download package:
composer create-project smsapi/php-client
- Execute tests:
./vendor/bin/phing