anhtuan92na / fpt-sms
FPT SMS API integration for Laravel
v1.0.0
2026-03-15 03:07 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/cache: ^10.0
- illuminate/http: ^10.0
- illuminate/support: ^10.0
Requires (Dev)
- mockery/mockery: ^1.5
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
README
A Laravel package for integrating with the FPT SMS API. Supports sending brandname SMS, OTP, advertising campaigns, and more.
Features
- Send Brandname SMS (OTP, Ads, Priority)
- Send MT Active SMS (standard & priority)
- Create & manage advertising campaigns
- Automatic access token caching (file, Redis, Memcached)
- Sandbox & Production mode
- Built-in logging
- Artisan commands for testing & monitoring
- Facade and Dependency Injection support
Requirements
- PHP >= 8.1
- Laravel >= 10.0
Installation
composer require anhtuan92na/fpt-sms
Publish the config file:
php artisan vendor:publish --tag=fpt-sms-config
Configuration
Add the following variables to your .env file:
FPT_SMS_CLIENT_ID=your_client_id FPT_SMS_CLIENT_SECRET=your_client_secret FPT_SMS_MODE=sandbox FPT_SMS_TIMEOUT=30 FPT_SMS_CACHE=true FPT_SMS_CACHE_DRIVER=file FPT_SMS_LOG=true FPT_SMS_LOG_CHANNEL=stack
| Key | Default | Description |
|---|---|---|
FPT_SMS_CLIENT_ID |
'' |
FPT Client ID |
FPT_SMS_CLIENT_SECRET |
'' |
FPT Client Secret |
FPT_SMS_MODE |
sandbox |
API mode: sandbox or live |
FPT_SMS_TIMEOUT |
30 |
Connection timeout (seconds) |
FPT_SMS_CACHE |
true |
Enable access token caching |
FPT_SMS_CACHE_DRIVER |
file |
Cache driver (file, redis, memcached) |
FPT_SMS_LOG |
true |
Enable request logging |
FPT_SMS_LOG_CHANNEL |
stack |
Laravel log channel |
Verify your configuration:
php artisan fpt-sms:status
Usage
Facade
use FptSms\Facades\FptSms; // Send OTP $result = FptSms::sendBrandnameOtp('BrandName', '0912345678', 'Your OTP code is: 123456'); // Send advertising SMS $result = FptSms::sendBrandnameAds('CAMPAIGN_CODE', '0912345678,0987654321'); // Create a campaign $result = FptSms::createCampaign('BrandName', 'Campaign 1', 'Message content', '2025-12-01 08:00:00', 1000);
Dependency Injection
use FptSms\FptSmsClient; class NotificationService { public function __construct( private FptSmsClient $fptSms ) {} public function sendOrderConfirmation($order) { return $this->fptSms->sendBrandnameOtp( 'ShopName', $order->customer->phone, "Order #{$order->id} has been confirmed" ); } }
Queue Job
use FptSms\FptSmsClient; class SendSmsJob implements ShouldQueue { use InteractsWithQueue, Queueable; public function __construct( public string $phone, public string $message ) {} public function handle(FptSmsClient $fptSms) { $fptSms->sendBrandnameOtp('BrandName', $this->phone, $this->message); } } // Dispatch SendSmsJob::dispatch('0912345678', 'Hello')->onQueue('sms');
API Methods
| Method | Description |
|---|---|
sendBrandnameOtp(brandName, phone, message) |
Send OTP SMS via brandname |
sendBrandnameAds(campaignCode, phoneList) |
Send advertising SMS to a phone list |
createCampaign(brandName, campaignName, message, scheduleTime, quota) |
Create an advertising campaign |
Artisan Commands
| Command | Description |
|---|---|
php artisan fpt-sms:status |
Check configuration status |
php artisan fpt-sms:test |
Send a test SMS |
php artisan fpt-sms:clear-cache |
Clear cached access token |
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.