PHPackages                             since/sms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. since/sms

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

since/sms
=========

一个基于PHP 8+的短信发送客户端库，采用驱动(driver)设计模式，提供单例模式和门面模式两种使用方式，支持配置管理、短信发送和批量发送功能，包含完整的类型声明和异常处理机制，易于扩展支持多种短信服务商。

1.0.0(8mo ago)02MITPHPPHP ^8.0

Since Sep 19Pushed 8mo agoCompare

[ Source](https://github.com/zhan11400/sms)[ Packagist](https://packagist.org/packages/since/sms)[ RSS](/packages/since-sms/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

since/sms
=========

[](#sincesms)

一个基于PHP 8+的高性能短信发送客户端库，同时支持深源恒际、腾讯云和阿里云短信平台，提供单例模式和门面模式两种使用方式，包含完整的类型声明和异常处理机制。

特性
--

[](#特性)

- **支持PHP 8+**：完全适配PHP 8的新特性和类型声明
- **双重使用模式**：同时支持单例模式和门面模式
- **完整的类型声明**：提高代码可读性和IDE支持
- **统一的异常处理**：简化错误处理流程
- **批量发送支持**：可同时向多个手机号发送短信
- **配置灵活**：支持动态配置和参数自定义
- **模块化设计**：按短信平台拆分实现，便于维护和扩展

项目结构
----

[](#项目结构)

本库采用模块化设计，按短信平台拆分实现，便于维护和扩展：

- `src/driver/AbstractSMS.php` - 抽象基类，定义短信发送接口和通用功能
- `src/SMS.php` - 工厂类，负责创建和返回具体的短信平台实现实例
- `src/driver/DeepfinchSMS.php` - 深源恒际短信平台实现
- `src/driver/TencentSMS.php` - 腾讯云短信平台实现
- `src/driver/AliyunSMS.php` - 阿里云短信平台实现
- `src/SMSFacade.php` - 门面类，提供更简洁的API调用方式

安装
--

[](#安装)

使用Composer安装：

```
composer require since/sms
```

依赖要求
----

[](#依赖要求)

- PHP &gt;= 8.0
- ext-curl 扩展
- ext-json 扩展
- tencentcloud/sms ^3.0 (腾讯云短信SDK)
- alibabacloud/dysmsapi-20170525 ^1.0 (阿里云短信SDK)

使用方式
----

[](#使用方式)

### 1. 配置参数

[](#1-配置参数)

#### 1.1 深源恒际短信服务配置

[](#11-深源恒际短信服务配置)

```
$deepfinchConfig = [
    'provider' => 'deepfinch',                  // 短信服务提供商
    'accessKeyId' => 'your_access_key_id',      // 深源恒际API ID
    'accessKeySecret' => 'your_access_key_secret', // 深源恒际API密钥
    'apiUrl' => 'https://cloudapi.deepfinch.com/data/send_sms', // 短信发送API地址
    'timeout' => 5,                             // 请求超时时间（秒）
    'templates' => [                            // 模板配置
        'verification' => 'your_verification_template_id', // 验证码模板ID
        'notification' => 'your_notification_template_id', // 通知模板ID
    ],
];
```

#### 1.2 腾讯云短信服务配置

[](#12-腾讯云短信服务配置)

```
$tencentConfig = [
    'provider' => 'tencent',                    // 短信服务提供商
    'accessKeyId' => 'your_tencent_access_key_id',  // 腾讯云API密钥ID
    'accessKeySecret' => 'your_tencent_access_key_secret', // 腾讯云API密钥
    'timeout' => 5,                             // 请求超时时间（秒）
    'templates' => [                            // 模板配置
        'verification' => 'your_tencent_verification_template_id', // 腾讯云模板ID
        'notification' => 'your_tencent_notification_template_id', // 腾讯云模板ID
    ],
    'tencent' => [                              // 腾讯云特有配置
        'sdkAppId' => 'your_tencent_sdk_app_id', // 腾讯云SDK AppID
        'signName' => 'your_tencent_sign_name', // 腾讯云短信签名
        'region' => 'ap-guangzhou',             // 腾讯云地域，默认ap-guangzhou
    ],
];
```

#### 1.3 阿里云短信服务配置

[](#13-阿里云短信服务配置)

```
$aliyunConfig = [
    'provider' => 'aliyun',                     // 短信服务提供商
    'accessKeyId' => 'your_aliyun_access_key_id',  // 阿里云AccessKey ID
    'accessKeySecret' => 'your_aliyun_access_key_secret', // 阿里云AccessKey Secret
    'timeout' => 5,                             // 请求超时时间（秒）
    'templates' => [                            // 模板配置
        'verification' => 'your_aliyun_verification_template_id', // 阿里云模板CODE
        'notification' => 'your_aliyun_notification_template_id', // 阿里云模板CODE
    ],
    'aliyun' => [                               // 阿里云特有配置
        'signName' => 'your_aliyun_sign_name',  // 阿里云短信签名
        'regionId' => 'cn-hangzhou',            // 阿里云地域ID，默认cn-hangzhou
    ],
];
```

### 2. 方式一：使用门面模式（推荐）

[](#2-方式一使用门面模式推荐)

#### 2.1 使用深源恒际短信服务

[](#21-使用深源恒际短信服务)

```
use since\SMSFacade;

// 初始化门面实例
$smsFacade = SMSFacade::getInstance($deepfinchConfig);

// 生成验证码
$verificationCode = rand(100000, 999999);

// 发送短信
$result = $smsFacade->send('13812345678', 'verification', [$verificationCode]);

// 查看结果
var_dump($result);
```

#### 2.2 使用腾讯云短信服务

[](#22-使用腾讯云短信服务)

```
use since\SMSFacade;

// 初始化门面实例
$tencentSmsFacade = SMSFacade::getInstance($tencentConfig);

// 生成验证码
$verificationCode = rand(100000, 999999);

// 发送短信
$tencentResult = $tencentSmsFacade->send('13812345678', 'verification', [$verificationCode]);

// 查看结果
var_dump($tencentResult);
```

#### 2.3 使用阿里云短信服务

[](#23-使用阿里云短信服务)

```
use since\SMSFacade;

// 初始化门面实例
$aliyunSmsFacade = SMSFacade::getInstance($aliyunConfig);

// 生成验证码
$verificationCode = rand(100000, 999999);

// 发送短信
$aliyunResult = $aliyunSmsFacade->send('13812345678', 'verification', [$verificationCode]);

// 查看结果
var_dump($aliyunResult);
```

### 3. 方式二：使用单例模式

[](#3-方式二使用单例模式)

#### 3.1 使用深源恒际短信服务

[](#31-使用深源恒际短信服务)

```
use since\SMS;

// 初始化单例实例
$sms = SMS::getInstance($deepfinchConfig);

// 发送短信
$result = $sms->send('13812345678', 'verification', [$verificationCode]);

// 查看结果
var_dump($result);
```

#### 3.2 使用腾讯云短信服务

[](#32-使用腾讯云短信服务)

```
use since\SMS;

// 初始化单例实例
$tencentSms = SMS::getInstance($tencentConfig);

// 发送短信
$tencentResult = $tencentSms->send('13812345678', 'verification', [$verificationCode]);

// 查看结果
var_dump($tencentResult);
```

#### 3.3 使用阿里云短信服务

[](#33-使用阿里云短信服务)

```
use since\SMS;

// 初始化单例实例
$aliyunSms = SMS::getInstance($aliyunConfig);

// 发送短信
$aliyunResult = $aliyunSms->send('13812345678', 'verification', [$verificationCode]);

// 查看结果
var_dump($aliyunResult);
```

### 4. 批量发送短信

[](#4-批量发送短信)

#### 4.1 使用深源恒际短信服务批量发送

[](#41-使用深源恒际短信服务批量发送)

```
// 方式一：门面模式批量发送
$batchResult = SMSFacade::getInstance($deepfinchConfig)->batchSend(
    ['13812345678', '13987654321'],
    'verification',
    [$verificationCode]
);

// 方式二：单例模式批量发送
$batchResult = SMS::getInstance($deepfinchConfig)->batchSend(
    ['13812345678', '13987654321'],
    'verification',
    [$verificationCode]
);

// 查看结果
var_dump($batchResult);
```

#### 4.2 使用腾讯云短信服务批量发送

[](#42-使用腾讯云短信服务批量发送)

```
// 方式一：门面模式批量发送
$tencentBatchResult = SMSFacade::getInstance($tencentConfig)->batchSend(
    ['13812345678', '13987654321'],
    'verification',
    [$verificationCode]
);

// 方式二：单例模式批量发送
$tencentBatchResult = SMS::getInstance($tencentConfig)->batchSend(
    ['13812345678', '13987654321'],
    'verification',
    [$verificationCode]
);

// 查看结果
var_dump($tencentBatchResult);
```

#### 4.3 使用阿里云短信服务批量发送

[](#43-使用阿里云短信服务批量发送)

```
// 方式一：门面模式批量发送
$aliyunBatchResult = SMSFacade::getInstance($aliyunConfig)->batchSend(
    ['13812345678', '13987654321'],
    'verification',
    [$verificationCode]
);

// 方式二：单例模式批量发送
$aliyunBatchResult = SMS::getInstance($aliyunConfig)->batchSend(
    ['13812345678', '13987654321'],
    'verification',
    [$verificationCode]
);

// 查看结果
var_dump($aliyunBatchResult);
```

异常处理
----

[](#异常处理)

库会抛出标准的PHP Exception异常，包含错误信息，建议使用try/catch进行异常处理：

```
try {
    $result = SMSFacade::getInstance($config)->send('13812345678', 'verification', [123456]);
    // 处理成功结果
} catch (Exception $e) {
    // 处理异常
    echo '短信发送失败：' . $e->getMessage();
}
```

手机号验证规则
-------

[](#手机号验证规则)

库会自动验证手机号格式：

- 手机号必须为11位数字
- 手机号必须全部为数字字符

响应格式
----

[](#响应格式)

短信发送成功后，返回API响应的JSON解析数组。发送失败时，返回false。

最佳实践
----

[](#最佳实践)

1. **配置信息安全**：建议将accessKeyId和accessKeySecret等敏感信息存储在环境变量或配置文件中，不要硬编码到代码里
2. **错误重试机制**：对于网络请求失败的情况，建议添加重试机制
3. **频率控制**：遵守短信发送频率限制，避免短时间内向同一手机号发送大量短信
4. **异常处理**：始终使用try/catch捕获可能的异常

开发说明
----

[](#开发说明)

1. 请确保PHP版本 &gt;= 8.0
2. 请确保已安装curl和json扩展
3. 安装依赖包：

```
composer install
```

4. 在开发环境中，可以通过以下命令快速测试：

```
php index.php
```

License
-------

[](#license)

This project is licensed under the MIT License.

鸣谢
--

[](#鸣谢)

- 腾讯云短信SDK：
- 阿里云短信SDK：
- 深源恒际短信平台：

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance62

Regular maintenance activity

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

241d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/41a6543979942d685e7df398addd15acf91e076b44b5539a2d6092dd1df42697?d=identicon)[zhan11400](/maintainers/zhan11400)

### Embed Badge

![Health badge](/badges/since-sms/health.svg)

```
[![Health](https://phpackages.com/badges/since-sms/health.svg)](https://phpackages.com/packages/since-sms)
```

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[guanguans/notify

Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

682104.9k7](/packages/guanguans-notify)[tzsk/sms

A robust and unified SMS gateway integration package for Laravel, supporting multiple providers.

320244.3k6](/packages/tzsk-sms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
