身份验证 
所有对TronZap API的请求都需要使用Bearer令牌和签名进行身份验证。这确保了您的API请求的安全性和完整性。
获取API凭据 
要开始使用TronZap API,您需要从控制面板获取API凭据:
- 登录您的TronZap控制面板
 - 导航到API部分
 - 复制您的API令牌和密钥
 

TIP
请确保您的API凭据安全,永远不要公开分享它们。您的API密钥应像密码一样对待。
必需的请求头 
| 请求头 | 描述 | 
|---|---|
Authorization: Bearer YOUR_API_TOKEN | 您的API令牌 | 
X-Signature: YOUR_SIGNATURE | 请求签名 | 
Content-Type: application/json | 内容类型必须为JSON | 
签名计算 
签名通过请求体与您的API密钥连接后的SHA256哈希值计算。
bash
signature=$(echo -n "$requestBody$apiSecret" | sha256sum | cut -d' ' -f1)不同语言的示例 
bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{"service":"energy","params":{"address":"TRX_ADDRESS","energy_amount":65000,"duration":1}}'
# 计算签名
SIGNATURE=$(echo -n "${REQUEST_BODY}${API_SECRET}" | sha256sum | cut -d' ' -f1)
# 发送API请求
curl -X POST "https://api.tronzap.com/v1/transaction/new" \
  -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({
  service: 'energy',
  params: {
    address: 'TRX_ADDRESS',
    energy_amount: 65000,
    duration: 1
  }
});
// 计算签名
const signature = crypto
  .createHash('sha256')
  .update(requestBody + apiSecret)
  .digest('hex');
// 发送API请求
axios({
  method: 'post',
  url: 'https://api.tronzap.com/v1/transaction/new',
  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([
  'service' => 'energy',
  'params' => [
    'address' => 'TRX_ADDRESS',
    'energy_amount' => 65000,
    'duration' => 1
  ]
]);
// 计算签名
$signature = hash('sha256', $requestBody . $apiSecret);
// 发送API请求
$ch = curl_init('https://api.tronzap.com/v1/transaction/new');
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({
  'service': 'energy',
  'params': {
    'address': 'TRX_ADDRESS',
    'energy_amount': 3206500000,
    'duration': 1
  }
})
# 计算签名
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/transaction/new',
  headers=headers,
  data=request_body
)
print(response.json())