PHP code example of zhouzishu / laravel-sms
1. Go to this page and download the library: Download zhouzishu/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/ */
zhouzishu / laravel-sms example snippets
Zhouzishu\LaravelSms\SmsManagerServiceProvider::class,
'SmsManager' => Zhouzishu\LaravelSms\Facades\SmsManager::class,
php artisan vendor:publish --provider="Zhouzishu\LaravelSms\SmsManagerServiceProvider"
'validation' => [
//内置的mobile参数的验证配置
'mobile' => [
'isMobile' => true,
'enable' => true,
'default' => 'mobile_captcha' => [
'enable' => true,
],
],
'content' => function ($code, $minutes, $input) {
return '【signature】您的验证码是' . $code . ',有效期为' . $minutes . '分钟,请尽快验证。';
}
php artisan migrate
'dbLogs' => true,
//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();
//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,
//请求参数
requestData : {
//手机号
mobile: function () {
return $('input[name=mobile]').val();
},
//手机号的检测规则
mobile_rule: 'mobile_