docs: 更正012注册和006绑定协议

This commit is contained in:
stu2not
2026-09-20 11:57:20 +08:00
parent 75fd3d86c4
commit 27e8ccfc2b
2 changed files with 44 additions and 31 deletions
+16 -25
View File
@@ -1,12 +1,12 @@
# Device Bootstrap And Binding Receipt # Device Registration
## Purpose ## Purpose
The device-level bootstrap/binding handshake maps a factory IMEI to Banban's The device registration handshake maps a factory IMEI to Banban's internal
internal `device_id` and `serial_number`. Its successful `msg_id=012` response `device_id` and `serial_number`. `msg_id=012` is the device registration
is the device binding success receipt and includes the associated ICCID for request and response. It is not the user/device binding success receipt and
downstream SIM/traffic binding. Devices do not need to know those IDs before does not represent the `msg_id=006` binding flow. Devices do not need to know
the first handshake. the assigned IDs before the first registration handshake.
## Flow ## Flow
@@ -22,7 +22,7 @@ sequenceDiagram
participant Auth as device_auth participant Auth as device_auth
Factory->>Mapping: Insert imei, device_id, serial_number, status=pending Factory->>Mapping: Insert imei, device_id, serial_number, status=pending
Device->>MQTT: Publish device/{imei}/event msg_id=012 binding request Device->>MQTT: Publish device/{imei}/event msg_id=012 registration request
MQTT->>Handler: Deliver identity init event MQTT->>Handler: Deliver identity init event
Handler->>Init: initialize_by_imei(imei) Handler->>Init: initialize_by_imei(imei)
Init->>Mapping: SELECT mapping by imei Init->>Mapping: SELECT mapping by imei
@@ -40,38 +40,29 @@ sequenceDiagram
Handler-->>MQTT: device/{imei}/event_resp status=failed Handler-->>MQTT: device/{imei}/event_resp status=failed
end end
Init->>Mapping: UPDATE status=activated, activated_at=now Init->>Mapping: UPDATE status=activated, activated_at=now
Handler-->>MQTT: device/{imei}/event_resp binding success receipt Handler-->>MQTT: device/{imei}/event_resp registration success
MQTT-->>Device: Receive device_id, device_sn, and iccid MQTT-->>Device: Receive device_id and device_sn
end end
``` ```
## Binding Success Receipt ## Registration Response
When the IMEI mapping and its authoritative ICCID association are available, When the IMEI mapping is available, the handler returns the registration
the handler returns the device binding success receipt on `msg_id=012`: response on `msg_id=012`:
```json ```json
{ {
"msg_id": "012", "msg_id": "012",
"params": { "params": {
"device_id": "TalkingQ_ZHWK00002110", "device_id": "TalkingQ_ZHWK00002110",
"device_sn": "TQ_ZHWK000000002110", "device_sn": "TQ_ZHWK000000002110"
"iccid": "898604E91123D1334901"
} }
} }
``` ```
The `iccid` value is the canonical, full ICCID used by the downstream SIM and The ICCID belongs to the later `msg_id=006` device-binding success receipt,
traffic service. It must come from an authoritative IMEI-to-ICCID provisioning not to this registration response. The registration response only establishes
record or a validated device report; it must not be derived from the IMEI. the device identity needed by the binding flow.
Successful device binding requires a non-empty, valid ICCID. If the ICCID
cannot be resolved or fails consistency validation, the handler must return
the existing `msg_id=012` failure response instead of returning a partial
success.
Adding `params.iccid` is an additive response-field change. Devices that ignore
unknown JSON fields remain compatible, while strict firmware parsers need a
protocol/version capability check before this response is enabled for them.
## Data Model ## Data Model
+28 -6
View File
@@ -6,11 +6,12 @@ The mini-program binding flow validates an active `device_auth` row before it
creates a pending bind session. Final binding is completed after the device creates a pending bind session. Final binding is completed after the device
returns an NFC card UUID. returns an NFC card UUID.
This is the user/NFC binding flow and is separate from the device-level This is the `msg_id=006` device-binding flow and is separate from the device
`msg_id=012` bootstrap/binding handshake documented in registration handshake documented in `02-device-bootstrap.md`. `msg_id=012`
`02-device-bootstrap.md`. The `msg_id=012` success receipt assigns the device only registers the device identity. `msg_id=006` starts and completes binding
identity and returns `iccid`; this flow binds that device to a mini-program the device to a mini-program user and optional child through the NFC card
user and optional child through the NFC card exchange. exchange; its successful receipt carries the ICCID needed by the downstream
SIM/traffic service.
```mermaid ```mermaid
sequenceDiagram sequenceDiagram
@@ -42,7 +43,7 @@ sequenceDiagram
API-->>Mini: bind_token, expires_at API-->>Mini: bind_token, expires_at
end end
Device->>MQTT: NFC response / card UUID Device->>MQTT: msg_id=006 binding success / card UUID / ICCID
MQTT->>Binding: finalize_nfc_bind(device_id, card_uuid) MQTT->>Binding: finalize_nfc_bind(device_id, card_uuid)
Binding->>DAO: load latest pending bind session Binding->>DAO: load latest pending bind session
Binding->>Card: activate_card(card_uuid, device_id) Binding->>Card: activate_card(card_uuid, device_id)
@@ -51,6 +52,27 @@ sequenceDiagram
Binding->>DAO: mark session completed Binding->>DAO: mark session completed
``` ```
## Binding Success Receipt
The successful device-binding receipt uses `msg_id=006` and includes the
authoritative ICCID:
```json
{
"msg_id": "006",
"params": {
"device_id": "TalkingQ_ZHWK00002110",
"device_sn": "TQ_ZHWK000000002110",
"iccid": "898604E91123D1334901"
}
}
```
The ICCID must come from the authoritative IMEI-to-ICCID provisioning record
or a validated device report. It must not be derived from the IMEI. If the
binding response cannot provide a valid ICCID, the binding result must not be
reported as a complete success.
## Related Tables ## Related Tables
```mermaid ```mermaid