# 查询签约订单


查询签约订单接口，用于开发者根据签约单号或外部签约单号查询对应签约订单的签约状态及详细信息。适用于签约完成后的状态同步、签约信息展示、协议支付前的签约状态校验等业务场景。

## 使用限制

- 调用频次限制：请遵守平台默认 QPS 限制，避免高频调用。
- 查询时需提供 auth_order_id 或 out_auth_order_no 中的至少一个，否则查询将失败。

## 接口说明

- 业务场景：适用于开发者在用户完成签约后，主动查询签约订单的签约状态、签约时间、解约来源等详细信息。常见场景包括：签约结果页展示、发起协议支付前的签约状态校验、签约状态定时同步等。
- 前提条件：调用方需已完成应用创建，并通过 get_client_token 接口获取到有效的应用级 AccessToken。
- 注意事项：
- auth_order_id 为平台侧签约单号，out_auth_order_no 为商户侧签约单号，两者均可用于查询，但建议优先使用 auth_order_id。
- 签约单状态包括 SIGN（已签约）、UNSIGN（已解约）、PROCESSING（签约处理中）、TIMEOUT（用户未签约超时），发起协议支付前请确保签约单状态为 SIGN。

## 基本信息

| 名称 | 描述 |
|-|-|
| HTTP Path | /api/trade_basic/v1/developer/query_sign_order |
| HTTP Method | POST |
| Scope | trade.sign.query |
| 权限要求 | - 需要申请权限 - 申请路径：豆包开放平台控制台 > 应用详情 > 能力 > 支付权限 - 需要应用级 AccessToken |

## 请求头

| 名称 | 类型 | 必填 | 描述 |
|-|-|-|-|
| content-type | string | 是 | 固定值 application/json |
| x-DB-AccessToken | string | 是 | 调用 get_client_token 接口生成的应用级访问凭证 |

## 请求参数

### Body

| 名称 | 类型 | 是否必填 | 描述 | 示例值 |
|-|-|-|-|-|
| auth_order_id | string | 否（与 out_auth_order_no 二选一） | 平台侧签约单的单号，auth_order_id 与 out_auth_order_no 二选一，长度不超过 64 byte | 80214322040407612\*\*\* |
| out_auth_order_no | string | 否（与 auth_order_id 二选一） | 外部签约单号，auth_order_id 与 out_auth_order_no 二选一，长度不超过 64 byte | SIGN2024010100\*\*\* |

## 请求示例

cURL

```shell
curl -X POST 'https://api.doubao-dev.com/api/trade_basic/v1/developer/query_sign_order' \
  -H 'content-type: application/json' \
  -H 'x-DB-AccessToken: clt.943da17996fb5cebfbc70c044c3fc25a57T54DcjT6HNKGqn******' \
  -d '{
    "auth_order_id": "80214322040407612***",
    "out_auth_order_no": ""
  }'
```

Go

```go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
)

func main() {
    url := "https://api.doubao-dev.com/api/trade_basic/v1/developer/query_sign_order"
    reqBody := map[string]string{
        "auth_order_id":     "80214322040407612***",
        "out_auth_order_no": "",
    }
    jsonData, _ := json.Marshal(reqBody)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("content-type", "application/json")
    req.Header.Set("x-DB-AccessToken", "clt.943da17996fb5cebfbc70c044c3fc25a57T54DcjT6HNKGqn******")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}
```

Java

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class QuerySignOrder {
    public static void main(String[] args) throws Exception {
        String url = "https://api.doubao-dev.com/api/trade_basic/v1/developer/query_sign_order";
        String requestBody = "{\"auth_order_id\":\"80214322040407612***\",\"out_auth_order_no\":\"\"}";

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("content-type", "application/json")
                .header("x-DB-AccessToken", "clt.943da17996fb5cebfbc70c044c3fc25a57T54DcjT6HNKGqn******")
                .POST(HttpRequest.BodyPublishers.ofString(requestBody))
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
```

Node.js

```javascript
const axios = require('axios');

async function querySignOrder() {
    const url = 'https://api.doubao-dev.com/api/trade_basic/v1/developer/query_sign_order';
    const headers = {
        'content-type': 'application/json',
        'x-DB-AccessToken': 'clt.943da17996fb5cebfbc70c044c3fc25a57T54DcjT6HNKGqn******'
    };
    const data = {
        auth_order_id: '80214322040407612***',
        out_auth_order_no: ''
    };

    try {
        const response = await axios.post(url, data, { headers });
        console.log(response.data);
    } catch (error) {
        console.error('Error:', error.message);
    }
}

querySignOrder();
```

## 响应参数

| 名称 | 类型 | 是否必填 | 描述 | 示例值 |
|-|-|-|-|-|
| code | int32 | 是 | 错误码，0 表示成功，非 0 表示失败 | 0 |
| msg | string | 是 | 错误提示 | success |
| log_id | string | 是 | 请求日志 ID，用于问题排查时提供给技术支持 | 2023010128382726 |
| data | object | 否 | 签约订单详情对象，仅在查询成功时返回 | 见下方 data 字段说明 |

### data 字段说明

| 名称 | 类型 | 是否必填 | 描述 | 示例值 |
|-|-|-|-|-|
| app_id | string | 是 | 应用 ID | tt1234567890\*\*\*\*\*\* |
| auth_order_id | string | 是 | 平台侧签约单的单号 | 80214322040407612\*\*\* |
| out_auth_order_no | string | 是 | 外部签约单号，与 auth_order_id 一一对应 | SIGN2024010100\*\*\* |
| open_id | string | 是 | 用户 OpenID | ou_a1b2c3d4e5f6\*\*\*\*\*\* |
| service_id | string | 是 | 签约模板 ID | SVC20240101000\*\*\* |
| status | string | 是 | 签约单状态，枚举值： TOBESERVED - 待签约 SERVING - 签约成功 CANCEL - 签约取消 TIMEOUT - 签约超时 | SERVING |
| sign_time | string | 否 | 用户签约时间，精度：毫秒 | 1692775192000 |
| unsign_source | integer | 否 | 用户解约来源，枚举值：1 - 用户主动解约；2 - 商户解约。仅在 status 为 UNSIGN 时返回 | 1 |

## 响应示例

### 正常示例

```json
{
    "data": {
        "app_id": "tt1234567890******",
        "auth_order_id": "80214322040407612***",
        "out_auth_order_no": "SIGN2024010100***",
        "open_id": "ou_a1b2c3d4e5f6******",
        "service_id": "SVC20240101000***",
        "status": "SIGN",
        "sign_time": "1692775192000",
        "unsign_source": 0
    },
    "code": 0,
    "msg": "success",
    "log_id": "2022092115392201020812109511046"
}
```

### 异常示例

```json
{
    "code": 500000001,
    "msg": "Parameter error",
    "log_id": "2022092115392201020812109511047",
    "data": null
}
```

## 错误码

### 通用错误码

| 错误码 | 错误名称 | 描述（msg） | 排查建议 |
|-|-|-|-|
| 0 | Success | success | 请求成功，无需处理 |
| 500000000 | OApiCommonInternalError | internal error | 系统内部错误，请稍后重试；若持续出现请携带 log_id 联系技术支持 |
| 500000001 | OApiCommonDeveloperParamError | Parameter error | 请求参数错误，请检查 auth_order_id 和 out_auth_order_no 是否至少传入一个，以及参数格式是否正确 |
| 500000002 | OApiCommonDeveloperRateLimitError | Rate limit error | 请求触发限流，请降低调用频率后重试 |
| 500000003 | OApiCommonVerifySignFailError | Verify sign fail | 签名验证失败，请检查 x-DB-AccessToken 是否有效、是否过期，必要时重新调用 get_client_token 获取新 token |
