trungdv / zalo-otp
Zalo OTP Package for Laravel - Send and verify OTP via Zalo API
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/trungdv/zalo-otp
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- laravel/framework: ^9.0|^10.0|^11.0|^12.0
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
README
A Laravel package for integrating with Zalo OTP API, supporting OTP sending and verification via Zalo.
Requirements
- PHP >= 8.1
- Laravel >= 9.0
- GuzzleHttp >= 7.0
Installation
1. Install package
composer require trungdv/zalo-otp
2. Publish config file
php artisan vendor:publish --tag=config
3. Configure in .env
# Zalo OTP Configuration ZALO_OTP_BASE_URL=https://oauth.zaloapp.com/v4/ ZALO_OTP_BUSINESS_BASE_URL=https://business.openapi.zalo.me/ ZALO_OTP_APP_ID=your_app_id ZALO_OTP_APP_SECRET=your_app_secret ZALO_OTP_TIMEOUT=30 ZALO_OTP_RETRY_ATTEMPTS=3
Configuration
The config file is published at config/zalo-otp.php
:
return [ 'base_url' => env('ZALO_OTP_BASE_URL', 'https://oauth.zaloapp.com/v4/'), 'bussiness_base_url' => env('ZALO_OTP_BUSINESS_BASE_URL', 'https://business.openapi.zalo.me/'), 'app_id' => env('ZALO_OTP_APP_ID'), 'app_secret' => env('ZALO_OTP_APP_SECRET'), 'timeout' => env('ZALO_OTP_TIMEOUT', 30), 'retry_attempts' => env('ZALO_OTP_RETRY_ATTEMPTS', 3), ];
Usage
sendOtp
use TrungDV\ZaloOtp\Facades\ZaloOtp; // Get instance $client = ZaloOtp::getInstance(); // Send OTP $response = $client->sendOtp([ 'phone' => '0123456789', 'template_id' => 'your_template_id', 'template_data' => [ 'otp' => '123456' ] ]); // Get response echo $response->body(); echo $response->status();
refreshToken
use TrungDV\ZaloOtp\Facades\ZaloOtp; // Get instance $client = ZaloOtp::getInstance(); // Set refresh token $client->setRefreshToken('your_refresh_token'); // Refresh access token $response = $client->refreshToken(); // Get response echo $response->body(); echo $response->status();
getMessageStatus
use TrungDV\ZaloOtp\Facades\ZaloOtp; // Get instance $client = ZaloOtp::getInstance(); // Get message status $response = $client->getStatusMessage([ 'message_id' => '1234567890', 'phone' => '0123456789' ]); // Get response echo $response->body(); echo $response->status();
License
MIT License. See LICENSE file for more details.
Contributing
- Fork repository
- Create feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Create Pull Request
Support
If you encounter any issues, please create an issue on GitHub or contact:
- Email: trungdv@example.com
- GitHub: @trungdv
Changelog
v1.0.0
- Initial release
- Support for sending OTP via Zalo
- Support for refresh token
- Support for getting message status
- Support for HTTP methods (GET, POST, PUT, PATCH)
- Facade support
- Service Container integration