PHP code example of gonzalezfj / smsc

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

    

gonzalezfj / smsc example snippets


...
'providers' => [
    ...
    NotificationChannels\SMSC\SMSCServiceProvider::class,
],
...

...
'SMSC' => [
    'http'       => [
        'endpoint' => 'https://www.smsc.com.ar/api/0.3/',
    ],
    'alias'   => '',
    'apikey'   => '',
    'timeout'    => 60,
],
...

use NotificationChannels\SMSC\SMSCChannel;
use NotificationChannels\SMSC\SMSCMessage;

class ResetPasswordWasRequested extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [SMSCChannel::class];
    }
    
    /**
     * Get the SMSC representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return string|\NotificationChannels\SMSC\SMSCMessage
     */
    public function toSMSC($notifiable) {
        return "Test notification";
        // Or
        return new SMSCMessage("Test notification", $notifiable->mobile_number);
    }
}

class User extends Authenticatable
{
    use Notifiable;
    
    public function routeNotificationForSMSC()
    {
        return "115371885";
    }
}

public function __construct($content, $number);

namespace App\Listeners;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use NotificationChannels\SMSC\Events\MessageWasSent;

class SentMessageHandler
{
    /**
     * Handle the event.
     *
     * @param  MessageWasSent  $event
     * @return void
     */
    public function handle(MessageWasSent $event)
    {
        $response = $event->response;
        $message = $event->message;

        // The message properties.
        \Log::info($message->content());
        \Log::info($message->number());

        // Message as array.
        \Log::info($message->toArray());

        // API Response properties.
        \Log::info($response->isSuccess());
        \Log::info($response->errorCode());
        \Log::info($response->errorMessage());
    }
}

namespace App\Listeners;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use NotificationChannels\SMSC\Events\SendingMessage;

class SendingMessageHandler
{
    /**
     * Handle the event.
     *
     * @param  SendingMessage  $event
     * @return void
     */
    public function handle(SendingMessage $event)
    {
        $message = $event->message;

        // The message properties.
        \Log::info($message->content());
        \Log::info($message->number());

        // Message as array.
        \Log::info($message->toArray());
    }
}