PHP code example of niladam / laravel-sendsms

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

    

niladam / laravel-sendsms example snippets




/**
 * This is the package main config file.
 *
 */
return [
    /**
     * This is your main username.
     */
    "username" => env("LARAVEL_SENDSMS_USERNAME", null),

    /**
     * This is your main password.
     */
    "password" => env("LARAVEL_SENDSMS_PASSWORD", null),

    /**
     * This is the base URL that the package will use.
     *
     * It has already been filled with a default value.
     *
     */
    "url" => env("LARAVEL_SENDSMS_URL", "https://api.sendsms.ro/json"),

    /**
     * If this package should have debug turned on
     * please set this here.
     *
     */
    "debug" => env("LARAVEL_SENDSMS_DEBUG", false),

    "messages" => [
        "from" => env("LARAVEL_SENDSMS_FROM", null),
        "callback_url" => env("LARAVEL_SENDSMS_CALLBACK", null),
        "charset" => env("LARAVEL_SENDSMS_CHARSET", null),
        "coding" => env("LARAVEL_SENDSMS_CODING", null),
        "class" => env("LARAVEL_SENDSMS_CLASS", -1),
        "auto_detect_encoding" => env(
            "LARAVEL_SENDSMS_AUTODETECT_ENCODING",
            null
        ),
        /**
         * Information on the report mask:
         *
         *  1   Delivered
         *  2   Undelivered
         *  4   Queued at network
         *  8   Sent to network
         *  16  Failed at network
         *
         * So, 19 means:
         *
         * (Delivered + Undelivered + Failed at network)
         * 1 + 2 + 16 = 19
         */
        "report_mask" => env("LARAVEL_SENDSMS_MASK", 19)
    ],

    /**
     * This is basically a mapping of the operations
     * that the API will use.
     *
     */
    "operations" => [
        "balance" => "user_get_balance",
        "ping" => "ping",
        "price" => "route_check_price",
        "info" => "user_get_info",
        "number" => "user_get_phone_number",
        "send" => "message_send",
    ],
];

use Niladam\LaravelSendsms\SendSmsMessage;

$message = SendSmsMessage::create();

$message->to('0744123123')
        ->message('Example message here.')
        // You can also use the alias ->text('example text')
        // the following is optional, as it'll use your default settings
        ->from('0744123456')
        ->send();

use Niladam\LaravelSendsms\SendSmsMessage;

SendSmsMessage::create()
        ->to('0744123123')
        // You can also use the alias ->text('example text')
        ->message('Example message here.')
        // the following is optional, as it'll use your default settings
        ->from('0744123456')
        ->send();

SendSmsMessage::create(to: 0744123123, message: 'Example message here')->send();

// Or by specifying the from.

SendSmsMessage::create(to: '0744123123', message: 'Example message here', from: '0744123456')->send();

use Niladam\LaravelSendsms\Facades\LaravelSendsms;

LaravelSendSms::ping();

// returns the following output
[
  "status" => 0,
  "message" => "OK",
]

use Niladam\LaravelSendsms\Facades\LaravelSendsms;

LaravelSendSms::balance();

// returns the following output
[
  "status" => 0,
  "message" => "OK",
  "details" => 49.76696,
]

use Niladam\LaravelSendsms\Facades\LaravelSendsms;

LaravelSendSms::price('0744123123');

// returns the following output
[
  "status" => 0,
  "message" => "OK",
  "details" => [
    "cost" => 0.035, // this is the cost.
    "status" => 64,
    "reason" => "64: Routed OK",
  ],
]

use Niladam\LaravelSendsms\Facades\LaravelSendsms;

LaravelSendSms::info();

// returns the following output
[
  "status" => 0,
  "message" => "OK",
  "details" => [
    "balance" => "49.76696",
    "name" => "Some Cool Company Name",
    "phone_number" => "",
    "currency_code" => "EUR",
    "default_prefix" => "40",
    "timezone" => "Europe/Bucharest",
    "last_message_sent_at" => "2022-07-28 12:48:37",
    "currency_symbol" => "€ ",
    "affiliate" => [
      "active" => false,
      "id" => null,
      "auth_ip_list" => null,
      "max_registrations" => null,
      "max_registrations_period" => null,
    ],
  ],
]

use Niladam\LaravelSendsms\Facades\LaravelSendsms;

LaravelSendSms::number();

// returns the following output
[
  "status" => 0,
  "message" => "OK",
  "details" => "", // This should contain information related to the user's verified phone number.
]
bash
php artisan vendor:publish --provider="Niladam\LaravelSendsms\LaravelSendsmsServiceProvider" --tag=config