https://github.com/zfegg/sms-sender
SMS sender service. And use for send sms captcha handler / 短信发送模块, 并且用于发送短信验证码处理程序
https://github.com/zfegg/sms-sender
sms
Last synced: about 1 year ago
JSON representation
SMS sender service. And use for send sms captcha handler / 短信发送模块, 并且用于发送短信验证码处理程序
- Host: GitHub
- URL: https://github.com/zfegg/sms-sender
- Owner: zfegg
- License: mit
- Created: 2016-08-09T08:01:26.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-10-22T04:06:24.000Z (over 3 years ago)
- Last Synced: 2024-04-23T20:43:38.794Z (about 2 years ago)
- Topics: sms
- Language: PHP
- Homepage:
- Size: 60.5 KB
- Stars: 4
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
短信发送抽象接口
==============
[](https://github.com/zfegg/sms-sender/actions?query=workflow%3A%22qa%22)
[](https://coveralls.io/github/zfegg/sms-sender?branch=master)
[](https://coveralls.io/github/zfegg/sms-sender?branch=master)
[](https://packagist.org/packages/zfegg/sms-sender)
[](https://packagist.org/packages/zfegg/sms-sender)
[](https://packagist.org/packages/zfegg/sms-sender)
[](https://packagist.org/packages/zfegg/sms-sender)
抽象常用短信业务:
1. 实现短信的限制发送(60s 内限制发送1次,1天上限发送10次)
2. 短信验证码生成与验证功能
## Installation / 安装
使用 Composer 安装
~~~
$ composer require zfegg/sms-sender
~~~
## Interfaces / 接口说明
* `Zfegg/SmsSender/Provider/ProviderInterface` 短信供应商实现接口
## Usage / 使用
### 基本使用示例代码:
[示例代码](examples/basic.php)
### 在 Expressive 中使用:
在 `config/application.php` 中添加模块加载.
~~~php
return array(
'modules' => array(
//... Your modules
'Zfegg/SmsSender'
),
);
~~~
添加短信发送配置 `module.config.php`
~~~php
return [
'dependencies' => [
'factories' => [
ProviderInterface::class => YourSmsProviderFactory::class,
],
]
'zfegg' => [
LimitSender::class => [
'provider' => ProviderInterface::class, // 设置短信商服务名. (可选), 默认 `ProviderInterface::class`
'cache' => CacheInterface::class, // 设置缓存服务名 (可选), 默认 `CacheInterface::class`
'day_send_times' => 10, // 设置每天发送次数上限 (可选), 默认10
'waiting_time' => 60, //设置每次发送等待时长 (可选), 默认60s
],
PostSmsCaptchaHandler::class => [
'types' => [
'register' => 'Register captcha code: {code}',
'login' => 'Login captcha code: {code}',
]
],
]
];
~~~
控制器使用:
~~~php
//发送验证码
$app->post('/api/send-sms-captcha', PostSmsCaptchaHandler::class);
//业务验证码验证
$app->post('/register', [
function ($req, $handler) {
//配置验证器
$inputFilter = (new \Laminas\InputFilter\Factory)->create([
[
'name' => 'captcha',
'validators' => [
[
'name' => SmsCode::class,
'options' => [
'inputName' => 'phone',
]
]
]
],
[
'name' => 'phone',
'validators' => [
[
'name' => 'PhoneNumber',
]
]
],
])
if (! $inputFilter->isValid()) {
//验证失败响应
return new JsonResponse(['messages' => $inputFilter->getMessages()], 403);
}
//验证成功继续注册
return $handler->handle($req);
},
YourRegisterHandler::class,
])
~~~