[color=var(--color-prettylights-syntax-comment)]# -*- coding: utf-8 -*- |
| [color=var(--color-prettylights-syntax-keyword)]import hmac |
| [color=var(--color-prettylights-syntax-keyword)]import time |
| [color=var(--color-prettylights-syntax-keyword)]import requests |
| [color=var(--color-prettylights-syntax-keyword)]from base64 [color=var(--color-prettylights-syntax-keyword)]import urlsafe_b64encode |
| |
| [color=var(--color-prettylights-syntax-comment)]# 管理台获取accessKey、secretKey |
| accessKey [color=var(--color-prettylights-syntax-constant)]= [color=var(--color-prettylights-syntax-string)]'' |
| secretKey [color=var(--color-prettylights-syntax-constant)]= [color=var(--color-prettylights-syntax-string)]'' |
| |
| [color=var(--color-prettylights-syntax-comment)]# APP或管理台获取设备识别码 |
| deviceName [color=var(--color-prettylights-syntax-constant)]= [color=var(--color-prettylights-syntax-string)]'' |
| |
| [color=var(--color-prettylights-syntax-comment)]# 存储数据的key |
| dataKey [color=var(--color-prettylights-syntax-constant)]= [color=var(--color-prettylights-syntax-string)]'' |
| |
| [color=var(--color-prettylights-syntax-comment)]# token过期时间 |
| expirationTime [color=var(--color-prettylights-syntax-constant)]= [color=var(--color-prettylights-syntax-entity)]int(time.[color=var(--color-prettylights-syntax-entity)]time()) [color=var(--color-prettylights-syntax-constant)]+ [color=var(--color-prettylights-syntax-constant)]60 [color=var(--color-prettylights-syntax-constant)]* [color=var(--color-prettylights-syntax-constant)]60 |
| |
| url [color=var(--color-prettylights-syntax-constant)]= [color=var(--color-prettylights-syntax-string)]"https://storage.diandeng.tech/api/v1/ts?e={0}&device={1}&keyword={2}&quickDate=1h&queryType=avg".[color=var(--color-prettylights-syntax-entity)]format( |
| expirationTime, deviceName, dataKey) |
| |
| sign [color=var(--color-prettylights-syntax-constant)]= [color=var(--color-prettylights-syntax-entity)]urlsafe_b64encode( |
| hmac.[color=var(--color-prettylights-syntax-entity)]new(secretKey.[color=var(--color-prettylights-syntax-entity)]encode([color=var(--color-prettylights-syntax-string)]"utf-8"), |
| url.[color=var(--color-prettylights-syntax-entity)]encode([color=var(--color-prettylights-syntax-string)]"utf-8"), digestmod[color=var(--color-prettylights-syntax-constant)]=[color=var(--color-prettylights-syntax-string)]'sha1').[color=var(--color-prettylights-syntax-entity)]digest() |
| ).[color=var(--color-prettylights-syntax-entity)]decode([color=var(--color-prettylights-syntax-string)]"utf-8") |
| token [color=var(--color-prettylights-syntax-constant)]= accessKey [color=var(--color-prettylights-syntax-constant)]+ [color=var(--color-prettylights-syntax-string)]":" [color=var(--color-prettylights-syntax-constant)]+ sign |
| [color=var(--color-prettylights-syntax-entity)]print(token) |
| |
| respson [color=var(--color-prettylights-syntax-constant)]= requests.[color=var(--color-prettylights-syntax-entity)]get(url [color=var(--color-prettylights-syntax-constant)]+ [color=var(--color-prettylights-syntax-string)]"&token="[color=var(--color-prettylights-syntax-constant)]+token) |
| [color=var(--color-prettylights-syntax-entity)]print(respson.[color=var(--color-prettylights-syntax-entity)]json()) |