Skip to content

出库 Webhook ​

出库状态变更通过 webhook 推送。支持订阅式(多事件、多地址)与提交出库单时登记的单订单专属地址(webhook_url)两种方式,均使用 HMAC-SHA256 签名、5 秒超时。投递通过 outbox 异步执行,订阅式与专属地址都支持最多 5 次指数退避重试。

事件 ​

事件触发时机
outbound.created出库单创建
outbound.approved审批通过 / 自动通过
outbound.warehouse_confirmed仓库已确认并锁定库存
outbound.rejected审批驳回
outbound.stock_ready仓库标记备货完成
outbound.shipped承运商取件 / 发运
outbound.completed发运完成
outbound.cancelled出库取消
outbound.evidence.uploaded仓库上传凭证

事件类型为 category.event:主类型当前为 outbound,子类型为 created、approved 等。订阅 events 支持 outbound.* 通配,表示接收该主类型下的全部事件。

投递 ​

  • 方法:POST
  • Content-Type:application/json
  • 超时:连接与读取各 5 秒
  • 成功:任意 2xx
  • 重试:订阅式与专属地址在失败后均重试,最多 5 次,间隔 1m、5m、30m、2h、6h;之后停止重试
  • 顺序:不保证;用 occurred_at 与 data.status 判断
  • 幂等:消费方按 id 去重
  • 专属地址:提交出库单时传入 webhook_url,系统会为该出库单生成 webhook_secret,可通过 /outbound/detail 读取;投递时 X-E2C-Webhook-Id 为 0。专属地址与订阅式一样写入 outbox,失败后按相同退避策略重试

请求头 ​

Header说明
X-E2C-Event事件类型,如 outbound.stock_ready
X-E2C-Delivery事件 ID,与负载 id 相同(同一事件的重试复用该值)
X-E2C-TimestampUnix 秒
X-E2C-Signaturesha256=<hex hmac>
X-E2C-Webhook-Id订阅 ID;专属地址投递时为 0

签名 ​

text
signature = HMAC_SHA256(secret, timestamp + "." + raw_request_body)
header    = "sha256=" + hex(signature)

校验步骤:

  1. 读取原始 body(JSON 解析前)。
  2. abs(now - X-E2C-Timestamp) > 300 秒则拒绝。
  3. 用共享密钥计算 HMAC。
  4. 使用常量时间比较。
  5. 快速返回 2xx,异步处理。

负载 ​

json
{
  "id": "evt_5f3c9a7d1e2b4c6d8e0f1a2b",
  "type": "outbound.stock_ready",
  "version": "1.0",
  "occurred_at": "2026-11-11T10:30:00+00:00",
  "data": {
    "outbound_id": 5001,
    "outbound_no": "OB20261111100000123",
    "source_type": "partner_outbound",
    "source_id": 1001,
    "member_id": 42,
    "warehouse_id": 1,
    "status": "stock_ready",
    "previous_status": "warehouse_confirmed",
    "stock_ready_at": "2026-11-11T10:30:00",
    "dispatch_task_id": null,
    "tracking_number": null
  }
}

字段说明 ​

字段类型说明
idstring事件 ID,格式 evt_ + 24 位十六进制,用于幂等
typestring事件类型
versionstring负载版本,当前为 1.0
occurred_atISO8601事件时间(服务端时区偏移)
data.outbound_idinteger通用出库单 ID
data.outbound_nostring出库单号
data.source_typestring来源类型,合作商出库为 partner_outbound
data.source_idinteger来源记录 ID(合作商为出库单 ID)
data.member_idinteger货主会员 ID
data.warehouse_idinteger仓库 ID
data.statusstring当前 SOP 状态
data.previous_statusstring/null变更前 SOP 状态
data.stock_ready_atdatetime/null备货完成时间
data.dispatch_task_idinteger/nullERP 发货任务 ID
data.tracking_numberstring/null运单号;合作商出库通常为 null,以发货任务或承运商回传为准

校验示例(Node.js) ​

js
import crypto from 'crypto'

function verify(rawBody, headers, secret) {
  const ts = headers['x-e2c-timestamp']
  if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false
  const expected = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(`${ts}.${rawBody}`)
    .digest('hex')
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(headers['x-e2c-signature']))
}

订阅列表 ​

POST/channel/api/v1/webhook/subscriptions

Auth: request-token (channel_partner)

列出当前会员的全部出库 webhook 订阅,按 ID 倒序。events 解码为数组,secret 不会返回。

所需能力: outbound_webhook_manage

请求体 ​

无请求参数。

响应 ​

json
{
  "code": 200,
  "msg": "success",
  "data": [
    {
      "id": 12,
      "member_id": 42,
      "url": "https://partner.example.com/hooks/e2c",
      "events": ["outbound.stock_ready", "outbound.shipped"],
      "active": 1,
      "created_at": "2026-11-10 09:00:00",
      "updated_at": "2026-11-10 09:00:00"
    }
  ]
}

错误码 ​

code含义
909未认证、令牌无效或不属于渠道伙伴
606能力不足(需要 outbound_webhook_manage)

cURL ​

cURL
curl -X POST 'https://apigate.e2c-energy.com/channel/api/v1/webhook/subscriptions' \
  -H 'request-token: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'

保存订阅 ​

POST/channel/api/v1/webhook/subscriptions/save

Auth: request-token (channel_partner)

新建或更新订阅。传入 id 时更新该会员自己的订阅;不传 id 时新建。secret 未提供时自动生成 24 字节随机十六进制串(48 字符)。注意:更新时总会写入 secret——提供则使用新值,未提供则重新生成,原密钥随即失效。未传 active 时会被置为 0(停用)。

所需能力: outbound_webhook_manage

请求体 ​

字段类型必填说明
idinteger否订阅 ID;提供时为更新
urlstring是合法 URL,接收 webhook 的 HTTPS/HTTP 地址
eventsstring[]是事件数组,至少一个;仅保留上方事件表中的值
secretstring否签名密钥;为空时自动生成
activeboolean/integer否是否启用,默认 false(0)

响应 ​

json
{
  "code": 200,
  "msg": "success",
  "data": {
    "id": 12,
    "secret": "5d41402abc4b2a76b9719d911017c5923f9c1d2e4b6a8f0c"
  }
}

secret 仅在本接口返回;请立即安全保存。

错误码 ​

code含义
909未认证、令牌无效或不属于渠道伙伴
606能力不足(需要 outbound_webhook_manage)
400url 缺失或非法、events 为空或全部无效
404更新时订阅不存在或不属于当前会员

cURL ​

cURL
curl -X POST 'https://apigate.e2c-energy.com/channel/api/v1/webhook/subscriptions/save' \
  -H 'request-token: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "https://partner.example.com/hooks/e2c",
  "events": [
    "outbound.stock_ready",
    "outbound.shipped"
  ],
  "active": true
}'

删除订阅 ​

POST/channel/api/v1/webhook/subscriptions/delete

Auth: request-token (channel_partner)

删除当前会员的订阅。id 不存在或不属于当前会员时返回 404。

所需能力: outbound_webhook_manage

请求体 ​

字段类型必填说明
idinteger是订阅 ID(兼容别名 subscription_id)

响应 ​

json
{
  "code": 200,
  "msg": "success",
  "data": null
}

错误码 ​

code含义
909未认证、令牌无效或不属于渠道伙伴
606能力不足(需要 outbound_webhook_manage)
400id 缺失
404订阅不存在或不属于当前会员

cURL ​

cURL
curl -X POST 'https://apigate.e2c-energy.com/channel/api/v1/webhook/subscriptions/delete' \
  -H 'request-token: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": 12
}'

投递日志与重试 ​

  • 投递方式:所有投递(订阅式 + 专属地址)先写入 t_plan_task_record outbox(type=WebhookDelivery),由 plan-task-worker.php 异步执行;业务接口不再同步等待 HTTP 投递
  • worker:php script/tools/plan-task-worker.php --limit=50(建议每分钟);旧 outbound-webhook-retry.php 仍可作为兼容入口
  • 投递状态:t_plan_task_record 的 status、attempts、next_retry_at、result、last_error;wms_outbound_webhook_delivery 仅保留历史数据