生活随笔
收集整理的這篇文章主要介紹了
腾讯云,物联网通信产品,动态注册步骤
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
使用apipost,post方法。
test_sign.py腳本生成sign
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
))
λ test_sign.py
sign_content:
POST
ap-guangzhou.gateway.tencentdevices.com
/device/register
hmacsha256
1625543789
542787393
770efeee110dca75a929ceab8b94ff1c5b67351e6db8da1a01ad0a275ce22d93
sign_base64: b’VhXqxMUBJxx4F94f69pl4FXAuUoDQEEfMgNS6X2poOw=’
信息填入,注意按照圖片里來,sign是單引號里面的內(nèi)容json不能有空格,回車換行,需要和py代碼里的一致
點擊發(fā)送
{"Response": {"Len": 53,"Payload": "VquGm1QSJ8LtvTiGq3Zl8peo7Bjqr95bUuEwkRydEytD43dETTxiE7Jye4PE9hQCAGiMS9lqUvdyG5vNY3NIQg==","RequestId": "d8a2876d-d6b1-4f1a-8685-043971539fa2"}
}
回復(fù)內(nèi)容使用base64解碼
VquGm1QSJ8LtvTiGq3Zl8peo7Bjqr95bUuEwkRydEytD43dETTxiE7Jye4PE9hQCAGiMS9lqUvdyG5vNY3NIQg==
base64解碼https://the-x.cn/base64/
去掉空格回車http://tools.bugscaner.com/text/zifuchuanqukongge.html
aes解密https://the-x.cn/cryptography/Aes.aspx
總結(jié)
以上是生活随笔為你收集整理的腾讯云,物联网通信产品,动态注册步骤的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。