type = input('api') ?: $this->request->header('api-type'); $this->type = $this->type ?: 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 { $user = UserService::instance(); if (empty($this->uuid)) { $token = input('token') ?: $this->request->header('api-token'); if (empty($token)) $this->error('登录认证TOKEN不能为空!'); [$state, $info, $this->uuid] = $user->check($this->type, $token); if (empty($state)) $this->error($info, '{-null-}', 401); } return $user->get($this->type, $this->uuid); } catch (HttpResponseException $exception) { throw $exception; } catch (\Exception $exception) { $this->error($exception->getMessage()); } } }