认证请求调用方式
认证请求与普通请求的区别:
| 内容 | 普通请求 | 认证请求 |
|---|---|---|
| 频率限制(每分钟) | 30次 | 120次 |
| 频率限制(每10分钟) | 90次 | 600次 |
| 繁忙时优先处理 | 否 | 是 |
| 非公开接口 | 不可用 | 可用 |
你可以从开发者那获取令牌(TOKEN)与密钥(SECRET_KEY),接口提供签名验证和IP白名单验证,为确保请求安全,请您务必启用一种验证方式,若同时启用签名验证和IP验证,您可以从这两种验证方式中任选一种进行请求。
| 参数 | 仅token | 签名验证 | IP验证 |
|---|---|---|---|
| token | 必须 | 必须 | 必须 |
| timestamp | 非必须 | 必须 | 非必须 |
| nonce | 非必须 | 必须 | 非必须 |
| sign | 非必须 | 必须 | 非必须 |
签名验证示例:
python
import time
import hashlib
import hmac
import requests
import uuid
from requests.exceptions import RequestException
def get_mcping(token: str, secret_key: str):
# 生成当前Unix时间戳(秒级)
timestamp = str(int(time.time()))
# 生成唯一随机字符串(每次请求随机生成,2分钟内避免出现重复)
nonce = uuid.uuid4().hex
# 计算HMAC-SHA256签名
signature = hmac.new(
secret_key.encode(),
f"{token}{timestamp}{nonce}".encode(),
hashlib.sha256
).hexdigest()
# 发送请求
try:
response = requests.get(
"https://api.azsu.top/mcping/json",
params={
"ip": "azsu.top", # 其他参数
"token": token, # 您的token
"timestamp": timestamp, # 时间戳
"nonce": nonce, # 一次性随机字符串
"sign": signature # 签名
},
timeout=10
)
return response.json()
except RequestException as e:
print(f"请求失败: {e}")
return None
if __name__ == "__main__":
TOKEN = "替换为您的token"
SECRET_KEY = "替换为您的密钥"
result = get_mcping(TOKEN, SECRET_KEY)
print(result)