refactor: 修改验证码接口及登录接口

This commit is contained in:
2025-01-02 16:22:58 +08:00
parent 7c6ae67188
commit c3f75fadc9
8 changed files with 109 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ declare (strict_types = 0);
namespace app\admin\controller\v1;
use think\facade\Cache;
use think\facade\Config;
class Captcha
@@ -10,12 +11,22 @@ class Captcha
/**
* 获取验证码
*/
public function index(\think\Config $config, \think\Session $session)
public function index()
{
// 生成token
$token = md5(uniqid() . random_str(8, 'all'));
// 生成验证码
$captcha = \think\captcha\facade\Captcha::create();
// 缓存验证码
$hash = password_hash($captcha['code'], PASSWORD_BCRYPT, ['cost' => 10]);
Cache::store('redis')->set('captcha:token.' . $token, $hash, Config::get('captcha.expire'));
// 输出验证码
$captcha = new \think\captcha\Captcha($config, $session);
$data = $captcha->create();
return success('获取验证码成功!', $data["img"]);
return success('获取验证码成功!', [
'token' => $token,
'captcha' => $captcha["img"],
]);
}
}