PHPackages                             wenslim/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. wenslim/sms

ActiveLibrary

wenslim/sms
===========

Send message

0.2.0(7y ago)014MITPHP

Since Sep 29Pushed 7y agoCompare

[ Source](https://github.com/wenslim/sms)[ Packagist](https://packagist.org/packages/wenslim/sms)[ RSS](/packages/wenslim-sms/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

发送短信
====

[](#发送短信)

📧 阿里云与腾讯云短信服务

安装
--

[](#安装)

```
$ composer require wenslim/sms
```

阿里云短信
-----

[](#阿里云短信)

### 配置

[](#配置)

> 进入控制台短信服务

1. 点击「AccessKey」获取 `AccessKey ID` 和 `Access Key Secret`
2. 设置短信签名与模版code

### 使用

[](#使用)

```
use Wenslim\Sms\Aliyun\Sms;

// 基础配置中获取的密钥
$accessKeyId = 'xxxxxxxxx';
$accessKeySecret = 'xxxxxxxxx';

// 初始化 Sms 类
$sms = new Sms($accessKeyId, $accessKeySecret);

// 接受人手机号
$sms -> setPhoneNumbers('xxxxxxxxxxx');

// 短信签名 & 短信模版CODE
$sms -> setSignName('xxx');
$sms -> setTemplateCode('xxx');

// 当模版设置变量
$sms -> setTemplateParam("{'code': '1234'}");
$sms -> send();
```

### 返回示例

[](#返回示例)

```
array(4) {
    ["Message"] => string(2) "OK"
    ["RequestId"] => string(36) "AE61E75C-6057-493A-989D-53DCF44C3686"
    ["BizId"] => string(20) "357420138207838299^0"
    ["Code"] => string(2) "OK"
}
```

### 参考

[](#参考)

- [官方 SDK](https://help.aliyun.com/document_detail/55451.html)

腾讯云短信
-----

[](#腾讯云短信)

### 配置

[](#配置-1)

进入控制台短信服务

1. 获取 `appid` 和 `appkey`
2. 配置签名与短信正文模版

### 基础使用

[](#基础使用)

```
use Wenslim\Sms\Txyun\Sms;

$appid = "xxxxxxxx";
$appkey = "xxxxxxxxxxxxxxxxxxxx";

$sms = new Sms($appid, $appkey);
// 国家码 & 手机号
$sms -> setMobile('86', '158xxxxxxxx');
// 模版 ID
$sms -> setTplId(xxxxxx);
// 模版参数
$sms -> setParams(["1234", "2"]);
$sms -> send();
```

### 返回示例

[](#返回示例-1)

```
array:4 [
    "result" => 0
    "errmsg" => "OK"
    "sid" => "2019:-6287508033737713054"
    "fee" => 1
]
```

### 参考

[](#参考-1)

- [官方 SDK](https://cloud.tencent.com/document/product/382)

在 Laravel 中使用
-------------

[](#在-laravel-中使用)

`config/services.php`

```
.
.
.
'sms' => [
    // 阿里云
    'aliyun' => [
        'accessKeyId' => env('SMS_ALIYUN_KEY'),
        'accessKeySecret' => env('SMS_ALIYUN_SECRET'),
    ],
    // 腾讯云
    'txyun' => [
        'appid' => env('SMS_TXYUN_APPID'),
        'appkey' => env('SMS_TXYUN_APPKEY'),
    ]
],
```

`.env`

```
.
.
.
// 阿里云
SMS_ALIYUN_KEY=xxxxxx
SMS_ALIYUN_SECRET=xxxxxx
// 腾讯云
SMS_TXYUN_APPID=xxxxxx
SMS_TXYUN_APPKEY=xxxxxx
```

eg. `UserController.php`

### 阿里云

[](#阿里云)

使用方法注入

```
use Wenslim\Sms\Aliyun\Sms;

class UserController extends Controller
{
    public function send(Sms $sms)
    {
        $sms -> setPhoneNumbers('xxxxxx');
    	$sms -> setSignName('xxxxxx');
        $sms -> setTemplateCode('xxxxxx');
        $sms -> setTemplateParam("{'code': '1234'}");
        $response = $sms -> send();
    }
}
```

使用服务名称

```
class UserController extends Controller
{
    public function send()
    {
        $sms = app('sms');
        $sms -> setSignName('xxxxxx');
        $sms -> setTemplateCode('xxxxxx');
        $sms -> setTemplateParam("{'code': '1234'}");
        $response = $sms -> send();
    }
}
```

### 腾讯云

[](#腾讯云)

使用方法注入

```
use Wenslim\Sms\Txyun\Sms;

class UserController extends Controller
{
    public function send(Sms $sms)
    {
        $sms -> setMobile('86', '158xxxxxxxx');
        $sms -> setTplId(xxxxxx);
        $sms -> setParams(["1234", "3"]);
        $response = $sms -> send();
    }
}
```

使用服务名称

```
class UserController extends Controller
{
    public function send()
    {
        $sms = app("tx_sms");
        $sms -> setMobile('86', '158xxxxxxxx');
        $sms -> setTplId(xxxxxx);
        $sms -> setParams(["1234", "2"]);
        $result = $sms -> send();
    }
}
```

License
-------

[](#license)

MIT

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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 ~8 days

Total

3

Last Release

2767d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0244f4a24cff48db8596c2c11eb725792f0866614f52c66a75527b1282fea0ac?d=identicon)[Wenslim](/maintainers/Wenslim)

---

Top Contributors

[![wenslim](https://avatars.githubusercontent.com/u/24260721?v=4)](https://github.com/wenslim "wenslim (5 commits)")

### Embed Badge

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

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

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k21](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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