initialize(); $options = getopt('', ['company-code:', 'actor-id:']); $actor = filter_var($options['actor-id'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); if (!$actor || !in_array((string) $actor, array_map('trim', explode(',', Settings::get('IAM_GROUP_OWNER_IDS'))), true)) throw new RuntimeException('请指定已配置的集团管理员 actor-id'); $code = $options['company-code'] ?? Settings::get('IAM_KEFU_COMPANY_CODE'); if (!is_string($code) || !preg_match('/^[a-z][a-z0-9-]{1,47}$/D', $code)) throw new RuntimeException('请指定客服所属公司编码'); $catalog = json_decode(file_get_contents(dirname(__DIR__, 2) . '/integration/kefu-menu-catalog.json'), true, 64, JSON_THROW_ON_ERROR); $store = new GroupStore((new SourceApiClient())->sourceKey()); echo json_encode((new KefuMenuCatalog($store))->import($catalog, $code, (int) $actor), JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR) . "\n"; } catch (Throwable $error) { fwrite(STDERR, $error instanceof \app\exception\ApiError || get_class($error) === RuntimeException::class ? $error->getMessage() . "\n" : "客服目录导入失败,请检查配置和目录结构。\n"); exit(1); }