From 6dd1d4a24596d0c9200d6824901e8a285ef2d8d7 Mon Sep 17 00:00:00 2001 From: KIMI Date: Sat, 8 Aug 2026 22:49:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20selftest=20=E6=89=80=E6=9C=89=20API=20?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=A1=A5=20operationID=20=E5=A4=B4=EF=BC=88O?= =?UTF-8?q?penIM=20=E5=BC=BA=E5=88=B6=E6=A0=A1=E9=AA=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/selftest.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/selftest.sh b/scripts/selftest.sh index d309aaa..645f5e7 100755 --- a/scripts/selftest.sh +++ b/scripts/selftest.sh @@ -30,11 +30,13 @@ fail() { echo " [失败] $1"; FAILED=1; } note() { echo " [提示] $1"; } # 优先用宿主机 curl;没有则在容器里跑 curl +# OpenIM 所有 API 都要求 operationID 请求头(链路追踪用,每次请求唯一即可) +new_opid() { echo "selftest-$(date +%s%N 2>/dev/null || date +%s)-$RANDOM"; } if command -v curl >/dev/null 2>&1; then - http_post() { curl -s -m 15 -X POST "$1" -H 'Content-Type: application/json' ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } + http_post() { curl -s -m 15 -X POST "$1" -H 'Content-Type: application/json' -H "operationID: $(new_opid)" ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } else note "宿主机无 curl,使用容器化 curl" - http_post() { docker run --rm --network host curlimages/curl:8.10.1 -s -m 15 -X POST "$1" -H 'Content-Type: application/json' ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } + http_post() { docker run --rm --network host curlimages/curl:8.10.1 -s -m 15 -X POST "$1" -H 'Content-Type: application/json' -H "operationID: $(new_opid)" ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } fi json_ok() { echo "$1" | tr -d ' \n' | grep -q '"errCode":0'; }