Lumen图片验证码

  • 代码
/*生成图形验证码*/
public function captchaInfo(CommonHelper $commonHelper)
{
    $captchaUuid = $commonHelper->createCaptchaUuid();
    $img = \Captcha::createById('default', $captchaUuid);
    return $this->formatResponse([
        'img' => 'data:image/png;base64,' . base64_encode($img),
        'uuid' => $captchaUuid
    ]);
}

/*验证图形验证码*/
public function checkCaptcha(Request $request)
{
    $value = $request->get('value');
    $captchaUuid = $request->get('checkCaptcha');
    $valid = \Captcha::checkCaptchaById($value, $captchaUuid);
    return $this->formatResponse($valid);
}
  • 参考文章
    https://github.com/aishan/lumen-captcha

你可能感兴趣的:(Lumen图片验证码)