# 测试外部接口(模拟任务平台调用) param( [string]$Target = "shadow", # shadow 或 production [string]$TaskNo = "", # 任务号 [string]$ApiKey = "" # API Key ) # 设置目标URL $baseUrl = if ($Target -eq "shadow") { "http://192.168.58.20:5320" } else { "http://192.168.58.20:4320" } Write-Host "========================================" -ForegroundColor Cyan Write-Host "测试外部接口 - $Target 环境" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # 验证参数 if (-not $TaskNo) { Write-Host "错误:请提供任务号" -ForegroundColor Red Write-Host "用法:.\test-external-api.ps1 -TaskNo TASK202601030184 -ApiKey your-api-key" -ForegroundColor Yellow exit 1 } if (-not $ApiKey) { Write-Host "错误:请提供 API Key" -ForegroundColor Red Write-Host "用法:.\test-external-api.ps1 -TaskNo TASK202601030184 -ApiKey your-api-key" -ForegroundColor Yellow exit 1 } # 步骤1:查询素材 Write-Host "步骤1:查询素材信息..." -ForegroundColor Green $queryUrl = "$baseUrl/api/external/product-assets?taskNo=$TaskNo" Write-Host "URL: $queryUrl" -ForegroundColor Gray try { $headers = @{ "X-API-Key" = $ApiKey } $response = Invoke-RestMethod -Uri $queryUrl -Method Get -Headers $headers -ContentType "application/json" Write-Host "✅ 查询成功" -ForegroundColor Green Write-Host "" Write-Host "素材信息:" -ForegroundColor Cyan Write-Host " 任务号: $($response.data.taskNo)" -ForegroundColor White Write-Host " SPU型号: $($response.data.productModel)" -ForegroundColor White Write-Host " 店铺: $($response.data.categoryName)" -ForegroundColor White Write-Host " 场景: $($response.data.sceneName)" -ForegroundColor White Write-Host "" Write-Host "资产统计:" -ForegroundColor Cyan Write-Host " 主图: $($response.data.assets.main.Count) 张" -ForegroundColor White Write-Host " SKU图: $($response.data.assets.sku.Count) 张" -ForegroundColor White Write-Host " 详情图: $($response.data.assets.detail.Count) 张" -ForegroundColor White Write-Host " PSD: $($response.data.assets.psd.Count) 个" -ForegroundColor White Write-Host "" Write-Host "下载链接:" -ForegroundColor Cyan Write-Host " 全部下载: $($response.data.downloadUrls.all)" -ForegroundColor White Write-Host " 主图下载: $($response.data.downloadUrls.main)" -ForegroundColor White Write-Host " SKU图下载: $($response.data.downloadUrls.sku)" -ForegroundColor White Write-Host " 详情图下载: $($response.data.downloadUrls.detail)" -ForegroundColor White if ($response.data.downloadUrls.psd) { Write-Host " PSD下载: $($response.data.downloadUrls.psd)" -ForegroundColor White } Write-Host "" # 步骤2:测试下载链接 Write-Host "步骤2:测试下载链接(全部下载)..." -ForegroundColor Green $downloadUrl = $response.data.downloadUrls.all Write-Host "URL: $downloadUrl" -ForegroundColor Gray # 只测试HEAD请求,不实际下载 try { $headResponse = Invoke-WebRequest -Uri $downloadUrl -Method Head -UseBasicParsing Write-Host "✅ 下载链接有效" -ForegroundColor Green Write-Host " Content-Type: $($headResponse.Headers['Content-Type'])" -ForegroundColor White Write-Host " Content-Length: $([math]::Round($headResponse.Headers['Content-Length'] / 1024 / 1024, 2)) MB" -ForegroundColor White Write-Host " Content-Disposition: $($headResponse.Headers['Content-Disposition'])" -ForegroundColor White } catch { Write-Host "❌ 下载链接测试失败" -ForegroundColor Red Write-Host " 错误: $($_.Exception.Message)" -ForegroundColor Red } } catch { Write-Host "❌ 查询失败" -ForegroundColor Red Write-Host " 错误: $($_.Exception.Message)" -ForegroundColor Red if ($_.Exception.Response) { $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream()) $responseBody = $reader.ReadToEnd() Write-Host " 响应: $responseBody" -ForegroundColor Red } exit 1 } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host "测试完成" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan