type = input('api', UserService::APITYPE_WXAPP); if (empty(UserService::TYPES[$this->type])) { $this->error("接口通道[{$this->type}]未定义规则!"); } $this->user = $this->getUser(); $this->uuid = $this->user['id']; } /** * 获取用户数据 * @return array */ protected function getUser(): array { try { $service = UserService::instance(); if (empty($this->uuid)) { $token = input('token') ?: $this->request->header('token'); if (empty($token)) $this->error('登录认证令牌不能为空!'); [$state, $info, $this->uuid] = $service->checkUserToken($this->type, $token); if (empty($state)) $this->error($info, '{-null-}', 401); } return $service->get($this->type, $this->uuid); } catch (HttpResponseException $exception) { throw $exception; } catch (\Exception $exception) { $this->error($exception->getMessage()); } } }