'手机号', 'mobile_code' => '验证码', 'password_new' => '新密码', ]; } public function resetPasswordAndLogin() { if (!$this->validate()) { throw new Exception($this->getErrorMsg()); } if ($this->mobile_code != $this->getCode()) { throw new Exception('验证码错误'); } $user = $this->getUser(); if (!$user) { throw new Exception('用户信息不存在'); } $user->setPassword($this->password_new); $user->saveOrFail(); return [ 'token' => ServiceUserToken::createToken($this->_user->id), 'user' => $this->_user, ]; } public function getUser(): ?ServiceUser { if ($this->_user === null) { $this->_user = ServiceUser::find()->where([ 'mobile' => $this->mobile, 'is_delete' => 0 ])->one(); } return $this->_user; } public function getCode() { return 1234; } }