pangu-user-platform/scripts/openapi-student-list-test.sh

38 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 开放API-学生列表 调用测试脚本(自动计算签名)
# 用法: ./scripts/openapi-student-list-test.sh <appCode> <appSecret> [baseUrl]
# 示例: ./scripts/openapi-student-list-test.sh YY000001 a1b2c3d4e5f6789012345678901234ab
# @author pangu
set -e
APP_CODE="${1:?请传入 appCode}"
APP_SECRET="${2:?请传入 appSecret}"
BASE_URL="${3:-http://localhost:8080}"
# 请求参数(按 ASCII 排序),与签名一致
PAGE_NUM="${PAGE_NUM:-1}"
PAGE_SIZE="${PAGE_SIZE:-10}"
# 参与签名的参数字符串key 按 ASCII 排序
PARAM_STR="pageNum=${PAGE_NUM}&pageSize=${PAGE_SIZE}&appSecret=${APP_SECRET}"
# MD5 并转大写macOS: md5Linux 可用 md5sum 取第1列
if command -v md5 >/dev/null 2>&1; then
SIGN=$(echo -n "$PARAM_STR" | md5 | tr 'a-z' 'A-Z')
else
SIGN=$(echo -n "$PARAM_STR" | md5sum | awk '{print $1}' | tr 'a-z' 'A-Z')
fi
TIMESTAMP=$(($(date +%s) * 1000))
URL="${BASE_URL}/open/api/student/list?pageNum=${PAGE_NUM}&pageSize=${PAGE_SIZE}"
echo "请求 URL: $URL"
echo "X-App-Id: $APP_CODE"
echo "X-Timestamp: $TIMESTAMP"
echo "X-Sign: $SIGN"
echo "---"
curl -s -w "\n\nHTTP_CODE:%{http_code}" -X GET "$URL" \
-H "X-App-Id: $APP_CODE" \
-H "X-Timestamp: $TIMESTAMP" \
-H "X-Sign: $SIGN"