type = $this->request->header('api-name') ?: input('api'); $this->type = $this->type ?: $this->request->header('api-type'); if (empty($this->type) || empty(UserAdminService::TYPES[$this->type])) { $this->error("接口支付未定义!"); } // 获取用户数据 $this->user = $this->getUser(); $this->uuid = $this->user['id'] ?? ''; if (empty($this->uuid)) { $this->error('用户登录失败!', '{-null-}', 401); } } /** * 获取用户数据 * @return array */ protected function getUser(): array { try { if (empty($this->uuid)) { $token = input('token') ?: $this->request->header('api-token'); if (empty($token)) $this->error('登录认证TOKEN不能为空!'); [$state, $info, $this->uuid] = UserTokenService::instance()->check($this->type, $token); if (empty($state)) $this->error($info, '{-null-}', 401); } return UserAdminService::instance()->get($this->uuid, $this->type); } catch (HttpResponseException $exception) { throw $exception; } catch (\Exception $exception) { $this->error($exception->getMessage()); } } }