01
下面的python代码,在在线python环境运行,得出需要的header信息 https://www.bejson.com/runcode/python3/
import hashlib import random import time import hmac import base64 if __name__ == '__main__': sign_format = '%s\n%s\n%s\n%s\n%s\n%d\n%d\n%s' url_format = '%s://ap-guangzhou.gateway.tencentdevices.com/device/register' request_format = "{\"ProductId\":\"%s\",\"DeviceName\":\"%s\"}" device_name = 'dev002' product_id = 'JCZDFSOKXS' product_secret = 'X42fPqwHxPiIBwY94cY5sQ1Y' request_text = request_format % (product_id, device_name) request_hash = hashlib.sha256(request_text.encode("utf-8")).hexdigest() nonce = random.randrange(2147483647) timestamp = int(time.time()) sign_content = sign_format % ( "POST", "ap-guangzhou.gateway.tencentdevices.com", "/device/register", "", "hmacsha256", timestamp, nonce, request_hash) print("\nsign_content: \n" + sign_content) sign_base64 = base64.b64encode(hmac.new(product_secret.encode("utf-8"), sign_content.encode("utf-8"), hashlib.sha256).digest()) print("sign_base64: " + str(sign_base64))
02
信息填入,注意按照图片里来,sign是单引号里面的内容json不能有空格,回车换行,格式需要和py代码里的一致
03
点击发送
{ "Response": { "Len": 53, "Payload": "VquGm1QSJ8LtvTiGq3Zl8gyE5HeIuO2IHtF22EZkyXRiwtwT5beApNUc5HnSl4cEGPtmF+L1stfToazWkcVFuA==", "RequestId": "9a995aae-2b4d-41f5-b437-cf8a9ee30a9d", "State": 1 } }
04
base64解码https://the-x.cn/base64/
05
去掉空格回车http://www.esjson.com/delSpace.html
06
aes解密https://the-x.cn/cryptography/Aes.aspx
注意第四项是产品秘钥,第五项是16个0
结果中的psk就是设备秘钥
本文章源自奇迹物联开源的物联网应用知识库Cellular IoT Wiki,更多技术干货欢迎关注收藏Wiki:Cellular IoT Wiki 知识库(https://rckrv97mzx.feishu.cn/wiki/wikcnBvAC9WOkEYG5CLqGwm6PHf)
(如有侵权,联系删除)
文章评论(0条评论)
登录后参与讨论