PHP code example of ycpfzf / vcode
1. Go to this page and download the library: Download ycpfzf/vcode 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/ */
ycpfzf / vcode example snippets
composer
php artisan vendor:publish
//不指定场景时使用配置文件中 ['sms']['templates']里的 default键指定的模板发送短信
Ycpfzf\Vcode\Vcode::sms()->name('13800138000')->send();
//指定场景 login ,必须在配置文件中的 ['sms']['templates']里有login键,并指定模版
Ycpfzf\Vcode\Vcode::sms()->name('13800138000')->scene('login')->send();
//不指定场景时,默认是default
Ycpfzf\Vcode\Vcode::email()->name('[email protected] ')->subject('验证码')->send();
//指定场景时,配置文件中的 ['email']['templates']指定使用的模板文件
Ycpfzf\Vcode\Vcode::email()->name('[email protected] ')->subject('验证码')->scene('login')->send();
//向模板传递参数,请注意 $code是要发送的验证码
Ycpfzf\Vcode\Vcode::email()->name('[email protected] ')->subject('验证码')->scene('login')->assgin($data)->send();
if(Ycpfzf\Vcode\Vcode::email()->name('[email protected] ')->check(353283)){
echo '验证成功了';
}else{
echo '验证码不正确';
}
//如果是短信验证码,将上面的email()方法换成sms()
Ycpfzf\Vcode\Vcode::sms()->name('13800138000')->queue();
Ycpfzf\Vcode\Vcode::email()->name('[email protected] ')->subject('验证码')->queue();