雁飞•格物DMP平台设备接入(HTTP协议)

雁飞•格物DMP平台设备接入(HTTP协议)

官方文档

有两种模式,一机一密和一型一密,本文主要记录第二种一型一密

(1)一机一密

(2)一型一密

创建产品并发布
编辑物模型并发布
申请动态注册获得deviceSecret

import requests
import time
import json

from hashlib import sha256
import hmac


def get_sign(data,key):
    data = data.encode('utf-8')
    key = key.encode('utf-8')
    sign = hmac.new(key, data, digestmod=sha256).hexdigest().lower()
    return sign



timestamp = str(round(time.time() * 1000))
productKey = "cu3dvw7f1ql1lxDa"
productSecret = "59e7cc19d1deb0c8ff7e9648c2e157e2"
deviceKey = "20220217"
signMethod = "hmacsha256"

sign = get_sign(deviceKey + productKey + signMethod + timestamp, productSecret)

url = "https://dmp-https.cuiot.cn:8943/auth/autoregist"


payload = json.dumps({
    "productKey": productKey,
    "productSecret": productSecret,
    "deviceKey": deviceKey,
    "timestamp": timestamp,
    "signMethod": signMethod,
    "sign":sign
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
激活设备获取token
import requests
import time
import json

from hashlib import sha256
import hmac


def get_sign(data,key):
    data = data.encode('utf-8')
    key = key.encode('utf-8')
    sign = hmac.new(key, data, digestmod=sha256).hexdigest().lower()
    return sign



timestamp = str(round(time.time() * 1000))
productKey = "cu3dvw7f1ql1lxDa"
productSecret = "59e7cc19d1deb0c8ff7e9648c2e157e2"
deviceKey = "20220217"
signMethod = "hmacsha256"
operator = "0"
deviceId = "202202171423"
deviceSecret = "F619453E4F8199E7793EAC0C070E894E"
sign = get_sign(deviceId + deviceKey + productKey + signMethod + operator + timestamp,deviceSecret)

url = "https://dmp-https.cuiot.cn:8943/auth"


payload = json.dumps({
    "productKey" : productKey,
    "deviceKey" : deviceKey,
    "operator" : operator,
    "deviceId" :deviceId,
    "timestamp" : timestamp,
    "signMethod" : signMethod,
    "sign" : sign,
    "deviceSecret" : deviceSecret
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容