案例:如何设置token有效期
更新时间: 2023-04-03 15:57:29
阅读 1051
案例:如何设置token有效期
注:目前saas版本不支持集成。
以公开环境为例
接口网址:https://netease.youdata.163.com/
接口后缀:api/dash/util/genToken
请求方式:post
提交内容:{
'tokenType': 'userPassword',
'email': #登入账户,
'password': #密码
“expiryTime“: 默认为秒,填写时间
}
返回内容:{
'code': 200,
'result':xxxxxxxx,
'logPath': xxxxxxxx
}
以python为例
import requests as re
import json
def get_token(host, post_json):
data = json.dumps(post_json)
headers = {
"content-type": "application/json; charset=UTF-8",
"user-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36",
"x-requested-with": "XMLHttpRequest",
"accept": "text/plain, */*; q=0.01",
"accept-encoding": "gzip, deflate, br"
}
api_url = 'api/dash/util/genToken'
if "https://" in host:
url = host + api_url
else:
url = "https://" + host + api_url
back = json.loads(re.post(url=url, headers=headers, data=data).text)["result"]
return back
# 请求接口
host = 'https://netease.youdata.163.com/'
# 提交json内容
post_json = {
"tokenType": "userPassword",
"email": "ceshi@163.com",
"password": "110",
"expiryTime": 86400 * 30
}
token = get_token(host, post_json)
print(token)
文档反馈
以上内容对您是否有帮助?