# 会员模块接口测试脚本 # 使用前请确保应用已启动在 http://localhost:8084 $BASE_URL = "http://localhost:8084" $TEST_MEMBER_ID = 26 # 测试环境会员ID Write-Host "========================================" -ForegroundColor Cyan Write-Host " 会员模块接口测试" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # ======================================== # 1. 测试获取会员信息 # ======================================== Write-Host "[测试 1] 获取会员信息" -ForegroundColor Yellow Write-Host "请求: GET $BASE_URL/api/member/info" -ForegroundColor Gray Write-Host "Header: X-Member-Id: $TEST_MEMBER_ID" -ForegroundColor Gray try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/member/info" -Method Get -Headers @{ "X-Member-Id" = "$TEST_MEMBER_ID" } Write-Host "✅ 成功" -ForegroundColor Green Write-Host "响应:" -ForegroundColor Cyan $response | ConvertTo-Json -Depth 10 } catch { Write-Host "❌ 失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # ======================================== # 2. 测试查询关注状态 # ======================================== Write-Host "[测试 2] 查询关注状态" -ForegroundColor Yellow Write-Host "请求: GET $BASE_URL/api/member/subscribe/status" -ForegroundColor Gray Write-Host "Header: X-Member-Id: $TEST_MEMBER_ID" -ForegroundColor Gray try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/member/subscribe/status" -Method Get -Headers @{ "X-Member-Id" = "$TEST_MEMBER_ID" } Write-Host "✅ 成功" -ForegroundColor Green Write-Host "响应: $response" -ForegroundColor Cyan } catch { Write-Host "❌ 失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # ======================================== # 3. 测试更新会员信息 # ======================================== Write-Host "[测试 3] 更新会员信息" -ForegroundColor Yellow Write-Host "请求: PUT $BASE_URL/api/member/info?nickname=测试用户&gender=1&birthday=1990-01-01&address=测试地址" -ForegroundColor Gray Write-Host "Header: X-Member-Id: $TEST_MEMBER_ID" -ForegroundColor Gray try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/member/info?nickname=测试用户&gender=1&birthday=1990-01-01&address=测试地址" -Method Put -Headers @{ "X-Member-Id" = "$TEST_MEMBER_ID" } Write-Host "✅ 成功" -ForegroundColor Green Write-Host "响应: $response" -ForegroundColor Cyan } catch { Write-Host "❌ 失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # ======================================== # 4. 测试管理端录入手机号 # ======================================== Write-Host "[测试 4] 管理端录入手机号" -ForegroundColor Yellow Write-Host "请求: POST $BASE_URL/api/admin/members/$TEST_MEMBER_ID/phone" -ForegroundColor Gray Write-Host "Body: { `"phone`": `"13800138000`" }" -ForegroundColor Gray try { $body = @{ phone = "13800138000" } | ConvertTo-Json $response = Invoke-RestMethod -Uri "$BASE_URL/api/admin/members/$TEST_MEMBER_ID/phone" -Method Post -Body $body -ContentType "application/json" Write-Host "✅ 成功" -ForegroundColor Green Write-Host "响应: $response" -ForegroundColor Cyan } catch { Write-Host "❌ 失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # ======================================== # 5. 再次获取会员信息(验证手机号已更新) # ======================================== Write-Host "[测试 5] 验证手机号已更新" -ForegroundColor Yellow Write-Host "请求: GET $BASE_URL/api/member/info" -ForegroundColor Gray Write-Host "Header: X-Member-Id: $TEST_MEMBER_ID" -ForegroundColor Gray try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/member/info" -Method Get -Headers @{ "X-Member-Id" = "$TEST_MEMBER_ID" } Write-Host "✅ 成功" -ForegroundColor Green Write-Host "响应:" -ForegroundColor Cyan $response | ConvertTo-Json -Depth 10 if ($response.hasPhone) { Write-Host "✅ 手机号已成功绑定" -ForegroundColor Green } else { Write-Host "⚠️ 手机号未绑定" -ForegroundColor Yellow } } catch { Write-Host "❌ 失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # ======================================== # 6. 测试小程序登录(需要有效的code) # ======================================== Write-Host "[测试 6] 小程序登录(需要提供有效的微信code)" -ForegroundColor Yellow Write-Host "注意: 此测试需要从小程序获取真实的code,跳过自动测试" -ForegroundColor Gray Write-Host "手动测试命令:" -ForegroundColor Cyan Write-Host "curl -X POST $BASE_URL/api/member/auth/miniapp/login \" -ForegroundColor Gray Write-Host " -H `"Content-Type: application/json`" \" -ForegroundColor Gray Write-Host " -d `"{`"code`":`"YOUR_CODE_HERE`"}"`" -ForegroundColor Gray Write-Host "" # ======================================== # 7. 测试服务号回调验证签名 # ======================================== Write-Host "[测试 7] 服务号回调验证签名" -ForegroundColor Yellow Write-Host "请求: GET $BASE_URL/api/member/auth/mp/callback?signature=test×tamp=123&nonce=test&echostr=test" -ForegroundColor Gray try { $response = Invoke-RestMethod -Uri "$BASE_URL/api/member/auth/mp/callback?signature=test×tamp=123&nonce=test&echostr=test" -Method Get Write-Host "✅ 成功(返回echostr表示验证通过)" -ForegroundColor Green Write-Host "响应: $response" -ForegroundColor Cyan } catch { Write-Host "❌ 失败: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # ======================================== # 总结 # ======================================== Write-Host "========================================" -ForegroundColor Cyan Write-Host " 测试完成" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "提示:" -ForegroundColor Yellow Write-Host "1. 小程序登录需要提供真实的微信code" -ForegroundColor Gray Write-Host "2. 服务号回调需要微信服务器推送的真实事件" -ForegroundColor Gray Write-Host "3. 管理端录入手机号需要配置正确的AES密钥" -ForegroundColor Gray Write-Host ""