Files
chongdun-mianya/docs/api.md
2026-10-27 13:54:39 +08:00

88 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 免押订单接口约定(给服务端)
小程序端只负责展示和拉起支付宝原生授权页,**所有芝麻信用相关调用、密钥、加签、异步通知都在服务端**。
前端目前走 `config/index.js` 的 `useMock: true` 本地 mock,服务端就绪后改 `false` 即可切到下面这套接口。
统一返回体:
```json
{ "code": 0, "message": "", "data": {} }
```
`code` 为 `0` 表示成功,非 0 时把 `message` 直接弹给用户。
## 1. 创建免押订单
```
POST /api/credit/orders
```
请求:
```json
{
"itemName": "宠物智能项圈",
"depositAmount": 69
}
```
服务端要做的事:调芝麻信用开放接口创建信用借还订单,把支付宝返回的信用借还单号一并下发。
响应:
```json
{
"orderId": "CO20261027120000",
"creditBorrowOrderId": "ZM20261027120000"
}
```
`creditBorrowOrderId` 是小程序拉起原生授权页时唯一要用的参数(见 `utils/zhima.js`)。
## 2. 查询订单
```
GET /api/credit/orders/{orderId}
```
响应(字段与 mock 对齐):
```json
{
"orderId": "CO20261027120000",
"itemName": "宠物智能项圈",
"depositAmount": 69,
"depositMode": "CREDIT",
"status": "ACTIVE",
"createdAt": 1761537600000
}
```
- `depositMode`:`CREDIT` 信用免押 / `PAID` 现场付押金
- `status`:`PENDING` 授权中 / `ACTIVE` 免押生效 / `RELEASED` 已解除 / `OVERDUE` 逾期未还
免押结果页会轮询这个接口(约 1.2 秒一次、最多 6 次)确认最终状态,**不要**用客户端回调直接判定成功。
## 3. 最近一单
```
GET /api/credit/orders/latest
```
无订单时返回 `null`(`data: null`)。
## 4. 解除信用授权 / 退还押金
```
POST /api/credit/orders/{orderId}/release
```
服务端调芝麻接口结束信用订单,并同步完成押金/履约处理;返回更新后的订单对象。
## 服务端必须兜住的几件事
1. **异步通知(notify)验签 + 幂等**:芝麻的授权结果、订单完结等以 notify 为准,重复通知只处理一次。
2. **信用闭环回传**:订单生成、逾期、归还完结都要真实回传支付宝,不能造数据。
3. **密钥不下发**:加签私钥、商户 ID 只留服务端,小程序只拿 `orderId` / `creditBorrowOrderId`。
4. **接口名以开通后的文档为准**:芝麻信用「信用借还」的具体开放接口名、参数随能力开通版本变化,本仓库没有硬编码,集中在 `utils/zhima.js` 与本文档两处待替换。