Files
iotlcm/docs/scripts/query_sim_session.sh
T
2026-10-29 14:59:32 +08:00

42 lines
1.1 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.
#!/usr/bin/env bash
# 查询 SIM 卡会话 — 请求体与 internal/model/sim_chan_api.go 中 SimSessionInput 一致(simKeys)
# 请仅使用获得授权的测试卡
# 用法:在工程根目录执行
# chmod +x docs/scripts/query_sim_session.sh
# ./docs/scripts/query_sim_session.sh
# 可选环境变量:BASE_URL、CHAN_KEY、ICCID(多个用逗号分隔)
set -euo pipefail
BASE_URL="${BASE_URL:-http://127.0.0.1:8110}"
PATH_QUERY="/query/sim-session"
CHAN_KEY="${CHAN_KEY:-YiDong_EC}"
# 不内置真实卡号;调用者必须提供 ICCID
if [[ -z "${ICCID:-}" ]]; then
echo "请设置 ICCID(仅获授权的测试卡)" >&2
exit 2
fi
IFS=',' read -r -a ICCIDS <<< "${ICCID}"
json_simkeys="["
sep=""
for id in "${ICCIDS[@]}"; do
id="$(echo -n "$id" | tr -d '[:space:]')"
[[ -z "$id" ]] && continue
json_simkeys+="${sep}{\"chanKey\":\"${CHAN_KEY}\",\"iccid\":\"${id}\"}"
sep=","
done
json_simkeys+="]"
body="{\"simKeys\":${json_simkeys}}"
echo "# POST ${BASE_URL}${PATH_QUERY}" >&2
echo "# body: ${body}" >&2
echo >&2
curl -sS -X POST "${BASE_URL}${PATH_QUERY}" \
-H 'Content-Type: application/json; charset=utf-8' \
-d "${body}"
echo