PHP code example of lswl / laravel-send-cache
1. Go to this page and download the library: Download lswl/laravel-send-cache 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/ */
lswl / laravel-send-cache example snippets
/**
1. 实现缓存类 `\Lswl\SendCaches\SendCache` 方法
2. 实现操作类 `\Lswl\SendCaches\SendCode` 方法
3. 调用发送
*/
// 缓存类实现
use Lswl\SendCaches\SendCache;
class EmailSendCache extends SendCache
{
/**
* {@inheritdoc}
*/
public function name(): string
{
return 'email';
}
}
// 操作类实现
use Lswl\SendCaches\SendCode;
class EmailSendCode extends SendCode
{
/**
* {@inheritdoc}
*/
protected function sendHandler(): bool
{
// 集体发送操作
return true;
}
}
// 实例化邮件发送
$email = new EmailSendCode(new EmailSendCode());
// 返回间隔时间,错误会抛出 `SendCacheException` 异常
$interval = $email
->to('[email protected]')
->code(123456)
->send();
use Lswl\SendCaches\SendCodeCacheHandler;
// 缓存操作
$cacheHandler = new SendCodeCacheHandler(new EmailSendCache());
// 验证,错误会抛出 `SendCacheException` 异常
$cacheHandler->to('[email protected]')
->verify(123456);
// 验证后使用验证码
$cacheHandler->useCode();