首先是控制器层
public function doLogin(Request $request)
{
$param = $request->param();
$validate = new LoginValidate();
// 验证参数
$check = $validate->check($param);
if(!$check)
{
return fail('-1', $validate->getError(), []);
}
// 登录操作
$user = new User();
$userInfo = $user->getUserInfo($param['username']);
if(!$userInfo)
{
return fail('-1', '用户不存在', []);
}
else
{
// 考虑密码加盐
$currentPassword = salt($param['password']);
if($currentPassword != $userInfo->password)
{
return fail('-1', '密码错误', []);
}
$jwtService = new JwtService();
$token = $jwtService->getToken($userInfo->id);
$data['token'] =