POST请求 #
url: /echart/dataset_api/
Content-Type: application/x-www-form-urlencoded
请求参数data #
{
"visitor":"xxx",
"token":"xxx",
"stamp":"xxxxx",
"type":"xxx",
"ds":[["A","B"],["a1","b1"],["a2","b2"]],
"update":0
}
参数说明 #
visitor: 用户名
type: 接口数据集ID
stamp: 时间戳(1970年1月1日到生成时间的毫秒数)
token: 采用sha1加密, token=SHA1(秘钥 + stamp + visitor + type)
update: 0表示新增, 1表示数据更新
ds: 二维数组 或 参考数据填报或数据更新的格式要求
“秘钥"即管理员在API服务设定中的"token”
返回格式 #
{
"status": 200,
"msg": "success"
}
调用样列参考 #
def post_data():
import requests
import hashlib
url='http://localhost:8000/echart/dataset_api/'
visitor = 'xxx'
key = 'xxxxxx'
chart_type = 123
ContentType="application/x-www-form-urlencoded"
stamp = int(time.time() * 1000)
token = hashlib.sha1(f"{key}{stamp}{visitor}{chart_type}".encode('utf-8')).hexdigest()
ds= json.dumps([["A", "B"],["a1", "b1"],["a2", "b2"]])
data={
"visitor": visitor,
"token": token,
"stamp": stamp,
"type": chart_type,
"ds": ds
}
res = requests.post(url, data=data, headers={'Content-Type': ContentType})
print(res.json())
接口配置 #
- 新建数据集
- 写入相关配置
dataset={
"table":"表名(字段1,字段2....)",
"preSql":["truncate table abc"],
"postSql":["insert into xxx select ...."]
}
- 相关权限管理参考“数据服务设定”