refactor: 修改验证码接口及登录接口
This commit is contained in:
@@ -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"],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user