# 预取消配送单

[调试诊断](https://developers.weixin.qq.com/console/devtools/debug?utm_source=api_tools)

> 接口应在服务器端调用，不可在前端（小程序、网页、APP等）直接调用，具体可参考[接口调用指南](/doc/oplatform/developers/dev/guide.md)。

接口英文名：preCancelOrder

#### 使用场景描述

- 在正式取消配送单前，商家可调用本接口查询该订单是否可以取消，取消订单配送公司需要扣除的费用是多少。各家取消规则如下：
- 顺丰同城急送：配送完成前任意节点可取消配送单
- 闪送：配送完成前任意节点可取消配送单
- 美团配送：配送完成前任意节点可取消配送单
- 达达：骑手取货之前可取消配送单

## 1. 调用方式

### HTTPS 调用

```bash
POST https://api.weixin.qq.com/cgi-bin/express/local/business/order/precancel?access_token=ACCESS_TOKEN
```

### 云调用

- 本接口不支持云调用。

### 第三方调用

- 本接口支持第三方平台代商家调用。

- 该接口所属的权限集 id 为：51、71

- 服务商获得其中之一权限集授权后，可通过使用 [authorizer_access_token](/doc/oplatform/developers/dev/AuthorizerAccessToken.md) 代商家进行调用，具体可查看 [第三方调用](/doc/oplatform/Third-party_Platforms/2.0/Before_Develop/call_interface.md) 说明文档。

## 2. 请求参数

### 查询参数 `Query String Parameters`

```json
[
  {
    "参数名": "access_token",
    "类型": "string",
    "必填": "是",
    "说明": "接口调用凭证，可使用 [access_token](/miniprogram/dev/server/API/mp-access-token/api_getaccesstoken)、[authorizer_access_token](/doc/oplatform/openApi/ticket-token/api_getauthorizeraccesstoken.md)"
  }
]
```

### 请求体 `Request Payload`

```json
[
  {
    "参数名": "shopid",
    "类型": "string",
    "必填": "是",
    "说明": "商家id， 由配送公司分配的appkey"
  },
  {
    "参数名": "shop_order_id",
    "类型": "string",
    "必填": "是",
    "说明": "唯一标识订单的 ID，由商户生成"
  },
  {
    "参数名": "delivery_id",
    "类型": "string",
    "必填": "是",
    "说明": "快递公司ID"
  },
  {
    "参数名": "waybill_id",
    "类型": "string",
    "必填": "是",
    "说明": "配送单id"
  },
  {
    "参数名": "cancel_reason_id",
    "类型": "number",
    "必填": "否",
    "说明": "取消原因Id"
  },
  {
    "参数名": "cancel_reason",
    "类型": "string",
    "必填": "否",
    "说明": "取消原因"
  },
  {
    "参数名": "shop_no",
    "类型": "string",
    "必填": "是",
    "说明": "商家门店编号，在配送公司登记，闪送shop_no必填，值为店铺id"
  },
  {
    "参数名": "delivery_sign",
    "类型": "string",
    "必填": "是",
    "说明": "用配送公司提供的appSecret加密的校验串说明"
  }
]
```

## 3. 返回参数

### 返回体 `Response Payload`

```json
[
  {
    "参数名": "resultcode",
    "类型": "number",
    "说明": "运力返回的错误码"
  },
  {
    "参数名": "resultmsg",
    "类型": "string",
    "说明": "运力返回的错误描述"
  },
  {
    "参数名": "deduct_fee",
    "类型": "number",
    "说明": "预计扣除的违约金(单位：元)，精确到分"
  },
  {
    "参数名": "desc",
    "类型": "string",
    "说明": "说明"
  }
]
```

## 4. 注意事项

本接口无特殊注意事项

## 5. 代码示例

请求示例

```json
{
  "shopid": "123456",
  "shop_order_id": "123456",
  "waybill_id": "123456",
  "delivery_id": "123456",
  "cancel_reason_id": 1,
  "cancel_reason": "",
  "delivery_sign": "123456",
  "shop_no": "shop_no_111"
}
```

返回示例

```json
{
  "resultcode": 0,
  "resultmsg": "ok",
  "deduct_fee": 5,
  "desc": "blabla"
}
```

## 6. 错误码

以下是本接口的错误码列表，其他错误码可参考 [通用错误码](/doc/oplatform/developers/errCode/README.md)；调用接口遇到报错，可使用官方提供的 [API 诊断工具](https://developers.weixin.qq.com/console/devtools/debug?utm_source=api_errcode) 辅助定位和分析问题。

```json
[
  {
    "错误码": "-1",
    "错误描述": "system error",
    "解决方案": "系统繁忙，此时请开发者稍候再试"
  }
]
```

## 7. 适用范围

本接口暂未明确可调用账号类型，或在业务中根据调用传参自行确定是否可调用，请以实际调用情况为准。
