获取服务
此接口端点返回可用服务及其价格的列表。
POST /v1/services
请求
此请求不需要任何参数。
bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{}'
# 计算签名
SIGNATURE=$(echo -n "${REQUEST_BODY}${API_SECRET}" | sha256sum | cut -d' ' -f1)
# 发送API请求
curl -X POST "https://api.tronzap.com/v1/services" \
-H "Authorization: Bearer ${API_TOKEN}" \
-H "X-Signature: ${SIGNATURE}" \
-H "Content-Type: application/json" \
-d "${REQUEST_BODY}"
javascript
const crypto = require('crypto');
const axios = require('axios');
const apiToken = 'your_api_token';
const apiSecret = 'your_api_secret';
const requestBody = JSON.stringify({});
// 计算签名
const signature = crypto
.createHash('sha256')
.update(requestBody + apiSecret)
.digest('hex');
// 发送API请求
axios({
method: 'post',
url: 'https://api.tronzap.com/v1/services',
headers: {
'Authorization': `Bearer ${apiToken}`,
'X-Signature': signature,
'Content-Type': 'application/json'
},
data: requestBody
})
.then(response => console.log(response.data))
.catch(error => console.error(error));
php
<?php
$apiToken = 'your_api_token';
$apiSecret = 'your_api_secret';
$requestBody = json_encode([]);
// 计算签名
$signature = hash('sha256', $requestBody . $apiSecret);
// 发送API请求
$ch = curl_init('https://api.tronzap.com/v1/services');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiToken,
'X-Signature: ' . $signature,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
python
import hashlib
import json
import requests
api_token = 'your_api_token'
api_secret = 'your_api_secret'
request_body = json.dumps({})
# 计算签名
signature = hashlib.sha256((request_body + api_secret).encode()).hexdigest()
# 发送API请求
headers = {
'Authorization': f'Bearer {api_token}',
'X-Signature': signature,
'Content-Type': 'application/json'
}
response = requests.post(
'https://api.tronzap.com/v1/services',
headers=headers,
data=request_body
)
print(response.json())
响应
响应提供有关可用能量服务和地址激活定价的信息。
响应字段
字段 | 类型 | 描述 |
---|---|---|
code | integer | 响应代码(0 = 成功) |
result | object | 响应数据 |
result.energy | array | 可用能量服务列表 |
result.energy[].duration | integer | 持续时间(小时)(1小时或24小时) |
result.energy[].min_energy | integer | 最小能量数量 |
result.energy[].max_energy | integer | 最大能量数量 |
result.energy[].price | float | 每1000能量的价格 |
result.energy[].price_32k | float | 32k能量的价格 |
result.energy[].price_65k | float | 65k能量的价格 |
result.energy[].price_131k | float | 131k能量的价格 |
result.activate_address | object | 地址激活服务信息 |
result.activate_address.price | float | 地址激活价格 |
响应示例
json
{
"code": 0,
"result": {
// 租赁能量服务
"energy": [
{
"duration": 1,
"min_energy": 50000,
"max_energy": 131000,
"price": 0.052300000,
"price_32k": 1.67,
"price_65k": 3.4,
"price_131k": 6.85
},
{
"duration": 1,
"min_energy": 131000,
"max_energy": 4000000,
"price": 0.052000000,
"price_32k": 1.66,
"price_65k": 3.38,
"price_131k": 6.81
},
{
"duration": 24,
"min_energy": 50000,
"max_energy": 131000,
"price": 0.13000000,
"price_32k": 4.16,
"price_65k": 8.45,
"price_131k": 17.03
},
{
"duration": 24,
"min_energy": 131000,
"max_energy": 4000000,
"price": 0.114500000,
"price_32k": 3.66,
"price_65k": 7.44,
"price_131k": 15.00
}
],
// 地址激活服务
"activate_address": {
"price": 1.4
}
}
}
可能的错误
错误代码 | 描述 |
---|---|
1 | 身份验证错误(令牌或签名不正确) |