PHP code example of onwulc / laravel-sms
1. Go to this page and download the library: Download onwulc/laravel-sms library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
onwulc / laravel-sms example snippets
Toplan\PhpSms\PhpSmsServiceProvider::class,
Toplan\Sms\SmsManagerServiceProvider::class,
'PhpSms' => Toplan\PhpSms\Facades\Sms::class,
'SmsManager' => Toplan\Sms\Facades\SmsManager::class,
php artisan vendor:publish --provider="Toplan\PhpSms\PhpSmsServiceProvider"
php artisan vendor:publish --provider="Toplan\Sms\SmsManagerServiceProvider"
'scheme' => [
//被使用概率为2/3
'Luosimao' => '20',
//被使用概率为1/3,且为备用代理器
'YunPian' => '10 backup',
//仅为备用代理器
'YunTongXun' => '0 backup',
];
'validation' => [
//内置的mobile参数的验证配置
'mobile' => [
'isMobile' => true,
'enable' => true,
'default' => 'mobile_captcha' => [
'enable' => true,
],
],
'content' => function ($code, $minutes, $input) {
return '【signature】您的验证码是' . $code . ',有效期为' . $minutes . '分钟,请尽快验证。';
}
'templates' => [
'YunTongXun' => '短信模版id',
'Alidayu' => ['短信模版id', '语音模版id'],
]
'data' => [
'code' => function ($code) {
return $code;
},
...
],
php artisan migrate
'dbLogs' => true,
$enable = PhpSms::queue(); //true of false
//开启队列:
PhpSms::queue(true);
//关闭队列:
PhpSms::queue(false);
php artisan queue:listen
//example:
PhpSms::queue(function($sms, $data){
//假设如此推入队列:
$this->dispatch(new YourQueueJobClass($sms));
});
//example:
'middleware' => ['api'],
use SmsManager;
$result = SmsManager::validateSendable();
//使用内置的验证逻辑
$result = SmsManager::validateFields();
//自定义验证逻辑
$result = SmsManager::validateFields(function ($fields, $rules) {
//在这里做你的验证处理,并返回结果...
//如:
return Validator::make($fields, $rules);
});
$result = SmsManager::requestVerifySms();
$result = SmsManager::requestVoiceVerify();
//example:
$state = SmsManager::state();
$state = SmsManager::retrieveState();
SmsManager::updateState('key', 'value');
SmsManager::updateState([
'key' => 'value'
]);
SmsManager::forgetState();
//方式1:
//如果不设置name,那么name默认为当前访问路径的path部分
SmsManager::storeRule('mobile', '');
//方式3
SmsManager::storeRule('mobile', [
'myRuleName' => '
$rule = SmsManager::retrieveRule('mobile', 'myRuleName');
$rules = SmsManager::retrieveRules('mobile');
SmsManager::forgetRule('mobile', 'myRuleName');
SmsManager::forgetRules('mobile');
$mobileRuleName = SmsManager::input('mobile_rule');
$all = SmsManager::input();
SmsManager::closure(function () {
//do someting...
});
javascript
$('#sendVerifySmsButton').sms({
//laravel csrf token
//该token仅为laravel框架的csrf验证,不是access_token!
token : "{{csrf_token()}}",
//请求时间间隔
interval : 60,
//语音验证码
voice : false,
//请求参数
requestData : {
//手机号
mobile: function () {
return $('input[name=mobile]').val();
},
//手机号的检测规则
mobile_rule: 'mobile_