API 集成文档

本文档介绍如何将您的软件接入授权验证系统

概述

授权验证系统提供 RESTful API 接口,支持卡密激活、验证、域名授权等功能。所有接口返回 JSON 格式数据。

基础信息

API地址: https://your-domain.com/api/
请求方式: GET / POST
返回格式: JSON

卡密验证接口

POST

验证卡密是否有效,并激活卡密

请求参数:

{
  "action": "verify",
  "card_key": "卡密",
  "device_id": "设备码(可选)",
  "product_id": "产品ID"
}

返回示例:

{
  "success": true,
  "data": {
    "card_key": "XXXX-XXXX-XXXX",
    "status": "used",
    "expires_at": "2025-12-31 23:59:59",
    "user": { "id": 1, "username": "user" }
  }
}
GET

查询卡密状态,不激活卡密

域名验证接口

GET

验证域名是否已授权

返回示例:

{
  "success": true,
  "data": {
    "domain": "example.com",
    "status": "active",
    "expires_at": "2025-12-31 23:59:59"
  }
}

用户相关接口

POST /api/user.php

用户登录验证

{
  "action": "login",
  "username": "用户名",
  "password": "密码"
}
GET /api/user.php?id=用户ID

获取用户信息和授权状态

错误码说明

错误码 说明
400参数错误
401未授权/登录失效
403无权限
404资源不存在
500服务器错误

示例代码

PHP 示例:

<?php
$apiUrl = 'https://your-domain.c../api/cards.php';
$data = [
    'action' => 'verify',
    'card_key' => 'XXXX-XXXX-XXXX',
    'product_id' => 1
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$result = json_decode($response, true);
if ($result['success']) {
    echo "验证成功";
}

JavaScript 示例:

const response = await fetch('https://your-domain.c../api/cards.php', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        action: 'verify',
        card_key: 'XXXX-XXXX-XXXX',
        product_id: 1
    })
});
const result = await response.json();
if (result.success) {
    console.log('验证成功');
}