PHPackages                             lucups/cnsms - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lucups/cnsms

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lucups/cnsms
============

A simple SMS toolkit without any third party dependencies, only for China.

0.6.0(8mo ago)173MITPHPPHP &gt;=7.0

Since Nov 30Pushed 8mo ago1 watchersCompare

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

READMEChangelog (6)DependenciesVersions (8)Used By (0)

CNSMS 极简短信工具库
=============

[](#cnsms-极简短信工具库)

Slogan
------

[](#slogan)

> 我就发个验证码，给我整那么活干啥...

介绍
--

[](#介绍)

适应中国大陆国情的极简短信工具库，除 `ext-curl`、`ext-json` 等大家都会用到的 PECL 扩展库外无任何第三方依赖包，适用于发送验证码短信、通知短信等场景。

A simple SMS toolkit without any third party dependencies, only for the Chinese Mainland.

- [GitHub](https://github.com/lucups/cnsms)
- [提交BUG](https://github.com/lucups/cnsms/issues/new)

支持的短信渠道
-------

[](#支持的短信渠道)

短信渠道链接支持版本推荐指数短信宝`v0.4.0`+⭐️⭐️⭐️⭐️阿里云短信服务`v0.1.0`+⭐️⭐腾讯云短信 SMS`v0.2.1`+⭐️安装
--

[](#安装)

```
composer require lucups/cnsms
```

使用
--

[](#使用)

### 短信宝

[](#短信宝)

```
$config = [
    'channel'     => Sms::CHANNEL_SMSBAO,
    'logFlag'     => true,
    'logfilePath' => '/tmp/cnsms.log',
    'username'    => 'xxxxx', // 登录账号
    'password'    => 'xxxxx', // 登录密码
    'apiKey'      => 'xxxxx', // 接口密钥（密码密钥二选一，请求的时候密码会被md5处理，apiKey 不会）
];

$result = Sms::create($config)->send('1340000000', '【测试账号】您的短信验证码是{code} ，在10分钟内有效。', ['code'=> '123456']);
print_r($result);
```

自 v0.6.0 开始，短信宝支持查询余额/短信余量:

```
$result = Sms::create($config)->balance();
print_r($result);
```

调用得到PHP数组，字段含义如下：

```
Array
(
    [code] => 0
    [msg] => success // 调用失败则是 fail
    [leftNum] => 48 // 短信剩余条数
    [balance] => 0 // 账户余额
)

```

### 阿里云短信服务

[](#阿里云短信服务)

```
use Lucups\Cnsms\Sms;

require_once __DIR__ . '/vendor/autoload.php';

$config = [
    'channel'         => Sms::CHANNEL_ALIYUN,
    'accessKeyId'     => 'xxxxxxx',
    'accessKeySecret' => 'xxxxxxx',
    'signName'        => 'xxx',
];

$result = Sms::create($config)->send('1340000000', 'SMS_12345678', ['code' => '666888']);
print_r($result);

// 完整配置
$config = [
    'channel'         => Sms::CHANNEL_ALIYUN,
    'logFlag'         => true,
    'logfilePath'     => '/tmp/cnsms.log',
    'accessKeyId'     => 'xxxxxxx',
    'accessKeySecret' => 'xxxxxxx',
    'signName'        => 'xxx',
    'regionId'        => 'cn-shanghai'
];
```

### 腾讯云短信服务

[](#腾讯云短信服务)

```
$config = [
    'channel'     => Sms::CHANNEL_TENCENT,
    'logFlag'     => true,
    'logfilePath' => '/tmp/cnsms.log',
    'secretId'    => 'xxxxxxx',
    'secKey'      => 'xxxxxxx',
    'appId'       => 'xxx',
    'signName'    => 'xxx',
];
$result = Sms::create($config)->send('1340000000', '178888', ['12345']);
print_r($result);
```

注意事项
----

[](#注意事项)

- 本工具库不校验手机号码合法性，需自行校验；
- 本工具库不处理短信发送失败的情况，需根据 `send` 方法的返回值自行处理；
- 鉴于国内日益严格的审查政策，建议使用服务相对比较人性化、审核速度相对较快的短信宝服务。

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance62

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~170 days

Recently: every ~191 days

Total

7

Last Release

241d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/93779358a53bdf438960e64b765ef909607d26dcc3df3a77a6bd76db0f87afd0?d=identicon)[Lucups](/maintainers/Lucups)

---

Top Contributors

[![lucups](https://avatars.githubusercontent.com/u/2325891?v=4)](https://github.com/lucups "lucups (34 commits)")

### Embed Badge

![Health badge](/badges/lucups-cnsms/health.svg)

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

###  Alternatives

[ichhabrecht/content-defender

Define allowed or denied content element types in your backend layouts

892.9M22](/packages/ichhabrecht-content-defender)[teamones/casbin

Teamones框架 casbin sdk

101.8k](/packages/teamones-casbin)

PHPackages © 2026

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