param(); //验证参数 $_rule = [ 'username|登录用户名' => 'require|length:4,20', 'password|登录密码' => 'require|length:6,20', 'key|验证码' => 'require|length:6,200', 'code|验证码' => 'require|length:1,6', ]; $_message = [ 'username.length' => '请输入4到20位的用户名!!!', 'password.length' => '请输入6到20位的密码!!!', 'code.length' => '请输入1到6位的验证码!!!', 'key.length' => '验证码不正确!!!', ]; env('app_debug') ?: validate($_rule, $_message)->check($_post); //验证码检测 env('app_debug') ?: $this->checkCaptcha($_post['code'], $_post['key']); //验证用户信息 $user_data = $manager->checkLogin($_post); //发送JWT签证密钥 $token_obj = (JwtAuth::getInstance())->setToken($user_data); //写入登录日志 defined('CURR_THIS') ?: define('CURR_THIS', get_called_class()); $user_data['user_id'] = $user_data['id']; ActionLog::getInstance()->write($user_data); //获取未读系统邮件 $message = new \app\api\model\Message(); $message->setUserMessage($user_data['user_id'],$user_data['site_id']); //返回数据 $data = [ 'access_token' => [ 'token' => $token_obj->getToken(), 'expire' => config('jwtauth.web.expire_at'), // 'refresh_token' => $token_obj->createRefreshToken(new Token()), ], 'userinfo' => $user_data, ]; return send_http_status($data); } /** * 通过refresh_token重新生成token */ public function refreshToken(Token $token) { $refresh_token = request()->param('refresh_token'); $_data = $token->refreshToken($refresh_token); if (!empty($_data)) { return send_http_status($_data); } return send_http_status('', 40509, 406); } /** * @OA\Get ( * path="login/captcha",tags={"公共分类"},summary="获取验证码",description="获取验证码", * @OA\Response( * response=200, * description="返回验证码信息", * @OA\JsonContent( * @OA\Schema( * required={"code","msg","count","data"}, * @OA\Property( * property="code", * type="integer", * format="int32", * description="状态码" * ), * @OA\Property( * property="msg", * type="string", * description="提示消息" * ), * @OA\Property( * property="count", * type="integer", * format="int32", * description="记录总数", * ), * @OA\Property( * property="data", * type="array", * description="请求结果", * @OA\Items( * @OA\Property( * property="base64", * type="string", * description="base64图片" * ), * @OA\Property( * property="key", * type="string", * description="验证码安全标识" * ), * @OA\Property( * property="md5", * type="string", * description="验证码md5值" * ), * ) * ), * ), * ), * ), * ) * 前后端分离验证码生成 */ public function captcha() { $_data = CaptchaApi::create(); return send_http_status($_data); } /** * 前后端分离验证码检测 * @param string $code * @param string $key */ public function checkCaptcha(string $code = '', string $key = '') { return CaptchaApi::check($code, $key) ?: send_http_status('', 40506); } }