美文网首页
雁飞•格物DMP平台设备接入(HTTP协议)

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

作者: 羋学僧 | 来源:发表于2022-02-17 15:36 被阅读0次

雁飞•格物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)

相关文章

网友评论

      本文标题:雁飞•格物DMP平台设备接入(HTTP协议)

      本文链接:https://www.haomeiwen.com/subject/qgcslrtx.html