XStoreQueryLicenseTokenAsync
为调用的游戏提供不透明的 JSON Web 令牌,该令牌可以传递给游戏的服务以验证权利和进行 B2B 调用。 参阅 许可证令牌概述 获取更多信息。
语法
HRESULT XStoreQueryLicenseTokenAsync(
const XStoreContextHandle storeContextHandle,
const char** productIds,
size_t productIdsCount,
const char* customDeveloperString,
XAsyncBlock* async
)
参数
storeContextHandle _In_
类型:XStoreContextHandle
XStoreCreateContext 返回的用户的应用商店上下文句柄。
productIds _In_z_count_(productIdsCount)
类型:char**
要为其检索令牌的产品 ID 的数组。
productIdsCount _In_
类型:size_t
传入 productIds 的数组中的 ID 数。
customDeveloperString _In_z_
类型:char*
往返传入令牌的值。 这通常由服务来选择。 您可以插入类似 userId 或电子邮件的对象来在许可证令牌中跟踪用户的令牌。 许可证令牌类似于所有权的收据。
此值不能为 null 或空字符串。
async _Inout_
类型:XAsyncBlock*
用于定义正在进行的异步工作的 XAsyncBlock。 XAsyncBlock 可用于轮询调用的状态和检索调用结果。 有关详细信息,请参阅 XAsyncBlock。
返回值
类型:HRESULT
HRESULT 成功或错误代码。
备注
要检索 JSON Web 令牌以及此函数的执行结果,请在调用此函数后调用 XStoreQueryLicenseTokenResult。 要检索 JSON Web 令牌的大小,请在调用此函数后调用 XStoreQueryLicenseTokenResultSize。 了解令牌的大小可让您更高效地检索到它。
许可证令牌是 Base64 编码的 JSON Web 令牌。 令牌的有效负载是一个 Base64 编码的字符串,可转换为可在服务器上用于进行验证的 JSON 值。
以下代码段显示一个检索许可证令牌的示例。
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 主机