> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 啟用授權測試

> 設定可授權的 XBOX 開發組建以測試 XStore 授權 API，包括相關案例以及 Partner 中必要的設定步驟。

本文說明如何將開發組建設定為可授權，以測試與授權相關的案例。

## 相關案例和 API

若要測試下列 API，您需要依照本文所述設定您的開發環境：

| API | 用法 |
| - | - |
| [XStoreQueryGameLicenseAsync](/zh-TW/reference/system/xstore/xstore_members) | 查詢遊戲試用版或光碟型授權的特性。 |
| [XStoreQueryLicenseTokenAsync](/zh-TW/reference/system/xstore/xstore_members) | 產生有效的授權權杖以進行服務型驗證，請參閱[使用授權權杖](/zh-TW/publishing/xstore-commerce/xstore-license-tokens)。 |
| [XStoreQueryAddOnLicensesAsync](/zh-TW/reference/system/xstore/xstore_members) | 傳回附加至數位遊戲授權的附加元件授權 (不含套件的耐久性產品)。 |
| [XStoreRegisterGameLicenseChanged](/zh-TW/reference/system/xstore/xstore_members) | 註冊以偵測授權變更 (例如，試用版授權升級為完整授權時)。 |

## 背景

在零售案例中，遊戲必須擁有授權才能遊玩。授權要求會檢查已安裝的光碟，或將要求傳送至 Microsoft 服務。如果帳戶透過直接購買或滿足條件的購買 (例如來自訂閱或套件組合) 而有權使用該產品，就會授予授權。在共用案例中也可以授予授權。如需共用的詳細資訊，請參閱[遊戲的產品共用模型](/zh-TW/publishing/xstore-commerce/xstore-product-sharing)。

開發案例預設不會遵循此行為。這些案例包括：

* 鬆散組建 (Visual Studio F5 部署、xbapp/wdapp register/deploy)
* 本機套件組建 (makepkg、xbapp/wdapp install)

這些組建啟動時不會進行任何授權檢查或相關設定。大部分的 `XStore` API 仍可運作，但為遊戲或耐久性產品授權時可能會出現非預期的結果。

若要將組建設定為以可授權的方式運作，請將正確的識別值套用至 MicrosoftGameConfig (如[啟用 XStore 開發與測試](/zh-TW/publishing/xstore-commerce/xstore-product-testing-setup)中所述)。

接著必須執行下列步驟：

1. [記下遊戲或 DLC 特定的內容識別碼](#get-contentid)
2. [依組建類型將內容識別碼套用至組建](#apply-content-id-to-build)
3. [**僅限主機**：記下 EKBID 並套用至組建](#apply-ekbid-to-build-only-applicable-to-console)

然後，對於每個執行該組建的帳戶，都必須從平台的對應 Store 購買產品以取得權利。

## 取得 ContentID

選取 **Show details** 後，您可以在 **Packages** 頁面上找到 ContentID：

<img src="https://mintcdn.com/microsoft-4404708b/iADzli99B7EWodAv/images/xstore/packagedetails.png?fit=max&auto=format&n=iADzli99B7EWodAv&q=85&s=a3facb4ae0079bb08cc33e22f6688d65" alt="Partner Center 上的套件頁面" width="1029" height="520" data-path="images/xstore/packagedetails.png" />

<Note>
  沙箱版本和零售版本的內容識別碼可能不同。如果您安裝遊戲的零售版本，產品會與不同於沙箱所需的內容識別碼相關聯。如果涉及區域性套件，內容識別碼也會不同。
</Note>

### 主機

在 Gaming Command Prompt 中執行 `xbapp list /d` (若是 DLC 則執行 `xbapp listdlc /d`)，以找出已安裝套件的內容識別碼。

```cmd theme={null}
Registered Applications by Package Full Name:

   41336MicrosoftATG.InGameStoreXS_2020.7.27.0_neutral__dspnxghe87tn0  
        Install  
        Drive: Development  
        Size: 0.28 GB.  
        ContentId: {2797FA46-A93B-494C-AD80-B67C9FCA939F}  
        ProductId: {4C544E39-5130-3044-C057-5A3446536A00}  
        EKBID: {37E80840-6BE0-46F8-8EDB-92F877056087}  
        DisplayName: ATG In-Game Store Sample  
        41336MicrosoftATG.InGameStoreXS_dspnxghe87tn0!Game  
```

### PC

在 Gaming Command Prompt 中執行 `wdapp list /d` (若是 DLC 則執行 `wdapp listdlc /d`)，以找出已安裝套件的內容識別碼。若是從 Store 安裝的套件，請使用 `/includeStore` 旗標。

## 將內容識別碼套用至組建

若是鬆散組建，請在 MicrosoftGameConfig 中新增下列區段：

```xml theme={null}
  <DevelopmentOnly>
    <ContentIdOverride>2797FA46-A93B-494C-AD80-B67C9FCA939F</ContentIdOverride>
    <EKBIDOverride>00000000-0000-0000-0000-000000000001</EKBIDOverride>
  </DevelopmentOnly>
```

若是套件組建，請將內容識別碼傳遞給 `makepkg`。例如：

```cmd theme={null}
makepkg pack /v /f chunks.xml /d Gaming.Xbox.XboxOne.x64\Layout\Image\Loose /pd ./output /contentid 2797FA46-A93B-494C-AD80-B67C9FCA939F
```

如果您建立套件時未使用 `/contentid` 參數，當您從本機來源安裝時，安裝程序會套用 MicrosoftGameConfig 中任何可用的 `ContentIdOverride`。

從 Store (沙箱或零售) 安裝的組建一律具有正確的內容識別碼 (如 Partner Center 中所示)。

## 將 EKBID 套用至組建 (僅適用於主機)

設定 EKBID (Escrow Key Blob ID)，讓組建在主機上可授權。在大部分案例中，只需將其從全為零或 33EC8436-5A0E-4F0D-B1CE-3F29C3955039 的預設測試值覆寫即可。

使用下列命令覆寫 EKBID：

```cmd theme={null}
xbapp setekbid <package full name> {<GUID that is not all zeroes or 33EC8436-5A0E-4F0D-B1CE-3F29C3955039>}
```

例如：

```cmd theme={null}
xbapp setekbid 41336MicrosoftATG.InGameStoreXS_2020.7.27.0_neutral__dspnxghe87tn0 {00000000-0000-0000-0000-000000000001}
```

此設定與 PC 無關 (沒有 `wdapp setekbid` 命令)。

### 試用版和 EKBID

若是**試用版**，必須套用實際的 EKBID。若要找出遊戲使用的 EKBID，請對從 Store 安裝的組建執行 `xbapp list /d`。如需詳細資訊，請參閱[為您的遊戲實作試用版](/zh-TW/publishing/xstore-commerce/xstore-trials)。

## 確保測試帳戶在沙箱中有權使用產品

對於同時發佈到沙箱和零售環境的產品，您可以使用 DevEntitlementTool 查詢並取得測試帳戶的權利。

取得權利的最佳方式是透過通訊協定啟用直接前往產品的 Store 頁面，因為僅發佈到沙箱的產品可能無法搜尋。開發主機或 PC 必須設定為遊戲發佈所在的沙箱。如需詳細資訊，請參閱 XBOX services 沙箱概觀文件；若是 PC，請參閱[針對 Store 作業正確切換沙箱](/zh-TW/publishing/xstore-commerce/xstore-switching-sandbox)。

正確登入後，請使用 Store 通訊協定連結前往 Store 頁面：

**在主機上：**

使用 Gaming Command Prompt：

`xbapp launch ms-windows-store://pdp/?productid=<storeID>`

**在 PC 上：**

在 \[執行] 方塊 (⊞Win +R) 或網頁瀏覽器中

`msxbox://game/?productId=<storeID>` (在 XBOX App 中顯示產品)

或

`ms-windows-store://pdp/?productid=<storeID>` (在 Microsoft Store 中顯示產品)

進入 Store 頁面後，選取 **Buy** 或 **Get**，為您的測試帳戶取得產品的授權。遊戲和 DLC 的下載與安裝應會自動開始。如果您打算使用本機組建反覆進行，可以取消此作業。

<Note>
  您必須為每個執行該組建，並期望與授權相關的 XStore API 能夠運作的帳戶取得權利。
</Note>

## DLC

若要讓本機 DLC 可授權，必須將內容識別碼套用至 `makepkg`，並將 `xbapp setekbid` 設定為預設值以外的值。只有 DLC 需要設定授權，基礎遊戲則不需要。

以含套件的耐久性產品呼叫下列 API 時，授權覆寫與其相關：

* [XStoreAcquireLicenseForDurablesAsync](/zh-TW/reference/system/xstore/xstore_members)
* [XStoreAcquireLicenseForPackageAsync](/zh-TW/reference/system/xstore/xstore_members)
* [XStoreCanAcquireLicenseForPackageAsync](/zh-TW/reference/system/xstore/xstore_members)
* [XStoreCanAcquireLicenseForStoreIdAsync](/zh-TW/reference/system/xstore/xstore_members)
* [XStoreRegisterPackageLicenseLost](/zh-TW/reference/system/xstore/xstore_members)

您可以在這裡找到更多詳細資料：

[管理可下載內容 (DLC) 並授權](/zh-TW/publishing/xstore-commerce/xstore-dlc)

[如何使用不含套件的耐久性產品](/zh-TW/publishing/xstore-commerce/xstore-dwob)

## 參考 API 文件

* [XStore (API 內容)](/zh-TW/reference/system/xstore/xstore_members)
  * 函式
    * [XStoreQueryGameLicenseAsync](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreQueryLicenseTokenAsync](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreQueryAddOnLicensesAsync](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreRegisterGameLicenseChanged](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreAcquireLicenseForDurablesAsync](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreAcquireLicenseForPackageAsync](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreCanAcquireLicenseForPackageAsync](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreCanAcquireLicenseForStoreIdAsync](/zh-TW/reference/system/xstore/xstore_members)
    * [XStoreRegisterPackageLicenseLost](/zh-TW/reference/system/xstore/xstore_members)

## 另請參閱

[商務概觀](/zh-TW/publishing/xstore-commerce/xstore-commerce-overview)<br />[啟用 XStore 開發與測試](/zh-TW/publishing/xstore-commerce/xstore-product-testing-setup)<br />[針對 Store 作業正確切換沙箱](/zh-TW/publishing/xstore-commerce/xstore-switching-sandbox)<br />[XStore API 參考](/zh-TW/reference/system/xstore/xstore_members)


## Related topics

- [XR-112 在初始啟用和繼續時建立使用者與控制器](/zh-TW/publishing/certification/xr/xr-112.md)
- [媒體驗證測試步驟](/zh-TW/publishing/game-publishing/concepts/certification/certification-media-validation-test-steps.md)
- [XBOX 主機遊戲的認證測試 XBOX 需求](/zh-TW/publishing/certification/console-cert-tested-requirements.md)
- [启用授权测试](/zh-CN/publishing/xstore-commerce/xstore-licensing-setup.md)
- [GDK 被授權人的安全性要求](/zh-TW/home/onboarding-access/security-requirements.md)
