$ErrorActionPreference = 'Stop' $body = '{"username":"admin","password":"123456"}' $r = Invoke-RestMethod -Uri 'http://localhost:5246/api/auth/login' -Method Post -ContentType 'application/json' -Body $body $token = $r.token $h = @{ Authorization = "Bearer $token"; 'Content-Type' = 'application/json' } Write-Output '== 创建农户1(四川锦江区) ==' $f1 = @{ name = '测试农户一'; idCard = '511302199001011234'; gender = '男'; phone = '138 1234 5678' province = '四川省'; county = '锦江区'; township = '春熙路街道'; village = '水井坊村'; groupName = '3组' address = '锦江区某路1号'; bankName = '中国农业银行'; bankAccount = '622848 0408 1234 5678' creditScore = 85; status = 'Active'; notes = '四级地区+银行+手机号测试' } | ConvertTo-Json $c1 = Invoke-RestMethod -Uri 'http://localhost:5246/api/farmers' -Method Post -Headers $h -Body $f1 $c1 | ConvertTo-Json -Compress Write-Output '== 创建农户2(广西平南县) ==' $f2 = @{ name = '测试农户二'; idCard = '452122199001012345'; gender = '女'; phone = '13911110002' province = '广西壮族自治区'; county = '平南县'; township = '大安镇'; village = '稻香村'; groupName = '5组' address = '平南县大安镇稻香村'; bankName = ''; bankAccount = '' creditScore = 80; status = 'Active'; notes = '' } | ConvertTo-Json $c2 = Invoke-RestMethod -Uri 'http://localhost:5246/api/farmers' -Method Post -Headers $h -Body $f2 $c2 | ConvertTo-Json -Compress Write-Output '== 村列表(按锦江区/春熙路街道) ==' (Invoke-RestMethod -Uri 'http://localhost:5246/api/regions/villages?county=%E9%94%A6%E6%B1%9F%E5%8C%BA&township=%E6%98%A5%E7%86%99%E8%B7%AF%E8%A1%97%E9%81%93' -Headers $h) -join ', ' Write-Output '== 组列表(按锦江区/春熙路街道/水井坊村) ==' (Invoke-RestMethod -Uri 'http://localhost:5246/api/regions/groups?county=%E9%94%A6%E6%B1%9F%E5%8C%BA&township=%E6%98%A5%E7%86%99%E8%B7%AF%E8%A1%97%E9%81%93&village=%E6%B0%B4%E4%BA%95%E5%9D%8A%E6%9D%91' -Headers $h) -join ', ' Write-Output '== 乡镇列表(锦江区,含农户补充) ==' (Invoke-RestMethod -Uri 'http://localhost:5246/api/regions/townships?county=%E9%94%A6%E6%B1%9F%E5%8C%BA' -Headers $h) -join ', ' Write-Output '== 列表按县筛选(平南县) ==' $list = Invoke-RestMethod -Uri 'http://localhost:5246/api/farmers?county=%E5%B9%B3%E5%8D%97%E5%8E%BF&page=1&pageSize=10' -Headers $h "total=$($list.total)" $list.items | ForEach-Object { "$($_.name) | $($_.province)/$($_.county)/$($_.township)/$($_.village)/$($_.groupName) | $($_.phone) | $($_.bankAccount)" } Write-Output '== /farmers/all 新字段 ==' $all = Invoke-RestMethod -Uri 'http://localhost:5246/api/farmers/all?limit=5' -Headers $h $all | ForEach-Object { "$($_.name) | province=$($_.province) county=$($_.county) township=$($_.township) village=$($_.village) groupName=$($_.groupName)" }