From c8e60c605951d6640a6a2a548b2264a4df4ab42a Mon Sep 17 00:00:00 2001 From: moyin <244344649@qq.com> Date: Wed, 17 Dec 2025 21:23:27 +0800 Subject: [PATCH] =?UTF-8?q?test=EF=BC=9A=E6=B7=BB=E5=8A=A0=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E9=97=AE=E9=A2=98=E8=B0=83=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建PowerShell调试脚本用于本地测试 - 包含完整的验证码测试流程 - 支持错误验证和正确验证的对比测试 - 自动显示TTL和尝试次数变化 - 便于快速定位验证码相关问题 --- Test-Verification-Debug.ps1 | 112 ++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Test-Verification-Debug.ps1 diff --git a/Test-Verification-Debug.ps1 b/Test-Verification-Debug.ps1 new file mode 100644 index 0000000..00c43e4 --- /dev/null +++ b/Test-Verification-Debug.ps1 @@ -0,0 +1,112 @@ +# 验证码问题调试脚本 +# 作者: moyin +# 日期: 2025-12-17 + +$baseUrl = "http://localhost:3000" +$testEmail = "debug@example.com" + +Write-Host "=== 验证码问题调试脚本 ===" -ForegroundColor Green + +# 步骤1: 发送验证码 +Write-Host "`n1. 发送验证码..." -ForegroundColor Yellow +$sendBody = @{ + email = $testEmail +} | ConvertTo-Json + +try { + $sendResponse = Invoke-RestMethod -Uri "$baseUrl/auth/send-email-verification" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "发送响应: $($sendResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Cyan + + if ($sendResponse.success) { + Write-Host "✅ 验证码发送成功" -ForegroundColor Green + + # 步骤2: 立即查看验证码调试信息 + Write-Host "`n2. 查看验证码调试信息..." -ForegroundColor Yellow + $debugResponse = Invoke-RestMethod -Uri "$baseUrl/auth/debug-verification-code" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "调试信息: $($debugResponse | ConvertTo-Json -Depth 5)" -ForegroundColor Cyan + + # 步骤3: 故意输入错误验证码 + Write-Host "`n3. 测试错误验证码..." -ForegroundColor Yellow + $wrongVerifyBody = @{ + email = $testEmail + verification_code = "000000" + } | ConvertTo-Json + + try { + $wrongResponse = Invoke-RestMethod -Uri "$baseUrl/auth/verify-email" -Method POST -Body $wrongVerifyBody -ContentType "application/json" + Write-Host "错误验证响应: $($wrongResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Red + } catch { + Write-Host "错误验证失败(预期): $($_.Exception.Message)" -ForegroundColor Yellow + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } + } + + # 步骤4: 再次查看调试信息 + Write-Host "`n4. 错误验证后的调试信息..." -ForegroundColor Yellow + $debugResponse2 = Invoke-RestMethod -Uri "$baseUrl/auth/debug-verification-code" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "调试信息: $($debugResponse2 | ConvertTo-Json -Depth 5)" -ForegroundColor Cyan + + # 步骤5: 再次尝试错误验证码 + Write-Host "`n5. 再次测试错误验证码..." -ForegroundColor Yellow + try { + $wrongResponse2 = Invoke-RestMethod -Uri "$baseUrl/auth/verify-email" -Method POST -Body $wrongVerifyBody -ContentType "application/json" + Write-Host "第二次错误验证响应: $($wrongResponse2 | ConvertTo-Json -Depth 3)" -ForegroundColor Red + } catch { + Write-Host "第二次错误验证失败: $($_.Exception.Message)" -ForegroundColor Yellow + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } + } + + # 步骤6: 最终调试信息 + Write-Host "`n6. 最终调试信息..." -ForegroundColor Yellow + $debugResponse3 = Invoke-RestMethod -Uri "$baseUrl/auth/debug-verification-code" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "最终调试信息: $($debugResponse3 | ConvertTo-Json -Depth 5)" -ForegroundColor Cyan + + # 步骤7: 使用正确验证码(如果有的话) + if ($sendResponse.data.verification_code) { + Write-Host "`n7. 使用正确验证码..." -ForegroundColor Yellow + $correctVerifyBody = @{ + email = $testEmail + verification_code = $sendResponse.data.verification_code + } | ConvertTo-Json + + try { + $correctResponse = Invoke-RestMethod -Uri "$baseUrl/auth/verify-email" -Method POST -Body $correctVerifyBody -ContentType "application/json" + Write-Host "正确验证响应: $($correctResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Green + } catch { + Write-Host "正确验证也失败了: $($_.Exception.Message)" -ForegroundColor Red + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } + } + } + + } else { + Write-Host "❌ 验证码发送失败: $($sendResponse.message)" -ForegroundColor Red + } +} catch { + Write-Host "❌ 请求失败: $($_.Exception.Message)" -ForegroundColor Red + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } +} + +Write-Host "`n=== 调试完成 ===" -ForegroundColor Green +Write-Host "请查看上述输出,重点关注:" -ForegroundColor Yellow +Write-Host "1. TTL值的变化" -ForegroundColor White +Write-Host "2. attempts字段的变化" -ForegroundColor White +Write-Host "3. 验证码是否被意外删除" -ForegroundColor White \ No newline at end of file