PHP code example of mortezamasumi / fb-sms

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

    

mortezamasumi / fb-sms example snippets


// config/fb-sms.php
return [
    // Sabanovin API domain (without scheme)
    'sabanovin_domain' => env('SABANOVIN_DOMAIN', 'api.sabanovin.com'),

    // Sabanovin reports the balance in Toman; multiplied to convert to Rial (1 Toman = 10 Rial)
    'sabanovin_balance_multiplier' => env('SABANOVIN_BALANCE_MULTIPLIER', 10),

    // Active operator class — one of the bundled operators or your own
    'operator' => env('SMS_CHANNEL_OPERATOR', \Mortezamasumi\FbSms\Operators\Fake::class),

    // API key/username used by Sabanovin and Smsir
    'api_key' => env('SMS_CHANNEL_API_KEY', 'key'),

    // SMS line/number used as the sender gateway
    'gateway' => env('SMS_CHANNEL_GATEWAY', 'gateway'),

    // Fixed receiver, overrides the notifiable's phone when set
    'receiver' => env('SMS_CHANNEL_RECEIVER', null),

    // Optional prefix/suffix applied to every message
    'prepend_text' => env('SMS_CHANNEL_PREPEND_TEXT', ''),
    'append_text'  => env('SMS_CHANNEL_APPEND_TEXT', "\n\n\n لغو ۱۱"),
];

use Illuminate\Notifications\Notification;

class InvoicePaid extends Notification
{
    public function via(object $notifiable): array
    {
        return ['sms'];
    }

    public function toSms(object $notifiable): string
    {
        return "Your invoice was paid. Amount: {$notifiable->amount}";
    }
}

$user->notify(new InvoicePaid());

use Illuminate\Support\Facades\Notification;

Notification::route('sms', '09121234567')->notify(new InvoicePaid());

class InvoicePaid extends Notification
{
    public function succeeded($operator): void
    {
        // $operator->getCode() / getMessage() hold the provider response
    }

    public function failed(\Throwable $exception): void
    {
        // log, alert, retry...
    }
}

use Mortezamasumi\FbSms\Facades\FbSms;

FbSms::credit(); // '125000' — 'N/A' when the provider is unreachable

use Mortezamasumi\FbSms\Contracts\Operator;

class MyOperator extends Operator
{
    public function send(): void
    {
        // $this->getText()   — message body
        // $this->getTo()     — recipient(s)
        // $this->getGateway()— sender line
        // $this->setCode('1'); $this->setMessage('ok');
    }

    public function credit(): string
    {
        return '10000';
    }
}

'operator' => env('SMS_CHANNEL_OPERATOR', App\Sms\MyOperator::class),
bash
php artisan vendor:publish --tag="fb-sms-config"