> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/guide/zh/authentication/anon-key.md).

# 用户识别码发放

用户识别键发放是帮助你无需单独的服务器联动或用户同意流程，也能在迷你应用内稳定识别用户的功能。

当用户进入迷你应用的瞬间，会创建该用户的迷你应用准会员。迷你应用可以基于这个用户管理服务使用数据、存储数据、排行榜、积分等信息。

{% hint style="info" %}
**Toss 登录迁移**

如果你之前一直通过 Toss 登录来识别用户，可以切换为用户识别键发放方式。适用于无需单独登录界面或服务器联动就需要进行用户识别的场景。
{% endhint %}

## 什么是用户识别键

用户识别键是在迷你应用内用于区分单个用户的唯一键值。它不会直接暴露用户的个人信息，同时能让迷你应用内部稳定识别同一用户。

返回的用户识别符会按迷你应用分别唯一。即使是同一个 Toss 用户，在不同的迷你应用中也会使用不同的识别键。

{% hint style="info" %}
**请务必确认**

* 在同一个迷你应用内，同一用户始终会返回相同的识别键。
* 即使删除应用或更换设备，只要是同一用户，返回的识别键也相同。
* 必须使用符合迷你应用类型的发放方式。若在其他类型中使用，可能会发生错误。
* 在沙盒环境中会返回 mock 数据。实际行为请通过二维码在 Toss 应用中测试。
  {% endhint %}

## 按迷你应用类型的使用方式

根据迷你应用类型，获取用户识别键的方式会有所不同。

| 迷你应用类型 | 用途         | 说明                          |
| ------ | ---------- | --------------------------- |
| 游戏     | 游戏用户识别     | 用于按用户单位管理游戏数据、排行榜、积分、存档数据等。 |
| 非游戏    | 通用迷你应用用户识别 | 用于按用户单位管理服务使用记录、用户设置、存储数据等。 |

## 游戏迷你应用

在游戏迷你应用中，会通过专用于在游戏内识别用户的方式获取用户识别键。像 Toss 登录一样，即使不弹出单独的认证界面，也可以在游戏迷你应用内部使用唯一的用户识别符。

该识别键仅在对应的游戏迷你应用内有效。可用于需要以用户为基础延续的数据，例如游戏内数据存储、排行榜管理、积分管理、存档数据管理。

{% hint style="warning" %}
**请注意**

* 只能在游戏迷你应用中使用。
* 在低于支持版本的 Toss 应用中，可能不会提供用户识别键。
* 为了稳定提供所有用户的识别符，游戏迷你应用的最低支持 Toss 应用版本已上调。
* 低于支持版本时，进入迷你应用会显示更新 안내 界面。
* 在沙盒环境中会返回 mock 数据。实际行为请通过二维码在 Toss 应用中测试。
  {% endhint %}

## 非游戏迷你应用

在非游戏迷你应用中，会通过用于在常规服务中识别用户的方式获取用户识别键。无需单独的认证界面或服务器联动，就可以在迷你应用内部使用唯一的用户识别符。

该识别键仅在对应的迷你应用内有效。可用于需要按用户管理的数据，例如用户专属设置、使用记录、存储数据。

{% hint style="warning" %}
**请注意**

* 只能在非游戏迷你应用中使用。
* 在低于支持版本的环境中，可能不会提供用户识别键。
* 返回的用户识别键不是用于调用 Toss 服务器 API 的密钥。
* 请仅用于内部用户识别和数据管理。
* 在沙盒环境中会返回 mock 数据。实际行为请通过二维码在 Toss 应用中测试。
  {% endhint %}

## 用户识别键使用示例

当需要在迷你应用内以用户为基础持续管理数据时，可以使用用户识别键。

* 管理用户的服务使用记录
* 保存用户专属设置
* 管理游戏排行榜、积分、存档数据
* 恢复回访用户的先前状态
* 构建无需登录即可提供的个性化体验

{% hint style="info" %}
用户识别键是用于区分用户的值。它不是用来替代真实姓名、电话号码、账号信息等个人信息的功能。
{% endhint %}

## 开发

在非游戏迷你应用中获取用户识别键的方法是 [User.getAnonymousKey](https://developers-apps-in-toss.toss.im/documentation/sdk/domains-api/user/user.getanonymouskey)请在其中确认。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers-apps-in-toss.toss.im/guide/zh/authentication/anon-key.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
