guolei19850528/laravel-sms
最新稳定版本:v1.0.1
Composer 安装命令:
composer require guolei19850528/laravel-sms
包简介
这是一个基于 Laravel 框架的短信服务扩展,用于集成微网通联短信服务。
README 文档
README
这是一个基于 Laravel 框架的短信服务扩展,用于集成微网通联短信服务。
功能特性
- 支持微网通联短信服务API
- 支持多应用配置
- 提供简洁的短信发送接口
- 支持自定义响应处理
- 内置请求签名验证机制
安装
使用 Composer 安装扩展:
composer require guolei19850528/laravel-sms
配置
发布配置文件
php artisan vendor:publish --provider="Guolei19850528\Laravel\Sms\ServiceProvider"
修改配置文件
在 config/guolei19850528-laravel-sms-config.php 文件中配置微网通联短信服务参数:
<?php
return [
'lmobile' => [
'your app' => [
'productId' => 'your product id', // 产品ID
'accountId' => 'your account id', // 账号ID
'password' => 'your password', // 密码
'smmsEncryptKey' => 'SMmsEncryptKey',// 短信加密密钥
'baseUrl' => 'https://api.51welink.com/', // API基础URL
]
]
];
使用方法
发送短信
<?php
use Guolei19850528\Laravel\Sms\Lmobile\Api;
// 初始化短信API客户端
$smsApi = new Api(
$accountId,
$password,
$productId,
$smmsEncryptKey,
$baseUrl
);
// 发送短信到单个手机号
$result = $smsApi->sendSms(
'13800138000',
'您的验证码是:123456,有效期5分钟。'
);
// 发送短信到多个手机号
$result = $smsApi->sendSms(
['13800138000', '13900139000'],
'您的验证码是:123456,有效期5分钟。'
);
// 自定义响应处理
$result = $smsApi->sendSms(
'13800138000',
'您的验证码是:123456,有效期5分钟。',
null,
[],
[],
function ($response) {
// 自定义响应处理逻辑
return $response->json()['Result'] === 'succ';
}
);
API 文档
类:Guolei19850528\Laravel\Sms\Lmobile\Api
构造函数
public function __construct(
string $accountId,
string $password,
string|int $productId,
string $smmsEncryptKey = 'SMmsEncryptKey',
string $baseUrl = 'https://api.51welink.com/'
)
参数说明:
$accountId: 微网通联短信服务账号ID$password: 微网通联短信服务密码$productId: 微网通联短信服务产品ID$smmsEncryptKey: 短信加密密钥,默认值为 'SMmsEncryptKey'$baseUrl: API基础URL,默认值为 'https://api.51welink.com/'
发送短信方法
public function sendSms(
string|array|null $phoneNos = '',
string|null $content = '',
string|null $url = '/EncryptionSubmit/SendSms.ashx',
array|null $urlParameters = [],
array|null $options = [],
\Closure|null $responseHandler = null,
array|null $validatorRules = ['Result' => 'required|string|in:succ']
): bool
参数说明:
$phoneNos: 接收短信的手机号,支持单个手机号字符串或多个手机号数组$content: 短信内容$url: API请求路径,默认值为 '/EncryptionSubmit/SendSms.ashx'$urlParameters: URL参数数组$options: HTTP请求选项$responseHandler: 响应处理回调函数$validatorRules: 响应验证规则,默认验证Result字段为'succ'
返回值:
- 发送成功返回
true,失败返回false
许可证
MIT License
作者
- 郭磊
- 邮箱: 174000902@qq.com
- GitHub: https://gitee.com/guolei19850528/laravel-sms
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-05