更新时间:2025-08-28 GMT+08:00
自定义模板示例
示例1
证书认证设备,不限制UserName与ClientId参数取值,从设备证书通用名称(Common Name)中取值设备ID。
|
参数 |
说明 |
|---|---|
|
Client ID |
任意值 |
|
User Name |
任意值 |
|
Password |
空值 |
鉴权模板:
{
"template_name": "template1",
"description": "template1",
"template_body": {
"parameters": {
"iotda::certificate::common_name": {
"type": "String"
}
},
"resources": {
"device_id": {
"Ref": "iotda::certificate::common_name"
}
}
}
}
示例2
设备ID格式为:${ProductId}_${NodeId}。
|
参数 |
说明 |
|---|---|
|
Client ID |
固定格式: ${ClientId}|securemode=2,signmethod=hmacsha256,timestamp=${timestamp}|
|
|
User Name |
由设备标识码和产品ID组成,固定格式: ${NodeId}&${ProductId} |
|
Password |
以设备密码为密钥,将设备参数与参数值拼接后的字符串为加密串进行hmacsha256算法加密。 加密串格式: clientId${clientId}deviceName${nodeId}productKey${productId}timestamp${timestamp}
|
鉴权模板:
{
"template_name": "template2",
"description": "template2",
"template_body": {
"parameters": {
"iotda::mqtt::client_id": {
"type": "String"
},
"iotda::mqtt::username": {
"type": "String"
},
"iotda::device::secret": {
"type": "String"
}
},
"resources": {
"device_id": {
"Fn::Join": [{
"Fn::SplitSelect": [
"${iotda::mqtt::username}",
"&",
1
]
}, "_", {
"Fn::SplitSelect": [
"${iotda::mqtt::username}",
"&",
0
]
}]
},
"timestamp": {
"type": "UNIX",
"value": {
"Fn::MathDiv": [{
"Fn::ParseLong": {
"Fn::SplitSelect": [{
"Fn::SubStringAfter": [{
"Fn::SplitSelect": ["${iotda::mqtt::client_id}", "|", 1]
}, "timestamp="]
}, ",", 0]
}
}, 1000]
}
},
"password": {
"Fn::HmacSHA256": [{
"Fn::Sub": [
"clientId${clientId}deviceName${deviceName}productKey${productKey}timestamp${timestamp}",
{
"clientId": {
"Fn::SplitSelect": [
"${iotda::mqtt::client_id}",
"|",
0
]
},
"deviceName": {
"Fn::SplitSelect": [
"${iotda::mqtt::username}",
"&",
0
]
},
"productKey": {
"Fn::SplitSelect": [
"${iotda::mqtt::username}",
"&",
1
]
},
"timestamp": {
"Fn::SplitSelect": [{
"Fn::SubStringAfter": [{
"Fn::SplitSelect": ["${iotda::mqtt::client_id}", "|", 1]
}, "timestamp="]
}, ",", 0]
}
}
]
},
"${iotda::device::secret}"
]
}
}
}
}
示例3
设备ID格式为:${productId}${nodeId}。
|
参数 |
说明 |
|---|---|
|
Client ID |
固定格式: ${productId}${nodeId}
|
|
User Name |
固定格式: ${productId}${nodeId};12010126;${connid};${expiry}
|
|
Password |
固定格式: ${token};hmacsha256
|
鉴权模板:
{
"template_name": "template3",
"description": "template3",
"template_body": {
"parameters": {
"iotda::mqtt::client_id": {
"type": "String"
},
"iotda::mqtt::username": {
"type": "String"
},
"iotda::device::secret": {
"type": "String"
}
},
"resources": {
"device_id": {
"Ref": "iotda::mqtt::client_id"
},
"timestamp": {
"type": "UNIX",
"value": {
"Fn::ParseLong": {
"Fn::SplitSelect": ["${iotda::mqtt::username}", ";", 3]
}
}
},
"password": {
"Fn::Sub": [
"${token};hmacsha256",
{
"token": {
"Fn::HmacSHA256": [
"${iotda::mqtt::username}",
{
"Fn::Base64Decode": "${iotda::device::secret}"
}
]
}
}
]
}
}
}
}
父主题: MQTT(S)协议-自定义模板鉴权