# 加签

为了更高的安全性，[高级合作伙伴](/zh/get-started/onboarding.md)必须对URL 进行签名

## URL接口加签

在[申请集成](/zh/get-started/onboarding.md)中，<mark style="color:red;">您将生成</mark> <mark style="color:red;"></mark><mark style="color:red;">`SecretKey`</mark>。URL请求接口的签名就是基于其生成，所以请千万注意不要泄漏。

### 加签步骤

API 接口请求加签主要由以下几个步骤组成。

1. **获取参数**
   * 首先，获取url接口需要签名的GET入参，组成一个数组，去掉 key 或 value 为空的 item；
   * 需要签名的参数，on-ramp见 [on-ramp参数说明](/zh/reference/integration-tutorial/widget-customization.md)，NFT Checkout见 [NFT Checkout参数说明](/zh/reference/ji-cheng-nft-checkout-ye-mian.md)
2. **参数排序**
   * 接着按所有参数名的字典序（ASCII码）升序排序，<mark style="color:green;">**注意只有参数里的 key 名进行排序，值不参与排序**</mark>；
3. **拼字符串**
   * 先将格式转化为`参数名=参数值`形式，并用`&`符连接，得到拼接字符串；
4. **摘要签名**
   * 然后对待加签字符串使用 `SecretKey` 做 `HMAC-SHA256` 算法进行摘要签名，并进行urlencoding，生成最终的签名。
5. **签名赋值**
   * 最后，将上一步得到的签名赋值到 url 里的 `signature`，集成FaTPay页面。FaTPay 网关收到请求后，会统一使用 `SecretKey` 校验签名，如果通过校验则返回相应的服务端数据。

### 加签示例

假设需要默认钱包地址，且对用户锁定并隐藏钱包地址页

请求参数如下：

```javascript
{
  "walletAddress": 0xF0C35891CAf1cCa9b1daB1291c61fF232E6D5888,
  "walletAddressHidden": 1,
  "walletAddressLocked": 1,
  "ext": ext
}
```

公共参数如下：

<pre class="language-javascript"><code class="lang-javascript">{
  "nonce": 748219,
  "partnerId": "mqMBpCIP630LJxLY",
  "timestamp": 1656600459
<strong>}
</strong></code></pre>

#### **获取参数**

首先，获取url接口需要签名的GET入参，组成一个数组，去掉 key 或 value 为空的 item。即可得到这样一个数组：

{% code overflow="wrap" %}

```java
ext=ext&nonce=54335363&partnerId=mqMBpCIP630LJxJK&partnerUrl=https://yoururl.com&timestamp=1657854065&walletAddress=xxxx&walletAddressHidden=1&walletAddressLocked=1
```

{% endcode %}

```javascript
{
  "partnerId": "mqMBpCIP630LJxLY",
  "timestamp": 1656600459,
  "nonce": 748219,
  "walletAddress": "0xF0C35891CAf1cCa9b1daB1291c61fF232E6D5888",
  "walletAddressHidden": 1,
  "walletAddressLocked": 1,
  "ext": "ext"
}
```

**参数排序**

接着按所有参数名的字典序（ASCII码）升序排序，得到：

```javascript
{
  "ext": "ext",
  "nonce": 748219,
  "partnerId": "mqMBpCIP630LJxLY",
  "timestamp": 1656600459,
  "walletAddress": "0xF0C35891CAf1cCa9b1daB1291c61fF232E6D5888",
  "walletAddressHidden": 1,
  "walletAddressLocked": 1
}
```

**拼字符串**

先将格式转化为`参数名=参数值`形式，并用`&`符连接，得到拼接字符串：

> ext=ext\&nonce=54335363\&partnerId=mqMBpCIP630LJxJK\&timestamp=1657854065\&walletAddress=0xF0C35891CAf1cCa9b1daB1291c61fF232E6D5888\&walletAddressHidden=1\&walletAddressLocked=1

**摘要签名**

然后对待加签字符串使用 `SecretKey` 做 `HMAC-SHA256` 算法进行摘要签名，对摘要字串进行`base64`编码生成签名：

> 4UoZ2gIm3bcLTw5K6WdBJIaYBiXgQF3uvOfY4Ovc6+4=

对签名 urlencode:

> 4UoZ2gIm3bcLTw5K6WdBJIaYBiXgQF3uvOfY4Ovc6%2B4%3D

**签名赋值**

最后，将上一步得到的签名赋值到 url 里的 `signature`，集成FaTPay页面。页面跳转至FaTPay后，FaTPay会统一使用 `SecretKey` 校验签名，如果通过校验则展示对应的下单流程。

{% code overflow="wrap" %}

```
https://ramp.fatpay.xyz/home?ext=ext&nonce=748219&partnerId=mqMBpCIP630LJxLY&timestamp=1656600459&walletAddress=0xF0C35891CAf1cCa9b1daB1291c61fF232E6D5888&walletAddressHidden=1&walletAddressLocked=1&signature=4UoZ2gIm3bcLTw5K6WdBJIaYBiXgQF3uvOfY4Ovc6%2B4%3D
```

{% endcode %}


---

# Agent Instructions: 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:

```
GET https://dev.fatpay.org/zh/reference/integration-tutorial/widget-signature.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
