定制 renderbit/laravel-sms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

renderbit/laravel-sms

最新稳定版本:1.3.0

Composer 安装命令:

composer require renderbit/laravel-sms

包简介

Framework-agnostic PHP library for sending SMS via Renderbit, with Laravel support.

README 文档

README

Tests Latest Version on Packagist PHP Version License

A Laravel package to send transactional SMS messages through supported SMS gateways. Built with simplicity, scalability, and performance in mind.

🚀 Features

  • Simple API to send SMS
  • Support for multiple providers (via api-based architecture)
  • Queue-friendly and retry-safe
  • Customizable sender name and API URL
  • Laravel-native configuration and logging
  • Facade & dependency injection support

📦 Installation

Install via Composer:

composer require renderbit/laravel-sms

🛠 Configuration

Publish the configuration file:

php artisan vendor:publish --tag=sms-config

This will publish config/sms.php.

Example config/sms.php:

return return [
    'url' => env('SMS_API_URL', '<default-preconfigured-url>'),
    'query_params' => [
        'user' => env('SMS_USER'),
        'password' => env('SMS_PASSWORD'),
        'senderid' => env('SMS_SENDER_ID', 'IEMUEM'),
        'channel' => 'trans',
        'DCS' => 0,
        'flashsms' => 0,
        'route' => '1'
    ],
    'number_field' => env('SMS_NUMBER_FIELD', 'number'),
    'message_field' => env('SMS_MESSAGE_FIELD', 'text'),
];;

Update your .env file:

SMS_USER=
SMS_PASSWORD=
SMS_SENDER_ID='IEMUEM'
SMS_API_URL='http://1.1.1.1/api/SendSMS?'
SMS_NUMBER_FIELD='number'
SMS_MESSAGE_FIELD='text'

✉️ Usage

You can send an SMS using the facade or the SmsClient class:

Using Facade

use Sms;

Sms::send('+919999999999', 'Hello, your OTP is 123456');

Using Dependency Injection

use Renderbit\Sms\SmsClient;

class NotificationService
{
    public function __construct(protected SmsClient $sms) {}

    public function notify($phone, $message)
    {
        $this->sms->send($phone, $message);
    }
}

✅ Example Response Handling

The send method returns a bool:

$success = Sms::send($phoneNumber, $message);

if (!$success) {
    // Log failure or retry
}

🧪 Testing

To fake SMS sending during tests:

Sms::shouldReceive('send')
    ->once()
    ->with('+919999999999', 'Test message')
    ->andReturn(true);

📁 Directory Structure (Core)

  • SmsClient: Main entry point, handles sms sending logic.
  • Facades\Sms: Facade accessor for SmsClient class.
  • config\sms: Default configs that can be overridden after publishing.
  • SmsServiceProvider: Auto-discovery and binding.

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.

📄 License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 61
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-05