> ## 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.

# XStoreQueryLicenseTokenAsync

> XStoreQueryLicenseTokenAsync 的參考資料，這是 GDK XStore 授權函式，可擷取用於權利驗證和 B2B 呼叫的 JSON Web 權杖。

# XStoreQueryLicenseTokenAsync

為呼叫的遊戲提供不透明的 JSON Web 權杖，可傳遞給遊戲的服務以驗證權利並進行 B2B 呼叫。如需詳細資訊，請參閱[授權權杖概觀](/zh-TW/publishing/xstore-commerce/xstore-license-tokens)。

## 語法

```cpp theme={null}
HRESULT XStoreQueryLicenseTokenAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char** productIds,  
         size_t productIdsCount,  
         const char* customDeveloperString,  
         XAsyncBlock* async  
)  
```

### 參數

*storeContextHandle*   \_In\_\
類型：XStoreContextHandle

由 [XStoreCreateContext](/zh-TW/reference/system/xstore/functions/xstorecreatecontext) 傳回的使用者市集內容控制代碼。

*productIds*   \_In\_z\_count\_(productIdsCount)\
類型：char\*\*

要擷取權杖的產品識別碼陣列。

*productIdsCount*   \_In\_\
類型：size\_t

傳入 **productIds** 之陣列中的識別碼數目。

*customDeveloperString*   \_In\_z\_\
類型：char\*

會往返傳入權杖中的值。此值通常由服務選擇。您可以插入使用者識別碼或電子郵件之類的內容，以便在授權權杖中追蹤使用者的權杖。授權權杖的用途類似擁有權的收據。

此值不可為 null 或空字串。

*async*   \_Inout\_\
類型：[XAsyncBlock\*](/zh-TW/reference/system/xasync/structs/xasyncblock)

定義正在進行之非同步工作的 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock) 可用來輪詢呼叫的狀態並擷取呼叫結果。如需詳細資訊，請參閱 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。

## 備註

若要擷取 JSON Web 權杖以及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreQueryLicenseTokenResult](/zh-TW/reference/system/xstore/functions/xstorequerylicensetokenresult)。若要擷取 JSON Web 權杖的大小，請在呼叫此函式之後呼叫 [XStoreQueryLicenseTokenResultSize](/zh-TW/reference/system/xstore/functions/xstorequerylicensetokenresultsize)。知道權杖的大小可讓您更有效率地擷取權杖。

授權權杖是以 Base64 編碼的 JSON Web 權杖。權杖的承載是以 Base64 編碼的字串，可轉換成可在伺服器上用於驗證的 JSON 值。

下列程式碼片段示範擷取授權權杖的範例。

```cpp theme={null}
void CALLBACK QueryLicenseTokenCallback(XAsyncBlock* asyncBlock)
{
    size_t size;
    HRESULT hr = XStoreQueryLicenseTokenResultSize(
        asyncBlock,
        &size);

    if (FAILED(hr))
    {
        printf("Failed retrieve the license token size: 0x%x\r\n", hr);
        return;
    }

    char* result = new char[size];
    hr = XStoreQueryLicenseTokenResult(
        asyncBlock,
        size,
        result);

    if (FAILED(hr))
    {
        printf("Failed retrieve the license token result: 0x%x\r\n", hr);
        delete[] result;
        return;
    }

    printf("result: %s\r\n", result);

    delete[] result;
}

void QueryLicenseToken(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char** productIds, size_t productIdsCount, const char* customDeveloperString)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = QueryLicenseTokenCallback;

    HRESULT hr = XStoreQueryLicenseTokenAsync(
        storeContextHandle,
        productIds,
        productIdsCount,
        customDeveloperString,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get license token: 0x%x\r\n", hr);
        return;
    }
}
```

## 需求

**標頭：** XStore.h (包含在 XGameRuntime.h 中)

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [授與玩家附加元件內容的存取權](/zh-TW/publishing/xstore-commerce/xstore-granting-access)
* [啟用授權測試](/zh-TW/publishing/xstore-commerce/xstore-licensing-setup)
* [基本 DRM 和授權檢查](/zh-TW/publishing/xstore-commerce/xstore-pc)
* [使用授權權杖在您的服務上驗證授權](/zh-TW/publishing/xstore-commerce/xstore-license-tokens)

## 另請參閱

[XStore](/zh-TW/reference/system/xstore/xstore_members)

[授權權杖概觀](/zh-TW/publishing/xstore-commerce/xstore-license-tokens)

[XStoreQueryLicenseTokenResult](/zh-TW/reference/system/xstore/functions/xstorequerylicensetokenresult)

[XStoreQueryLicenseTokenResultSize](/zh-TW/reference/system/xstore/functions/xstorequerylicensetokenresultsize)


## Related topics

- [XStoreQueryLicenseTokenAsync](/zh-CN/reference/system/xstore/functions/xstorequerylicensetokenasync.md)
- [XStoreQueryLicenseTokenResult](/reference/system/xstore/functions/xstorequerylicensetokenresult.md)
- [XStoreQueryLicenseTokenResultSize](/reference/system/xstore/functions/xstorequerylicensetokenresultsize.md)
