PHP code example of fruitware / prostor-sms-php-sdk
1. Go to this page and download the library: Download fruitware/prostor-sms-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/ */
fruitware / prostor-sms-php-sdk example snippets
use Fruitware\ProstorSms\Client;
use GuzzleHttp\Client as GuzzleClient;
//set basic access authentication
$options = [
'defaults' => [
'auth' => ['username', 'password'],
],
];
$smsGate = new Client(new GuzzleClient($options));
use GuzzleHttp\Subscriber\Log\Formatter;
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$log = new Logger('maib_guzzle_request');
$log->pushHandler(new StreamHandler(__DIR__.'/logs/prostor_sms_guzzle_request.log', Logger::DEBUG));
$subscriber = new LogSubscriber($log, Formatter::SHORT);
$smsGate->getHttpClient()->getEmitter()->attach($subscriber);
use Fruitware\ProstorSms\Model\Sms;
use Fruitware\ProstorSms\Exception\BadSmsStatusException;
$sms = new Sms();
$sms
->setId(unique()) // id sms в вашей системе
->setPhone('+71234567890')
->setText('тест sms')
;
try {
$smsGate->send($sms);
}
catch (BadSmsStatusException $ex) {
// что-то сделать с ошибкой
}
var_dump('sms', $sms);
$sms = new Sms();
$sms
->setId(unique()) // id sms в вашей системе
->setPhone('+71234567890')
->setText('тест sms')
->sender('TEST') // Подпись отправителя (например TEST)
;
// Название очереди статусов отправленных сообщений
$queueName = 'myQueue1';
// Дата для отложенной отправки сообщения
$scheduleTime = (new \DateTime())->modify('+1 day');
$smsCollection = $smsGate->sendQueue([$sms, $sms], $queueName, $scheduleTime);
foreach ($smsCollection as $sms) {
if ($sms->getStatus() !== $sms::STATUS_ACCEPTED) {
// что-то сделать с ошибкой
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.