amsiam/send-sms 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

amsiam/send-sms

Composer 安装命令:

composer require amsiam/send-sms

包简介

Send SMS through any bulk provider just using single package.

README 文档

README

Overview

The Amsiam\SendSMS package provides a simple and flexible way to send SMS messages in Laravel applications. It supports multiple SMS drivers and allows sending single messages, one message to multiple recipients, or multiple messages to multiple recipients. Additionally, it provides functionality to check the SMS balance for the configured driver.

Table of Contents

  1. Requirements
  2. Installation
  3. Configuration
  4. Usage
  5. Supported Drivers
  6. Error Handling
  7. Support

Requirements

  • PHP: 7.4 or higher
  • Laravel: 8.x or higher
  • Composer: For package installation
  • A valid account with a supported SMS provider (e.g., BulkSMSBD)

Installation

  1. Install the package via Composer:

    composer require amsiam/send-sms
  2. Publish the configuration file (optional):

    php artisan vendor:publish --provider="Amsiam\SendSMS\SendSMSServiceProvider"

    This will create a config/sendsms.php file in your Laravel project.

  3. Register the Facade(optional): Add the SendSMS facade to your config/app.php file under the aliases array:

    'aliases' => [
        // Other aliases...
        'SendSMS' => Amsiam\SendSMS\Facades\SendSMS::class,
    ],

Configuration

The package uses a configuration file (config/sendsms.php) to set the default SMS driver and driver-specific settings. Below is an example configuration:

<?php

return [
    'default' => env('SMS_DRIVER', 'bulk_sms'),

    'drivers' => [
        'bulk_sms' => [
            'api_key' => env('SMS_BULK_SMS_BD_API_KEY'),
            'sender_id' => env('SMS_BULK_SMS_BD_SENDERID'),
        ],
        // Add other drivers here
    ],
];

Environment Variables

Add the following to your .env file to configure the driver:

SMS_DRIVER=bulk_sms
SMS_BULK_SMS_BD_API_KEY=your_api_key
SMS_BULK_SMS_BD_SENDERID=your_sender_id

Available Configuration Options

  • default: The default SMS driver (e.g., bulk_sms).
  • drivers: An array of driver-specific configurations, such as API keys and base URLs.

Usage

The SendSMS class provides methods to send SMS messages and check balances. You can use it via the Amsiam\SendSMS\Facades\SendSMS facade, which simplifies imports and usage.

Setting a Driver

By default, the package uses the driver specified in the default configuration. To switch drivers programmatically:

use Amsiam\SendSMS\Enums\SMSDriver;
use Amsiam\SendSMS\Facades\SendSMS;

SendSMS::setDriver(SMSDriver::BULK_SMS);

Sending a Single SMS

Send an SMS to a single phone number:

use Amsiam\SendSMS\Facades\SendSMS;

$response = SendSMS::sendSMS('8801234567890', 'Hello, this is a test message!');

Sending One Message to Multiple Recipients

Send the same message to multiple phone numbers:

use Amsiam\SendSMS\Facades\SendSMS;

$phones = ['8801234567890', '8809876543210'];
$response = SendSMS::sendOneMessageToMany($phones, 'Hello, this is a broadcast message!');

Sending Multiple Messages to Multiple Recipients

Send different messages to different phone numbers:

use Amsiam\SendSMS\Facades\SendSMS;

$phones = ['8801234567890', '8809876543210'];
$messages = ['Hello John!', 'Hello Jane!'];
$response = SendSMS::sendManyMessageToMany($phones, $messages);

Checking SMS Balance

Retrieve the balance for the configured SMS driver:

use Amsiam\SendSMS\Facades\SendSMS;

$balance = SendSMS::getBalance();

Static Method Calls

The SendSMS facade supports static method calls, making it convenient to use without manual instantiation:

use Amsiam\SendSMS\Facades\SendSMS;

$response = SendSMS::sendSMS('8801234567890', 'Hello, this is a test message!');
$balance = SendSMS::getBalance();

Note: The facade internally handles instantiation and uses the default driver.

Supported Drivers

The package currently supports the following driver:

  • BulkSMSBD: A driver for the BulkSMSBD service (Amsiam\SendSMS\Drivers\BulkSMSBDDriver).

To add support for additional drivers, implement the ISendSMSDriver interface and register the driver in the configuration.

Error Handling

  • If the driver is not set or improperly configured, methods like sendSMS, sendOneMessageToMany, sendManyMessageToMany, and getBalance will return null.
  • Static calls to undefined methods will throw a BadMethodCallException.
  • Ensure the phone numbers and messages are valid for the driver being used (e.g., correct format for BulkSMSBD).

Example of handling errors:

use Amsiam\SendSMS\Facades\SendSMS;

try {
    $response = SendSMS::sendSMS('8801234567890', 'Test message');
    if ($response === null) {
        // Handle driver not set or failed request
        echo "Failed to send SMS.";
    } else {
        // Handle success
        echo "SMS sent successfully!";
    }
} catch (\Exception $e) {
    // Handle exceptions (e.g., network issues, invalid configuration)
    echo "Error: " . $e->getMessage();
}

Support

For issues or feature requests, please contact the package maintainer or open an issue on the package's GitHub repository (if available). Ensure you provide:

  • Laravel version
  • PHP version
  • Package version
  • Relevant error messages or logs

For driver-specific issues (e.g., BulkSMSBD), contact the SMS provider's support team.

amsiam/send-sms 适用场景与选型建议

amsiam/send-sms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 amsiam/send-sms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 amsiam/send-sms 我们能提供哪些服务?
定制开发 / 二次开发

基于 amsiam/send-sms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-28