PHP code example of macellan / netgsm

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

    

macellan / netgsm example snippets


// config/services.php
...
    'sms' => [
        'netgsm' => [
            'username' => env('NETGSM_USERNAME', ''),
            'password' => env('NETGSM_PASSWORD', ''),
            'header' => env('NETGSM_HEADER', ''),
            'language' => env('NETGSM_LANGUAGE', 'tr'),
            'enable' => env('NETGSM_ENABLE', false),
            'debug' => env('NETGSM_DEBUG', false), // Will log sending attempts and results
            'sandbox_mode' => env('NETGSM_SANDBOX_MODE', false), // Will not invoke API call
        ],
    ],
...

use Illuminate\Notifications\Notification;
use Macellan\Netgsm\DTO\Sms\BaseSmsMessage;
use Macellan\Netgsm\DTO\Sms\SmsMessage;

class TestNotification extends Notification
{
    public function via($notifiable)
    {
        return ['netgsm'];
    }

    public function toNetgsm(object $notifiable): BaseSmsMessage
    {
        return new SmsMessage('Netgsm test message');
    }
}

return new OtpSmsMessage('Netgsm otp test message');

public function routeNotificationForSms()
{
    return $this->phone;
}

Notification::route('sms', '+905554443322')  
            ->notify(new TestNotification());

use Macellan\Netgsm\Facades\Netgsm;
use Macellan\Netgsm\DTO\Sms\SmsMessage;
use Macellan\Netgsm\DTO\Sms\OtpSmsMessage;

// Sms send
$smsMessage = (new SmsMessage('Netgsm test message'))
    ->setNumbers(['+905554443322']);
Netgsm::sendSms($smsMessage);
/**
// return array 
[
    'code' => '00', // Netgsm response code
    'id' => '111111', // Bulk Id
]
**/

// Otp Sms send
$otpSmsMessage = (new OtpSmsMessage('Netgsm otp test message'))
    ->setNumbers(['+905554443322']);
Netgsm::sendSms($otpSmsMessage);
/**
// return array 
[
    'code' => '00', // Netgsm response code
    'id' => '111111', // Job id
    'error' => '', // Error message
]
**/