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

# XStoreGetUserPurchaseIdAsync

> XStoreGetUserPurchaseIdAsync

# XStoreGetUserPurchaseIdAsync

取得客戶購買識別碼。此識別碼會擷取 Microsoft Store 識別碼金鑰，可用來代表目前使用者授與免費產品的權利。此 API 用於[從您的服務管理產品](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)中所述的流程

## 語法

```cpp theme={null}
HRESULT XStoreGetUserPurchaseIdAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char* serviceTicket,  
         const char* publisherUserId,  
         XAsyncBlock* async  
)  
```

### 參數

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

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

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

與購買相關聯的服務票證。

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

包含發行者使用者識別碼的字串。

*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 成功或錯誤碼。

## 備註

若要擷取客戶的購買識別碼以及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreGetUserPurchaseIdResult](/zh-TW/reference/system/xstore/functions/xstoregetuserpurchaseidresult)。若要擷取客戶購買識別碼的大小，請在呼叫此函式之後呼叫 [XStoreGetUSerPurchaseIdResultSize](/zh-TW/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize)。知道結果大小可協助您更有效率地讀取結果。

下列程式碼片段示範如何擷取客戶購買識別碼。

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

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

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

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

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

    delete[] result;
}

void GetUserPurchaseId(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* serviceTicket, const char* publisherUserId)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;

    asyncBlock->callback = GetUserPurchaseIdCallback;

    HRESULT hr = XStoreGetUserPurchaseIdAsync(
        storeContextHandle,
        serviceTicket,
        publisherUserId,
        asyncBlock.get());

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

## 需求

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

**程式庫：** xgameruntime.lib

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

## 概念文件

* [要求使用者市集識別碼以進行服務對服務驗證](/zh-TW/publishing/xstore-commerce/xstore-requesting-userstoreid)

## 另請參閱

[XStore](/zh-TW/reference/system/xstore/xstore_members)\
[XStoreGetUserPurchaseIdResult](/zh-TW/reference/system/xstore/functions/xstoregetuserpurchaseidresult)\
[XStoreGetUSerPurchaseIdResultSize](/zh-TW/reference/system/xstore/functions/xstoregetuserpurchaseidresultsize)\
[從您的服務管理產品](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)


## Related topics

- [XStoreGetUserPurchaseIdAsync](/es/reference/system/xstore/functions/xstoregetuserpurchaseidasync.md)
- [XStoreGetUserPurchaseIdResult](/reference/system/xstore/functions/xstoregetuserpurchaseidresult.md)
