PHP code example of kstmostofa / laravel-smpp
1. Go to this page and download the library: Download kstmostofa/laravel-smpp 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/ */
kstmostofa / laravel-smpp example snippets
return [
'host' => env('SMPP_HOST','127.0.0.1'),
'port' => env('SMPP_PORT',2775),
'username' => env('SMPP_USERNAME','smppuser'),
'password' => env('SMPP_PASSWORD','smpppass'),
'timeout' => env('SMPP_TIMEOUT',10000),
'debug' => env('SMPP_DEBUG',false),
];
use Kstmostofa\LaravelSmpp\Facades\LaravelSmpp;
use Kstmostofa\LaravelSmpp\SMPP;
LaravelSmpp::getTransport()->open();
LaravelSmpp::bindTransceiver();
$id = LaravelSmpp::setSender('SENDER', SMPP::TON_ALPHANUMERIC)
->setRecipient('1234567890', SMPP::TON_INTERNATIONAL)
->requestDLR()
->sendSMS('Hello world');
LaravelSmpp::close();
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Kstmostofa\LaravelSmpp\Facades\LaravelSmpp;
use Kstmostofa\LaravelSmpp\DeliveryReceipt;
use Kstmostofa\LaravelSmpp\Sms;
use Kstmostofa\LaravelSmpp\Transport\Socket;
class SmppReceive extends Command
{
protected $signature = 'smpp:receive {--host=} {--port=} {--username=} {--password=} {--timeout=} {--debug}';
protected $description = 'Listen for SMPP Delivery Receipts (DLRs) and MO SMS messages';
public function handle()
{
$cfg = config('smpp');
foreach(['host','port','username','password','timeout'] as $k){ if($this->option($k)!==null) $cfg[$k]=$this->option($k); }
if($this->option('debug')) $cfg['debug']=true;
// Optional: force IPv4 in problematic networks
// Socket::$forceIpv4 = true;
try {
LaravelSmpp::setConfig($cfg);
LaravelSmpp::getTransport()->open();
LaravelSmpp::bindTransceiver();
$this->info('Connected & bound: '.json_encode($cfg));
} catch(\Throwable $e){
$this->error('Initial connect failed: '.$e->getMessage());
return 1;
}
while(true){
try {
$pdu = LaravelSmpp::readSMS();
if($pdu instanceof DeliveryReceipt){
// Persist/update message status in DB
$this->info('[DLR] id='.$pdu->messageId.' status='.$pdu->status);
} elseif($pdu instanceof Sms){
// Store inbound MO
$this->info('[MO ] from='.$pdu->source->value.' text='.$pdu->message);
}
// Keep link alive (adjust cadence as needed)
LaravelSmpp::enquireLink();
usleep(100000); // 100ms
} catch(\Throwable $e){
$this->error('Loop error: '.$e->getMessage());
sleep(1);
try { LaravelSmpp::reconnect(); } catch(\Throwable $re){ $this->error('Reconnect failed: '.$re->getMessage()); }
}
}
}
}
LaravelSmpp::setConfig([
'host'=>'alt.host','port'=>2776,'username'=>'alt','password'=>'secret','timeout'=>15000,'debug'=>true,
]);
use Kstmostofa\LaravelSmpp\Transport\Socket;
Socket::$forceIpv4 = true; // or Socket::$forceIpv6 = true;
bash
php artisan vendor:publish --provider="Kstmostofa\\LaravelSmpp\\LaravelSmppServiceProvider" --tag="smpp-config"