TP6實現前後端分離的圖片驗證碼,驗證碼以介面形式返回

_迷途發表於2024-05-21

1. 驗證碼介面

$captcha = captcha();
$data['data'] = [
    'img' => "data:image/png;base64," . base64_encode($captcha->getData()),
    'key' => uniqid()
];
$data['status'] = 200;
return json($data);

2.驗證

$code = '使用者輸入的驗證碼';
$key = session('captcha.key');
if(!password_verify(mb_strtolower($code, 'UTF-8'), $key)){
    //驗證碼錯誤
}

相關文章