跳到主要内容

API集成

API地址:https://revenue.ezfuns.com/api/v1/server
请求方法:POST
请求头:可选 Content-Type: text/plain

API集成通过 JWT 进行鉴权,可以从 https://jwt.io/libraries 找到相应的库。

请求URL:API地址 + '/' + 接口名称

请求参数:

payload = {
"method": "接口名称", # 接口名称
"params": {}, # 接口参数
"exp": now + 30*60, # 过期时间,建议当前时间+30分钟
"nonce": "random-string", # 随机字符串,32个字符以内
}
project_id = "xxx" # 项目ID
project_secret = "xxx" # API密钥
body = jwt.encode(
payload,
key=project_secret,
algorithm="HS256",
headers={"project_id": project_id},
)

通过以上步骤将请求参数编码成一个字符串,将此字符串作为请求体发送请求。

请求体字符串示例,可通过 jwt.io 解码查看内容:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsInByb2plY3RfaWQiOiJic3EwaDhoMzJyem00In0.eyJtZXRob2QiOiJjdXN0b21lci5pbmZvIiwicGFyYW1zIjp7InBheXdhbGxfaWQiOiJlbmMxMDVmZ2duNXhhIiwiY3VzdG9tZXIiOnsiZXh0ZXJuYWxfaWQiOiJpbnRlcm5hbF8yMjY0Mjg5MTcyOTI4MDczNTM5In0sImluY2x1ZGVfYmFsYW5jZSI6dHJ1ZX0sImV4cCI6MTY1NTIxMzUzOCwibm9uY2UiOiJzSTIzR01kMHI0cjluQSJ9.z0nsbVO3H-lpUgtq-glPGpzOBb_8YPLVCgpXK-hNiAE

响应内容:

对于 200 状态码的成功响应,响应内容为JWT字符串,通过以下步骤解开响应体。

payload = jwt.decode(
body,
key=project_secret,
options={"require": ["exp", "nonce"]},
algorithms=["HS256"],
)
result = payload['result']

对于非 200 状态码的错误响应,响应内容为JSON数据,无需特殊处理。

响应体字符串示例,可通过 jwt.io 解码查看内容:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsInByb2plY3RfaWQiOiJic3EwaDhoMzJyem00In0.eyJyZXN1bHQiOnsiaWQiOiIxMzUzNzQ1NzU2MDY3MDA0NDAxMCIsImV4dGVybmFsX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