$params['mobile']]; $user = Sale::where($where)->findOrEmpty(); if ($user->isEmpty()) { throw new \Exception('无此用户'); } // 账号密码登录 if (LoginEnum::ACCOUNT_PASSWORD == $params['scene']) { if (!isset($params['password'])) { throw new \Exception('请输入密码'); } $passwordSalt = Config::get('project.unique_identification'); if ($user['password'] !== create_password($params['password'], $passwordSalt)) { throw new \Exception('密码错误'); } } // 手机验证码登录 if (LoginEnum::MOBILE_CAPTCHA == $params['scene']) { if (!isset($params['code'])) { throw new \Exception('请输入手机验证码'); } $smsDriver = new SmsDriver(); $result = $smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::LOGIN_CAPTCHA); if (!$result) { throw new \Exception('验证码错误'); } } //获取token $token = create_token($params['mobile']); $user->token = $token; $user->save(); return [ 'id' => $user['id'], 'mobile' => $user['mobile'], 'sale_token' => $token, ]; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } public static function getSaleIdByToken($sale_token) { $user = Sale::where('token',$sale_token)->findOrEmpty(); if ($user->isEmpty()) { return -1; } return $user['id']; } }