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

# XStoreQueryLicenseTokenAsync

向调用游戏提供一个不透明的 JSON Web 令牌，该令牌可传递给游戏的服务以验证权益并进行 B2B 调用。有关详细信息，请参阅[许可证令牌概述](/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](/reference/system/xstore/functions/xstorecreatecontext) 返回的用户的应用商店上下文句柄。

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

要检索令牌的产品 ID 数组。

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

传递到 **productIds** 的数组中的 ID 数量。

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

一个来回传递到令牌中的值。此值通常由服务选择。可以插入类似 userId 或 email 之类的内容，以在许可证令牌中跟踪用户的令牌。许可证令牌用作所有权凭证。

不能为 null 或空字符串。

*async*   \_Inout\_\
类型：[XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

定义正在执行的异步工作的 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。可使用 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) 轮询调用状态并检索调用结果。有关详细信息，请参阅 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

要检索 JSON Web 令牌以及此函数的执行结果，请在调用此函数后调用 [XStoreQueryLicenseTokenResult](/reference/system/xstore/functions/xstorequerylicensetokenresult)。要检索 JSON Web 令牌的大小，请在调用此函数后调用 [XStoreQueryLicenseTokenResultSize](/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 主机

## 概念文档

* [向玩家授予附加内容的访问权限](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-granting-access-to-content)
* [启用许可证测试](/publishing/xstore-commerce/xstore-licensing-setup)
* [基本 DRM 和许可证检查](/publishing/xstore-commerce/xstore-pc)
* [使用许可证令牌在你的服务上验证许可](/publishing/xstore-commerce/xstore-license-tokens)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)

[许可证令牌概述](/publishing/xstore-commerce/xstore-license-tokens)

[XStoreQueryLicenseTokenResult](/reference/system/xstore/functions/xstorequerylicensetokenresult)

[XStoreQueryLicenseTokenResultSize](/reference/system/xstore/functions/xstorequerylicensetokenresultsize)


## Related topics

- [XStoreQueryLicenseTokenResult](/zh-CN/reference/system/xstore/functions/xstorequerylicensetokenresult.md)
- [XStoreQueryLicenseTokenResultSize](/zh-CN/reference/system/xstore/functions/xstorequerylicensetokenresultsize.md)
- [PC 上的 XStore — DRM、许可证令牌和沙盒](/zh-CN/publishing/xstore-commerce/xstore-pc.md)
- [启用授权测试](/zh-CN/publishing/xstore-commerce/xstore-licensing-setup.md)
- [为玩家授予对附加内容的访问权限](/zh-CN/publishing/xstore-commerce/xstore-granting-access.md)
