option('timeout'), FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); if ($timeout === false) { $this->error('timeout 必须为正整数(单位:秒)。'); return self::FAILURE; } $company = Company::find($this->argument('company_id')); if (!$company) { $this->error('企业不存在。'); return self::FAILURE; } $account = $company->qccAccount; if (!$account || !in_array($account->status, [CompanyQccAccount::STATUS_SELECTED, CompanyQccAccount::STATUS_OCCUPIED, CompanyQccAccount::STATUS_UNKNOWN], true)) { $status = $account ? $account->status : 'none'; $this->error("企业必须处于候选(selected)、已占额(occupied)或待人工确认(unknown)状态,当前状态:{$status}。"); return self::FAILURE; } if (empty(trim((string) $company->credit_code))) { $this->error('企业缺少统一社会信用代码,无法调用 packInfo。'); return self::FAILURE; } try { $response = $yuanheRepository->enterprisePackInfo([ 'creditCode' => $company->credit_code, 'enterpriseName' => $company->company_name, ], $timeout); } catch (Throwable $exception) { // 非 JSON 响应保留原文;没有响应时仅输出错误,不打印签名或请求头。 $result = $exception instanceof YuanhePackInfoException && $exception->rawResponse !== null ? $exception->rawResponse : $exception->getMessage(); $this->output->writeln($result, OutputInterface::OUTPUT_RAW); return self::FAILURE; } $this->output->writeln( json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), OutputInterface::OUTPUT_RAW ); return in_array($response['code'] ?? null, [200, '200'], true) ? self::SUCCESS : self::FAILURE; } }