PHP code example of quince / kavenegar-client

1. Go to this page and download the library: Download quince/kavenegar-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/ */

    

quince / kavenegar-client example snippets




$apiKey = '{API_KEY}';
$senderNumber = '10004346';

$client = Quince\kavenegar\ClientBuilder::build($apiKey, $senderNumber);

$client->send('09123456789', 'سلام چطوری؟');

use Quince\kavenegar\Client;

class SmsController extend Controller
{

    protected $client;
    
    public function __construct(Client $client)
    {
        $this->client = $client
    }
    
    public function send()
    {
        $this->client->send('09123456789', 'سلام جطوری؟');
    }
    
}

// Send a message to `09123456789` in 4/9/2016, 1:00:43 AM
$client->send('09123456789', 'The text to send', 1460147443, 0, '12', '30004346');

// Send a message to multiple receptors
$client->send(['09123456789', '09356789124', '09213456789'], 'The text to send', 1460147443, 0, '12', '30004346');

// Send multiple message to multiple receptor
$client->bulkSend(
    ['09123456789', '09356789124', '09213456789'],
    ['Text to send to 09123456789', 'Text to send to 09367891245', 'Text to send to 09213456789'],
    1460147443,
    [0, 1, 2],
    ['12', '13', '14'],
    ['10004346', '20004346', '30004346']
);

// Get delivery status of a message
$client->getMessageStatus('8792343');

// Get delivery status of multiple messages
$client->getMessageStatus(['8792343', '8792344', '8792345']);

// Get delivery status of a message
$client->getMessageStatus('13');

// Get delivery status of multiple messages
$client->getMessageStatus(['13', '14', '15']);

// Get details of a message
$client->getMessageDetail('8792343');

// Get details of multiple messages
$client->getMessageDetail(['8792343', '8792344', '8792345']);

// Get outbox messages sent between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getOutbox(1460140000, 1460147443, 0);

// Get 20 latest sent messages from all sender numbers
$client->getRecentOutbox(20, 0);

// Get outbox messages count between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getOutboxCount(1460140000, 1460147443, 0);

// Cancel sending of message with id of 8792343
$client->cancelMessage('8792343');

// Get all unread messages sent to all lines
$client->getInbox(false, 0);

// Get inbox messages count between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getInboxCount(1460140000, 1460147443, 0, false);

// Get phone count in 11252 postal code area
$client->phoneCountByPostalCode('11252');

// Send a message to all MCI phones and 1000 random MTN phones in 11252 postal code area
// scheduled to send in 4/9/2016, 1:00:43 AM with sender number of 30004346
$client->sendByPostalCode(
    '11252',
    'Testing send by postal code',
    0,
    0,
    -1,
    1000,
    1460147443,
    '30004346'
);

// Get info of current account
$client->getAccountInfo();

// Get current account configuration
$client->getAccountConfigs();

// Enable apilogs and daily reports
// and set default sender to 30004346
// and disable resend when failing to send a message
$client->setAccountConfigs([
    'apilogs'       => 'enabled',
    'dailyreport'   => 'enabled',
    'defaultsender' => '30004346',
    'resendfailed'  => 'disabled'
]);

// send a code to 09123456789 with licence_template template
$client->sendVerificationCode('09123456789', 'EA-958423', 'licence_template');

php artisan vendor:publish --provider="Quince\kavenegar\Providers\ServiceProvider"