API对接文档

API 对接文档

快速集成后台API,实现用户统计、版本检测、错误上报等功能

当前应用:xiazai v1.0

01 快速开始

API 地址
https://cs.tinyaii.top/api/v1
App Key
534a235d30f13cac
请求格式
application/json
响应格式
application/json

02 API 接口

POST /api/v1/user/heartbeat

定期上报用户活跃状态,用于统计DAU/WAU/MAU。建议每5-10分钟调用一次。

请求参数
{
    "app_key": "534a235d30f13cac",
    "machine_id": "用户机器唯一标识",
    "version": "1.0.0"
}
响应示例
{
    "code": 200,
    "message": "心跳记录成功",
    "data": { "recorded": true }
}
POST /api/v1/version/check

检查是否有新版本可用,返回最新版本信息和下载地址。

请求参数
{
    "app_key": "534a235d30f13cac",
    "current_version": "1.0.0",
    "platform": "windows"
}
响应示例
{
    "code": 200,
    "data": {
        "has_update": true,
        "current_version": "1.0.0",
        "latest_version": "1.1.0",
        "download_url": "https://...",
        "release_notes": "更新说明...",
        "force_update": false
    }
}
POST /api/v1/error/report

上报软件运行时的错误信息,便于排查问题。

请求参数
{
    "app_key": "534a235d30f13cac",
    "machine_id": "用户机器标识",
    "software_version": "1.0.0",
    "error_type": "NullReferenceException",
    "error_message": "错误信息",
    "error_stack": "堆栈跟踪",
    "os_info": "Windows 10 Pro"
}

03 代码示例

C# 完整示例
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

public class SoftwareApi
{
    private const string BaseUrl = "https://cs.tinyaii.top/api/v1";
    private const string AppKey = "534a235d30f13cac";
    
    public static async Task Heartbeat(string machineId, string version)
    {
        var client = new HttpClient();
        var data = new { app_key = AppKey, machine_id = machineId, version };
        var json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
        await client.PostAsync($"{BaseUrl}/user/heartbeat", 
            new StringContent(json, Encoding.UTF8, "application/json"));
    }
    
    public static async Task<UpdateInfo> CheckUpdate(string currentVersion)
    {
        var client = new HttpClient();
        var data = new { app_key = AppKey, current_version = currentVersion, platform = "windows" };
        var json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
        var response = await client.PostAsync($"{BaseUrl}/version/check",
            new StringContent(json, Encoding.UTF8, "application/json"));
        var result = await response.Content.ReadAsStringAsync();
        return Newtonsoft.Json.JsonConvert.DeserializeObject<UpdateInfo>(result);
    }
    
    public static async Task ReportError(Exception ex, string machineId, string version)
    {
        var client = new HttpClient();
        var data = new {
            app_key = AppKey,
            machine_id = machineId,
            software_version = version,
            error_type = ex.GetType().Name,
            error_message = ex.Message,
            error_stack = ex.StackTrace,
            os_info = Environment.OSVersion.ToString()
        };
        var json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
        await client.PostAsync($"{BaseUrl}/error/report",
            new StringContent(json, Encoding.UTF8, "application/json"));
    }
}
Python 示例
import requests
import platform
import uuid

BASE_URL = "https://cs.tinyaii.top/api/v1"
APP_KEY = "534a235d30f13cac"

def get_machine_id():
    return str(uuid.getnode())

def heartbeat(version):
    data = {
        "app_key": APP_KEY,
        "machine_id": get_machine_id(),
        "version": version
    }
    requests.post(f"{BASE_URL}/user/heartbeat", json=data)

def check_update(current_version):
    data = {
        "app_key": APP_KEY,
        "current_version": current_version,
        "platform": platform.system().lower()
    }
    response = requests.post(f"{BASE_URL}/version/check", json=data)
    return response.json()

def report_error(exception, version):
    data = {
        "app_key": APP_KEY,
        "machine_id": get_machine_id(),
        "software_version": version,
        "error_type": type(exception).__name__,
        "error_message": str(exception),
        "error_stack": "",
        "os_info": platform.platform()
    }
    requests.post(f"{BASE_URL}/error/report", json=data)

04 导出文档

导出完整的API对接文档,方便离线查看或分享给团队成员。

导出 Markdown 文档 前往API测试