> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/jiang-li/integrations.md).

# 集成

将 Rewards 活动连接到 Decentraland 场景或外部服务器，以自动发放可穿戴物和表情动作。

创建并配置活动，并确保库存充足、能够发放奖励后，下一步是将活动关联到奖励触发器。触发器可以是场景、任务，也可以是外部服务器。本节将介绍如何通过不同方式与 Rewards 集成。

## 从场景发放奖励

可以将 Rewards 直接集成到 Decentraland 场景中，但这种方式存在一些风险。由于逻辑嵌入在用户可以访问的场景代码中，因此不建议用它来铸造稀有度低于 \[EPIC]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#rarity) 的物品。

请注意，技术知识足够丰富且意志坚定的用户，可能会绕过验证码等安全措施、更改 IP 地址并铸造所有可用物品，然后在市场上出售。防范这种情况的主要措施是确保物品供应充足，让每个人都有公平的机会获得奖励。

### 建议使用的分发器标志

建议使用以下分发器配置，以降低此场景中的漏洞利用风险：

* \[限制分配]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#limit-assignments)
* \[受益者签名]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#beneficiary-signature)
* \[验证码保护]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#captcha-protection)
* \[已连接到 Decentraland]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#connected-to-decentraland)
* \[Decentraland 内的位置]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#position-inside-decentraland)（如果适用于你的使用场景）

### 示例

```tsx
import { getPlayer } from '@dcl/sdk/src/players'
import { signedFetch } from '@decentraland/SignedFetch'
import { getRealm } from '~system/Runtime'

export function main() {
  // 1. 获取验证码挑战并向用户展示
  const request = await fetch(`https://rewards.decentraland.org/api/captcha`, {
    method: 'POST',
  })
  const captcha = await request.json()

  // 2. 显示验证码供玩家完成 - 示例见 studios.decentraland.org/resources

  // 3. 获取用户数据
  const user = getPlayer()

  // 4. 获取当前 Realm
  const realmInfo = await getRealm({})

  // 5. 发送请求以分配可穿戴物品/表情
  const assignRequest = await signedFetch('https://rewards.decentraland.org/api/rewards', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      campaign_key: '[DISPENSER_KEY]', // 分发器密钥
      beneficiary: user.userId, // 以太坊地址
      catalyst: realmInfo.baseUrl, // Catalyst 域名
      captcha_id: captcha.data.id, // "9e6b2d07-b47b-4204-ae87-9c4dea48f9b7"
      captcha_value: '[CAPTCHA_VALUE]', // "123456"
    }),
  })

  const reward = await assignRequest.json()
```

## 从 Decentraland 任务发放奖励

此旧版集成链接指向已归档的任务文档。

你可以轻松将 Rewards 与 [Decentraland 任务](https://github.com/decentraland/documentation/blob/5f8c7f73c67a9a36e85095cb02e72dc6355fa590/content/creator/deprecated/quests/overview.md)集成；如果你想奖励完成任务的用户，这种方式非常合适。

### 建议使用的分发器标志

建议使用以下分发器配置，以降低此场景中的漏洞利用风险：

* \[限制分配]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#limit-assignments)（如果适用于你的使用场景）

其他任何标志都会导致集成失败，请避免使用。

{% hint style="warning" %}
⚠️ Dispenser 密钥应妥善保密，因此绝不能在任何时候向用户公开。
{% endhint %}

### 示例

要将 Quest 集成到 Rewards 服务中，你只需要一个 Dispenser 密钥，并且 [配置 webhook](https://github.com/decentraland/documentation/blob/5f8c7f73c67a9a36e85095cb02e72dc6355fa590/content/creator/deprecated/quests/rewards.md) 以发放奖励。

```js
{
    // ...
    "reward": {
        "hook": {
            "webhookUrl": "https://rewars.decentraland.org/api/rewards",
            "requestBody": {
                "campaign_key": "[DISPENSER_KEY]",
                "beneficiary": "{user_address}"
            }
        },
        // ...
    }
}
```

## 从自定义服务器发放奖励

你可以直接从服务器集成 Rewards，这非常适合在铸造物品前执行额外检查。另一个优点是，与场景代码不同，你的服务器代码可能不会公开，因此用户更难发现并利用其中的漏洞。

### 建议使用的分发器标志

建议使用以下分发器配置，以降低此场景中的漏洞利用风险：

* \[限制分配]\([查看文档](https://docs.decentraland.org/creator/content-creator-zh/readme.md)#limit-assignments)（如果适用于你的使用场景）

启用其他任何标志都可能使集成变得复杂，或者根据你的使用场景，甚至导致集成失败。因此，除非有特定需求，否则不建议使用这些标志。不过，你可以了解它们可能带来的好处。

{% hint style="warning" %}
⚠️ Dispenser 密钥应妥善保密，因此绝不能在任何时候向用户公开。
{% endhint %}

### 示例

```tsx
const request = await fetch('https://rewards.decentraland.org/api/rewards', {
	method: 'POST',
	headers: {
		'Content-Type': 'application/json',
	},
	body: JSON.stringify({
		campaign_key: '[DISPENSER_KEY]',
		beneficiary: '0x0f5d2fb29fb7d3cfee444a200298f468908cc942', // 以太坊地址
	}),
})

const response = await request.json()
```


---

# 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://docs.decentraland.org/creator/content-creator-zh/jiang-li/integrations.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.
