laravel api 验证码

composer引入验证码扩展包

composer require gregwar/captcha
build();
        $expire = now()->addMinutes(2);
        $result = [
            'captcha_key' => $key,
            'captcha_image_content' => $captcha->inline(),
            'code' => $captcha->getPhrase(),
        ];
        \Cache::put($key, ['code' => $captcha->getPhrase()], $expire);

        return response_success($result);
    }

    public function getCode(Request $request)
    {
        $key = $request->input('key');
        $code = \Cache::get($key);
        return response_success($code);
    }
}

你可能感兴趣的:(laravel api 验证码)