# Connect（连接）

在应用与 Backpack 交互之前，必须先建立连接。

该连接请求会提示用户分享其公钥，以表示同意继续。

一旦用户连接成功，Backpack 会返回一个 `session` 参数，后续所有方法都应使用此参数。

{% hint style="info" %}
关于 session 的更多信息，请参阅[Handling Sessions](https://app.gitbook.com/o/1pzK7I96ua1kPK2SCiPg/s/p2WpAGNII69RQ8wSTC1p/~/changes/47/qian-bao/ji-shu-wen-dang/deeplinks/handling-sessions-hui-hua-chu-li)。
{% endhint %}

## **基础 URL**

```
https://backpack.app/ul/v1/connect
```

## **查询字符串参数（Query String Parameters）**

* `app_url`（必填）：用于提供应用元数据（例如标题、图标）的 URL，必须进行 URL 编码。
* `dapp_encryption_public_key`（必填）：用于端到端加密的公钥，用于生成共享密钥。有关 Backpack 如何管理共享密钥的详情，请参考[Encryption](https://app.gitbook.com/o/1pzK7I96ua1kPK2SCiPg/s/p2WpAGNII69RQ8wSTC1p/~/changes/47/qian-bao/ji-shu-wen-dang/deeplinks/encryption-jia-mi-ji-zhi)部分。
* `redirect_link`（必填）：连接成功后 Backpack 应将用户重定向到的 URI。详情请参阅[Specifying Redirects](https://app.gitbook.com/o/1pzK7I96ua1kPK2SCiPg/s/p2WpAGNII69RQ8wSTC1p/~/changes/47/qian-bao/ji-shu-wen-dang/deeplinks/specifying-redirects-zhi-ding-zhong-ding-xiang)。必须进行 URL 编码。
* `cluster`（可选）：指定后续交互所使用的网络。若连接至 Solana 主网，请留空或设置为 `mainnet-beta`。若连接至 Eclipse，请设置为：

  ```
  solana:EAQLJCV2mh23BsK2P9oYpV5CHVLDNHTxY
  ```

## **返回值**

### Approve（同意）

* `wallet_xxx`：Backpack 使用的 base58 编码加密公钥，用于与连接应用构建共享密钥。
* `nonce`：base58 编码的随机数，用于加密响应。
* `data`：已加密的 JSON 字符串。应用可通过共享密钥解密数据，详情见[Encryption](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/encryption-jia-mi-ji-zhi.md)。加密后的字节使用 base58 编码。

```json
// 解密后的 `data` 参数内容
{
  // 用户公钥的 base58 编码
  "public_key": "3huUrtWW5s5ew98eUFRYz9LPsDUQTujNzzYaB9DBkppQ",

  // 用于后续签名与消息处理的 session token
  // 应用在之后的所有 deeplinks 中都应携带该 token
  "session": "..."
}
```

* **`public_key`**：用户的公钥，以 base58 编码的字符串形式表示。
* **`session`**：以 base58 编码的字符串形式表示。连接应用应该将其视为不透明的，仅需与其他参数一起传递即可。会话不会过期。有关会话的更多信息，请参阅 [Handling Sessions](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/handling-sessions-hui-hua-chu-li.md)。

### Reject（拒绝）

需要传&#x9012;**`errorCode` (错误代码)** &#x548C;**`errorMessage` (错误信息)** 作为查询参数。

请参阅 [Errors](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/limitations-xian-zhi.md#errors-cuo-wu-chu-li) 了解所有可能的错误代码。


---

# 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://support.backpack.exchange/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/provider-fang-fa/connect-lian-jie.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.
