PHP code example of asanak / php-sms-client

1. Go to this page and download the library: Download asanak/php-sms-client 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/ */

    

asanak / php-sms-client example snippets


use Asanak\SmsClient;
use Asanak\SmsConfig;

$config = new SmsConfig([
    'base_url' => 'https://sms.asanak.ir'
]);
$sms = new SmsClient('your-username', 'your-password', $config);

try {
    $data = $sms->sendSms(
        source: '9821XXXXX',
        destination: '09120000000',
        message: 'کد فعالسازی شما 123456 می‌باشد.',
        send_to_black_list: false
    );
    // $data is message ids list
} catch(\Throwable $th) {
    echo $th->getMessage();
}

try{
    $data = $sms->p2p(
        source: ['9821X1', '9821X2'],
        destination: ['0912XXXX1', '0912XXXX2'],
        message: ['متن پیامک شماره یک', 'متن پیامک شماره دو'],
        send_to_black_list: [false, true]
    );
    $messageIds = array_column($data, 'messageId');
} catch(\Throwable $th) {
    echo $th->getMessage();
}

try{
    $data = $sms->template(
        template_id: 101,
        parameters: ['code' => 123456],
        destination: '09120000000',
        send_to_black_list: false
    );
    // $data is message ids list
} catch(\Throwable $th) {
    echo $th->getMessage();
}

$response = $sms->msgStatus(['12345678', '12345679']);

try {
    $data = $sms->getCredit();
    $credit = $data['credit'] ?? null;
} catch(\Throwable $th) {
    echo $th->getMessage();
}

try {
    $data = $sms->getRialCredit();
    $credit = $data['credit'] ?? null;
} catch(\Throwable $th) {
    echo $th->getMessage();
}

try {
    $templates = $sms->getTemplates();
} catch(\Throwable $th) {
    echo $th->getMessage();
}


use Asanak\SmsClient;
use Asanak\SmsConfig;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('sms-client');
$logger->pushHandler(new StreamHandler(__DIR__.'/sms.log'));

$config = new SmsConfig([
    'base_url' => 'https://sms.asanak.ir'
]);
$sms = new SmsClient('username', 'password', $config, $logger);
bash
composer