> 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 集成。

## 从场景发放奖励

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

请记住，技术知识足够丰富且有决心的用户可能会绕过验证码等安全措施，修改他们的 IP 地址，并铸造所有可用物品，然后再将其出售到市场上。对此的主要防护措施是确保物品供应充足，这样每个人都有公平的机会获得奖励。

### 推荐的发放器标志

建议使用以下发放器配置，以降低在这种情况下被利用的风险：

* \[限制分配]\([查看文档](/creator/content-creator-zh/readme.md)#limit-assignments)
* \[受益人签名]\([查看文档](/creator/content-creator-zh/readme.md)#beneficiary-signature)
* \[验证码保护]\([查看文档](/creator/content-creator-zh/readme.md)#captcha-protection)
* \[已连接到 Decentraland]\([查看文档](/creator/content-creator-zh/readme.md)#connected-to-decentraland)
* \[Decentraland 内部位置]\([查看文档](/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. 发送请求以分配一个 wearable/emote
  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/docs/tree/main/creator/deprecated/quests/overview.md)集成，如果你想在用户完成任务后奖励他们，这非常理想。

### 推荐的发放器标志

建议使用以下发放器配置，以降低在这种情况下被利用的风险：

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

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

{% hint style="warning" %}
⚠️ 发放器密钥应予以保密，因此你绝不应在任何时候向用户暴露它。
{% endhint %}

### 示例

要将你的任务与 Rewards 服务集成，你只需要一个发放器密钥并且 [配置一个 webhook](https://github.com/decentraland/docs/tree/main/creator/deprecated/quests/rewards.md) 来发放奖励。

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

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

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

### 推荐的发放器标志

建议使用以下发放器配置，以降低在这种情况下被利用的风险：

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

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

{% hint style="warning" %}
⚠️ 发放器密钥应予以保密，因此你绝不应在任何时候向用户暴露它。
{% 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.decentraland.org/creator/content-creator-zh/jiang-li/integrations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
