#!/usr/bin/env bash # 端到端冒烟:送审→发码签发→CSPS→入库→发布→注入→下架 # 依赖:api-svc 运行在 :8080 set -e BASE="http://localhost:8080/api/v1" # HMAC 签名工具(与 httpx.Sign 一致:base64(HMAC-SHA256(secret, METHOD\nPATH))) sign() { # secret method path printf '%s\n%s' "$2" "$3" | openssl dgst -sha256 -hmac "$1" -binary | base64 } call() { # apiKey secret method path jsonBody local key="$1" secret="$2" method="$3" path="$4" body="$5" # 签名只用 path(不含 query),与 Go 端 c.Request.URL.Path 一致 local sigpath="/api/v1${path%%\?*}" local sig; sig=$(sign "$secret" "$method" "$sigpath") if [ "$method" = "GET" ]; then curl -s -X GET "$BASE$path" -H "Authorization: TCS $key:$sig" else curl -s -X "$method" "$BASE$path" \ -H "Authorization: TCS $key:$sig" \ -H "Content-Type: application/json" -d "$body" fi } echo "== 1) CP 送审 ==" REG=$(call ak-cp sk-cp POST /content/register \ '{"title":"示例微短剧","episode_count":24,"category":"WD","file_sha256":"fh-001","merkle_root":"mr-001","perceptual_hash":"ph-001","cp_media_id":"FS-77821","cp_name":"飞翮信息"}') echo "$REG" REVIEW_ID=$(echo "$REG" | sed -n 's/.*"review_id":"\([^"]*\)".*/\1/p') CTID=$(echo "$REG" | sed -n 's/.*"content_twin_id":"\([^"]*\)".*/\1/p') echo "review_id=$REVIEW_ID ctid=$CTID" echo "== 2) 监管发码签发 ==" ISS=$(call ak-regulator sk-regulator POST /content/issue \ "{\"review_id\":\"$REVIEW_ID\",\"issuer\":\"北京市广播电视局\"}") echo "$ISS" MA=$(echo "$ISS" | sed -n 's/.*"ma_code":"\([^"]*\)".*/\1/p') CERT=$(echo "$ISS" | sed -n 's/.*"certificate":"\([^"]*\)".*/\1/p') echo "ma_code=$MA" echo "== 3) CSPS 审核通过 ==" call ak-reviewer sk-reviewer POST /content/csps-result \ "{\"ma_code\":\"$MA\",\"approved\":true,\"reviewer_id\":\"rv-1\"}"; echo echo "== 4) 入媒资库 ==" call ak-reviewer sk-reviewer POST /content/ingest \ "{\"ma_code\":\"$MA\",\"content_twin_id\":\"$CTID\",\"media_asset_id\":\"MEDIA-001\",\"lib_name\":\"广东IPTV媒资库\"}"; echo echo "== 5) 发布给运营商 ==" call ak-reviewer sk-reviewer POST /content/publish \ "{\"ma_code\":\"$MA\",\"certificate\":\"$CERT\"}"; echo echo "== 6) CDN 注入校验(匹配) ==" call ak-operator sk-operator POST /content/inject \ "{\"content_twin_id\":\"$CTID\",\"ma_code\":\"$MA\",\"file_sha256\":\"fh-001\",\"operator_id\":\"CT-IPTV-GD\",\"cdn_endpoint\":\"cdn://ct-gd/vod/1\"}"; echo echo "== 7) CDN 注入校验(篡改,应拒绝) ==" call ak-operator sk-operator POST /content/inject \ "{\"content_twin_id\":\"$CTID\",\"ma_code\":\"$MA\",\"file_sha256\":\"tampered\",\"operator_id\":\"CT-IPTV-GD\",\"cdn_endpoint\":\"cdn://x\"}"; echo echo "== 8) 映射查询 ==" call ak-regulator sk-regulator GET "/content/mappings?ma_code=$MA" ""; echo echo "== 9) 运营商越权下架(应拒绝) ==" call ak-operator sk-operator POST /content/takedown \ "{\"ma_code\":\"$MA\",\"reason\":\"越权\"}"; echo echo "== 10) 监管应急下架 ==" call ak-regulator sk-regulator POST /content/takedown \ "{\"ma_code\":\"$MA\",\"reason\":\"违规\"}"; echo echo "== 完成 =="