blinker数据接口获取数据-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 840|回复: 0

blinker数据接口获取数据

[复制链接]
发表于 2021-9-15 23:50 | 显示全部楼层 |阅读模式
[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())



文档里的获取云存储中的数据的demo,无法获取到数据,有小伙伴能获取到吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 11:54 , Processed in 0.093824 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表