共用方式為


PlayReady 測試伺服器的Base64 JSON 語法

概觀

PlayReady Test Server 支援 Base64 JSON 語法進行授權設定,提供精簡且 URL 安全的方法來內嵌複雜的授權參數。 此方法會以Base64格式編碼 JSON 組態數據,使其適用於URL參數和 HTTP 標頭。

編碼程式

Base64 JSON 語法牽涉到兩個步驟:

  1. 建立 JSON 組態物件
  2. 使用Base64編碼來編碼 JSON 字串
JSON Configuration → Base64 Encoding → URL Parameter

基本 JSON 結構

編碼之前,請先建立 JSON 組態:

{
  "licenseType": "persistent",
  "keyId": "12345678-1234-1234-1234-123456789012",
  "outputProtection": {
    "digital": "required",
    "analog": "optional"
  }
}

Base64 編碼範例

簡單設定

原始 JSON:

{"licenseType": "persistent", "keyId": "12345678-1234-1234-1234-123456789012"}

Base64 編碼:

eyJsaWNlbnNlVHlwZSI6InBlcnNpc3RlbnQiLCJrZXlJZCI6IjEyMzQ1Njc4LTEyMzQtMTIzNC0xMjM0LTEyMzQ1Njc4OTAxMiJ9

複雜組態

原始 JSON:

{
  "licenseType": "rental",
  "keyId": "87654321-4321-4321-4321-210987654321",
  "expirationDate": "2024-12-31T23:59:59Z",
  "outputProtection": {
    "digital": "required",
    "analog": "never"
  }
}

Base64 編碼:

eyJsaWNlbnNlVHlwZSI6InJlbnRhbCIsImtleUlkIjoiODc2NTQzMjEtNDMyMS00MzIxLTQzMjEtMjEwOTg3NjU0MzIxIiwiZXhwaXJhdGlvbkRhdGUiOiIyMDI0LTEyLTMxVDIzOjU5OjU5WiIsIm91dHB1dFByb3RlY3Rpb24iOnsiZGlnaXRhbCI6InJlcXVpcmVkIiwiYW5hbG9nIjoibmV2ZXIifX0=

URL 使用量

查詢參數格式

https://playready.directtaps.net/pr/svc/rightsmanager.asmx?cfg=base64&data=BASE64_ENCODED_JSON

完整範例 URL

持續性授權

https://playready.directtaps.net/pr/svc/rightsmanager.asmx?cfg=base64&data=eyJsaWNlbnNlVHlwZSI6InBlcnNpc3RlbnQiLCJrZXlJZCI6IjEyMzQ1Njc4LTEyMzQtMTIzNC0xMjM0LTEyMzQ1Njc4OTAxMiJ9

租用授權

https://playready.directtaps.net/pr/svc/rightsmanager.asmx?cfg=base64&data=eyJsaWNlbnNlVHlwZSI6InJlbnRhbCIsImtleUlkIjoiODc2NTQzMjEtNDMyMS00MzIxLTQzMjEtMjEwOTg3NjU0MzIxIiwiZXhwaXJhdGlvbkRhdGUiOiIyMDI0LTEyLTMxVDIzOjU5OjU5WiJ9

設定選項

授權類型

支援所有標準授權類型:

{
  "licenseType": "persistent|non-persistent|rental|subscription"
}

輸出保護設定

設定數位與模擬輸出保護:

{
  "outputProtection": {
    "digital": "required|optional|never",
    "analog": "required|optional|never",
    "hdcp": {
      "version": "1.4|2.0|2.1|2.2",
      "required": true
    }
  }
}

Time-Based 限制

設定到期和寬限期:

{
  "expirationDate": "2024-12-31T23:59:59Z",
  "gracePeriod": 3600,
  "firstPlayExpiration": "PT48H"
}

實作範例

JavaScript/HTML5

// Create configuration object
const config = {
  licenseType: "persistent",
  keyId: keyId,
  outputProtection: {
    digital: "required",
    analog: "optional"
  }
};

// Convert to JSON and encode
const jsonString = JSON.stringify(config);
const base64Data = btoa(jsonString);

// Build URL
const licenseUrl = `https://playready.directtaps.net/pr/svc/rightsmanager.asmx?cfg=base64&data=${base64Data}`;

C# 應用程式

using System;
using System.Text;
using Newtonsoft.Json;

// Create configuration object
var config = new {
    licenseType = "persistent",
    keyId = keyId,
    outputProtection = new {
        digital = "required",
        analog = "optional"
    }
};

// Convert to JSON and encode
string jsonString = JsonConvert.SerializeObject(config);
byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonString);
string base64Data = Convert.ToBase64String(jsonBytes);

// Build URL
string licenseUrl = $"https://playready.directtaps.net/pr/svc/rightsmanager.asmx?cfg=base64&data={base64Data}";

Python 範例

import json
import base64

# Create configuration dictionary
config = {
    "licenseType": "persistent",
    "keyId": key_id,
    "outputProtection": {
        "digital": "required",
        "analog": "optional"
    }
}

# Convert to JSON and encode
json_string = json.dumps(config)
base64_data = base64.b64encode(json_string.encode('utf-8')).decode('utf-8')

# Build URL
license_url = f"https://playready.directtaps.net/pr/svc/rightsmanager.asmx?cfg=base64&data={base64_data}"

進階組態

多軌內容

具有多個曲目的內容設定:

{
  "licenseType": "persistent",
  "tracks": [
    {
      "keyId": "video-key-guid",
      "trackType": "video",
      "outputProtection": {
        "digital": "required"
      }
    },
    {
      "keyId": "audio-key-guid", 
      "trackType": "audio",
      "outputProtection": {
        "digital": "optional"
      }
    }
  ]
}

Domain-Bound 授權

網域系結內容的設定:

{
  "licenseType": "persistent",
  "keyId": "domain-key-guid",
  "domainBinding": {
    "domainId": "domain-service-id",
    "domainAccountId": "account-identifier",
    "required": true
  }
}

測試和驗證

譯碼驗證

若要確認Base64編碼:

// Decode Base64 back to JSON
const decodedJson = atob(base64Data);
const configObject = JSON.parse(decodedJson);
console.log(configObject);

常見測試案例

  1. 基本授權類型:個別測試每個授權類型
  2. 輸出保護:驗證不同的保護層級
  3. 時間限制:測試到期和寬限期
  4. 複雜組態:測試多重追蹤和網域案例

錯誤處理

編碼錯誤

  • 無效的 JSON:編碼之前格式不正確的 JSON 結構
  • 編碼問題:Base64 轉換期間的字元編碼問題
  • URL 安全:確保Base64數據的適當URL編碼

Server-Side 錯誤

  • 譯碼失敗:HTTP 400 與Base64譯碼錯誤
  • JSON 剖析:HTTP 400 與 JSON 結構錯誤
  • 組態無效:HTTP 400 並出現設定驗證錯誤

最佳做法

  1. JSON 驗證:在編碼之前驗證 JSON
  2. URL 編碼:正確編碼 URL 的 Base64 數據
  3. 大小限制:讓設定合理調整 URL 限制的大小
  4. 測試:徹底測試編碼/譯碼程式
  5. 錯誤處理:正常處理編碼和伺服器錯誤

優點

  • 精簡:URL 中比完整 JSON 更精簡
  • URL 安全:Base64 編碼是 URL 安全
  • 彈性:支持複雜的組態物件
  • 標準:使用標準Base64編碼

支援和疑難解答

針對Base64 JSON語法的問題:

  1. 在編碼之前確認 JSON 結構
  2. 測試Base64編碼/譯碼程式
  3. 檢查Base64數據的URL編碼
  4. 驗證組態參數
  5. 檢閱伺服器錯誤回應以取得詳細數據

如需其他支援,請參閱主要的 PlayReady 測試伺服器 檔。