鉴权
1. 简介
鉴权 用于获取和管理访问令牌,以便访问需要认证的 API 接口。
2. 鉴权
2.1 获取 API Key
2.2 使用 API Key 生成 Access Token
请求
- 方法: POST
- 路径:
https://api.nuwaai.com/web/apiKey/auth - 消息体:
{
"secretKey": "{apikey}"
}
参数说明
| 参数名称 | 类型 | 是否必填 | 参数说明 |
|---|---|---|---|
| apikey | String | 是 | API 密钥中生成的 key |
响应
{
"code": {code},
"msg": {message},
"data": {data}
}
| 参数名称 | 类型 | 是否必填 | 参数说明 |
|---|---|---|---|
| code | int | 是 | 响应码:0 为 ok,其他为错误,具体错误 message |
| message | String | 否 | 当响应码为 0 时返回。具体错误原因 |
| data | String | 是 | 当响应码为 0 时返回。返回内容为 access_token |
示例
const secretKey = 'sk-jqZ-gBPcRCG1nLpaenmS1gew7rcCkIs-NUWSPzpd3DeWYxobM_CHm-uPTCa8gDPv';
fetch('https://api.nuwaai.com/web/apiKey/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
secretKey: secretKey,
}),
})
.then(res => res.json())
.then(data => {
if (data.code === 0) {
console.log('token:', data.data);
localStorage.setItem('token', data.data);
} else {
console.error('请求失败:', data.msg);
}
})
.catch(error => {
console.error('请求出错:', error);
});