Integration slips account for roughly a third of project delay — this page is the main cure. Three questions before, three traps during, error-code acceptance after.
API对接是包网搭建里最依赖外部配合的环节,也是延期重灾区。问题的根源不是技术难,是约定不清。这篇按对接前、中、后三个阶段给清单。
十个体对接失败的项目里,四个栽在验签。常见原因:参数排序规则不一致(字典序、大小写敏感)、时间戳容差没对齐(建议 ±300 秒)、编码差异(URL encode 的空格处理)。解法是拿对方的示例代码逐字节比对签名串,先对齐再联调。
网络超时后重试,是分布式系统的日常。如果接口不幂等,一次重试就是两笔订单。对接前问清楚:这个接口幂等吗?幂等键是什么?答不上来的接口,按不幂等处理——自己生成唯一请求号带上。
超时时间不能拍脑袋。读取超时建议 3-5 秒,重试 2-3 次,退避间隔翻倍(1s、2s、4s)。重试超过 3 次还没有成功,进人工处理队列,别让机器硬扛。
| 层级 | 职责 | 验收标准 |
|---|---|---|
| HTTP 状态码 | 大类:4xx 客户端错、5xx 服务端错 | 禁止业务错误返回 200 |
| 业务错误码 | 细节:六位数字,前三位模块、后三位具体错误 | 错误码表全覆盖,无「未知错误」 |
| 错误响应体 | 排查线索 | code、message、traceId 三字段齐全 |
验收时专门做一轮错误注入测试:传错参数、带过期签名、模拟超时,看返回是否规范。「成功路径能通」只完成了一半的验收,错误路径才是日常运维要面对的。
接口层的重试、熔断、降级策略,属于架构层的议题,展开在高可用架构。安全层面的验签算法与密钥管理,见安全专题。联调周期怎么排缓冲,看周期拆解——那篇里联调计划两周实际五周的数据,就是这份清单想预防的事。
去年看过一个项目,联调阶段卡了整整四周,原因说出来不值一提:双方的签名算法实现都没错,但一方对参数做 URL encode 时把空格编码成 +,另一方按 RFC 3986 编码成 %20。两行代码的差异,四周的工期。这个案例的通用教训是:联调第一件事不是测业务逻辑,是用最小请求把签名、时间戳、编码这三件基础设施的事对齐。对齐之后再谈功能,效率完全不同。
API integration is the part of a platform build most dependent on someone else's cooperation, and the most reliable source of delay. The root cause is rarely technical difficulty — it is unspecified expectations. This page provides the checklist in three stages: before, during and after.
Of ten failed integrations, four die here. The usual causes: parameter-sorting rules differ (lexicographic order, case sensitivity), timestamp tolerance is misaligned (aim for ±300 seconds), or encoding differs (how URL encoding treats spaces). The fix is unglamorous: compare your signature string against their sample code byte by byte, and align before anything else.
Retry-after-timeout is daily life in distributed systems. If an endpoint is not idempotent, one retry becomes two orders. Ask before integrating: is this endpoint idempotent, and what is the idempotency key? No answer means treat it as non-idempotent — generate your own unique request ID and send it along.
Do not guess timeouts. Read timeout of 3-5 seconds, two to three retries, exponential backoff (1s, 2s, 4s). Past three failed retries, route to a human queue — do not let the machine keep insisting.
| Layer | Responsibility | Acceptance bar |
|---|---|---|
| HTTP status | The category: 4xx client error, 5xx server error | Business errors never return 200 |
| Business codes | The detail: six digits — three for module, three for the error | Code table complete; no "unknown error" |
| Error body | The diagnostic trail | code, message and traceId all present |
Run a dedicated fault-injection round at acceptance: malformed parameters, expired signatures, simulated timeouts. "The happy path works" is half the acceptance — the error path is what operations lives with daily.
Retry, circuit-breaking and degradation policies at the interface layer are architecture topics — see high-availability architecture. Signature algorithms and key management are covered in the security topic. For how much buffer an integration stage needs, see the timeline breakdown — the two-weeks-planned-five-weeks-actual figure there is exactly what this checklist exists to prevent.
One project we watched last year lost four full weeks in integration for a reason that sounds trivial: both sides implemented the signature algorithm correctly, but one URL-encoded spaces as "+" and the other followed RFC 3986 and encoded them as "%20". Two characters of difference, four weeks of calendar. The general lesson: the first integration task is not business logic. It is aligning the plumbing — signatures, timestamps, encoding — with a minimal request. Only after that do functional tests run at a sane pace.
Send the documentation over — we will walk it against the checklist.
Contact us