PHP code example of gosms-ge / sms-sdk

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

    

gosms-ge / sms-sdk example snippets




use GoSmsGe\SmsSDK\GoSmsClient;

$client = new GoSmsClient('your-api-key');

// Send SMS
$response = $client->sendSms('MYBRAND', '995555123456', 'Hello!');
echo $response->messageId; // 12345
echo $response->balance;   // 4999

$response = $client->sendSms('MYBRAND', '995555123456', 'Hello!');

// With urgent flag
$response = $client->sendSms('MYBRAND', '995555123456', 'Urgent!', true);

$response->success;       // bool
$response->messageId;     // int
$response->from;          // string
$response->to;            // string
$response->text;          // string
$response->sendAt;        // string (ISO 8601)
$response->balance;       // int
$response->encode;        // "default" or "Unicode"
$response->segment;       // int
$response->smsCharacters; // int

$response = $client->sendBulkSms(
    'MYBRAND',
    ['995555111111', '995555222222', '995555333333'],
    'Sale today!'
);

$response->totalCount;   // 3
$response->successCount; // 3
$response->failedCount;  // 0

foreach ($response->messages as $msg) {
    echo $msg->messageId . ' -> ' . $msg->to;
    if (!$msg->success) {
        echo ' FAILED: ' . $msg->error;
    }
}

$response = $client->checkSms(12345);

$response->status; // "IN_PROGRESS", "DELIVERED", "REJECTED", "EXPIRED", "QUEUE", "ENROUTE"

$response = $client->getBalance();

$response->balance; // 5000

$response = $client->sendOtp('995555123456');

$response->hash;    // "abc123..." — save this for verification
$response->balance; // 4999

// Rate limit info
if ($response->rateLimitInfo) {
    echo $response->rateLimitInfo->remaining; // 9
    echo $response->rateLimitInfo->limit;     // 10
}

$response = $client->verifyOtp('995555123456', $hash, '1234');

if ($response->verify) {
    echo 'OTP verified!';
} else {
    echo 'Wrong code';
}

// Rate limit info
if ($response->rateLimitInfo) {
    echo $response->rateLimitInfo->remaining; // 8
}

$response = $client->createSender('NewBrand');

$response->success; // true

use GoSmsGe\SmsSDK\Exception\ApiException;
use GoSmsGe\SmsSDK\Exception\InsufficientBalanceException;
use GoSmsGe\SmsSDK\Exception\InvalidPhoneException;
use GoSmsGe\SmsSDK\Exception\NetworkException;

try {
    $client->sendSms('MYBRAND', '995555123456', 'Hello!');
} catch (InsufficientBalanceException $e) {
    // Handle low balance
} catch (InvalidPhoneException $e) {
    // Handle bad phone number
} catch (ApiException $e) {
    // Catch-all for any API error
    echo $e->getErrorCode();    // int (100-113)
    echo $e->getErrorMessage(); // string
} catch (NetworkException $e) {
    // Transport failure or invalid JSON response
}

use GoSmsGe\SmsSDK\Exception\TooManyRequestsException;
use GoSmsGe\SmsSDK\Exception\AccountLockedException;

try {
    $response = $client->sendOtp('995555123456');
} catch (TooManyRequestsException $e) {
    echo 'Too many attempts. Retry after ' . $e->getRetryAfter() . 's';
} catch (AccountLockedException $e) {
    echo 'Account locked. Retry after ' . $e->getRetryAfter() . 's';
}

use GoSmsGe\SmsSDK\GoSmsClient;
use GuzzleHttp\Client as Guzzle;

$guzzle = new Guzzle(['timeout' => 10]);

$client = new GoSmsClient(
    'your-api-key',
    'https://api.gosms.ge',
    $guzzle
);

$client = new GoSmsClient('your-api-key', 'https://your-custom-endpoint.com');

// In AppServiceProvider::register()
$this->app->singleton(GoSmsClient::class, function () {
    return new GoSmsClient(config('services.gosms.api_key'));
});

// In your controller
public function send(GoSmsClient $gosms)
{
    $gosms->sendSms('MYBRAND', $request->phone, 'Your code is 1234');
}