56 lines
1.9 KiB
PowerShell
56 lines
1.9 KiB
PowerShell
|
|
# 测试API的PowerShell脚本
|
|||
|
|
|
|||
|
|
$API_BASE_URL = "http://localhost:5003/api/v1"
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
# 1. 注册用户
|
|||
|
|
Write-Host "1. 注册用户..."
|
|||
|
|
$registerBody = @{
|
|||
|
|
username = "testuser"
|
|||
|
|
email = "test@example.com"
|
|||
|
|
password = "password123"
|
|||
|
|
} | ConvertTo-Json
|
|||
|
|
|
|||
|
|
$registerResponse = Invoke-RestMethod -Uri "$API_BASE_URL/auth/register" -Method Post -Body $registerBody -ContentType "application/json"
|
|||
|
|
$token = $registerResponse.data.token
|
|||
|
|
Write-Host "注册成功,获取到token: $token"
|
|||
|
|
|
|||
|
|
# 2. 创建邮件
|
|||
|
|
Write-Host "`n2. 创建邮件..."
|
|||
|
|
$sendTime = (Get-Date).AddDays(1).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
|
|||
|
|
$mailData = @{
|
|||
|
|
title = "测试邮件"
|
|||
|
|
content = "这是一封测试邮件内容"
|
|||
|
|
recipientType = "SELF"
|
|||
|
|
sendTime = $sendTime
|
|||
|
|
triggerType = "TIME"
|
|||
|
|
triggerCondition = @{}
|
|||
|
|
attachments = @()
|
|||
|
|
isEncrypted = $false
|
|||
|
|
capsuleStyle = "default"
|
|||
|
|
} | ConvertTo-Json -Depth 10
|
|||
|
|
|
|||
|
|
$headers = @{
|
|||
|
|
"Authorization" = "Bearer $token"
|
|||
|
|
"Content-Type" = "application/json"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$createMailResponse = Invoke-RestMethod -Uri "$API_BASE_URL/mails/create" -Method Post -Body $mailData -Headers $headers
|
|||
|
|
Write-Host "创建邮件成功:"
|
|||
|
|
$createMailResponse | ConvertTo-Json -Depth 10
|
|||
|
|
|
|||
|
|
# 3. 获取邮件列表
|
|||
|
|
Write-Host "`n3. 获取邮件列表..."
|
|||
|
|
$mailsResponse = Invoke-RestMethod -Uri "$API_BASE_URL/mails?type=SENT&page=1&size=20" -Method Get -Headers $headers
|
|||
|
|
Write-Host "获取邮件列表成功:"
|
|||
|
|
$mailsResponse | ConvertTo-Json -Depth 10
|
|||
|
|
|
|||
|
|
} catch {
|
|||
|
|
Write-Host "测试失败: $($_.Exception.Message)"
|
|||
|
|
if ($_.Exception.Response) {
|
|||
|
|
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
|
|||
|
|
$reader.BaseStream.Position = 0
|
|||
|
|
$errorBody = $reader.ReadToEnd()
|
|||
|
|
Write-Host "错误详情: $errorBody"
|
|||
|
|
}
|
|||
|
|
}
|