Files
workphone-sdk/sdk/app/services/device_id_util.py
Manus AI 42fe10401a 1
1
2026-05-24 17:50:04 +08:00

20 lines
636 B
Python
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.

"""设备 ID 衍生字段MD5 等),供 API 与控制台展示。"""
from __future__ import annotations
import hashlib
def device_id_md5(device_id: str) -> str:
"""设备 serial / device_id 的 MD5小写 hex32 位)。"""
raw = (device_id or "").strip()
return hashlib.md5(raw.encode("utf-8")).hexdigest()
def enrich_device_id_fields(device: dict) -> dict:
"""为设备 dict 补充 device_id_md5不改变原 dict 引用时可就地更新)。"""
did = device.get("device_id") or device.get("serial") or ""
if did:
device["device_id_md5"] = device_id_md5(str(did))
return device