php部分
tp5自带的验证码模块,不过还是需要自行安装think-captcha扩展包
composer require topthink/think-captcha
public function getCaptcha()
{
$config = [
// 验证码字符集合
'codeSet' => '0123456789',
// 验证码字体大小
'fontSize' => 30,
//字体
'fontttf' => '5.ttf',
// 验证码位数
'length' => 4,
// 背景颜色
'bg' => [119, 136, 153]
];
$captcha = new Captcha($config);
$re = $captcha->entry();
return 'data:image/png;base64,' . base64_encode($re->getData());
}
前端只需要将此接口返回值放入img标签的src即可
0条评论