#!/usr/bin/env bash # 测试 api/front/integral/list 是否返回支出明细(type=2) # 用法: BASE_URL=http://localhost:8081 ./test-integral-list.sh # 或: ./test-integral-list.sh (默认 BASE_URL=http://localhost:8081) set -e BASE="${BASE_URL:-http://localhost:8081}" USER="13739117991" PASS="123456" echo "=== 测试 integral/list 支出明细 (type=2) ===" echo "BASE_URL=$BASE" echo "" echo "1. 登录 ($USER / $PASS) ..." LOGIN=$(curl -s -X POST "$BASE/api/front/loginV2" \ -H "Content-Type: application/json" \ -d "{\"account\":\"$USER\",\"password\":\"$PASS\"}") if echo "$LOGIN" | grep -qE '"code":\s*(0|200)'; then echo " 登录成功" else echo " 登录失败 (若为「此账号未注册」请在本环境用已注册账号或本地起后端测试): $LOGIN" exit 1 fi TOKEN=$(echo "$LOGIN" | sed -n 's/.*"token":"\([^"]*\)".*/\1/p') if [ -z "$TOKEN" ]; then echo " 未获取到 token" exit 1 fi echo " Token: ${TOKEN:0:24}..." echo "" echo "2. GET api/front/integral/list?page=1&limit=20&type=2 (支出明细) ..." RES=$(curl -s -X GET "$BASE/api/front/integral/list?page=1&limit=20&type=2" \ -H "Content-Type: application/json" \ -H "Authori-zation: $TOKEN") echo "$RES" | head -c 800 echo "" echo "" if echo "$RES" | grep -qE '"code":\s*(0|200)'; then echo "3. 结果: 接口返回成功 (code=0/200)" if echo "$RES" | grep -q '"list":'; then echo " data.list 已返回;带 type=2 时仅包含支出明细,见上方 JSON。" fi exit 0 else echo "3. 结果: 接口未成功 (需登录或 code 非 0/200)" exit 1 fi