API接口文档
概述
本系统提供RESTful API接口,支持开发者通过HTTP POST请求验证用户身份。所有接口均返回JSON格式数据。
API基础地址:https://verify.wdsj.casa/api.php
通用响应格式
成功响应
{
  "status": "success",
  "message": "操作成功的描述信息",
  "data": {
    // 相关数据(可选)
  }
}
        错误响应
{
  "status": "error",
  "message": "错误原因描述"
}
        接口列表
1. 用户注册
URL: https://verify.wdsj.casa/api.php
方法: POST
描述: 注册新用户账号
请求参数:
{
  "action": "register_user",
  "username": "用户名",
  "email": "邮箱地址",
  "password": "密码"
}
                成功响应:
{
  "status": "success",
  "message": "用户注册成功"
}
                2. 用户登录
URL: https://verify.wdsj.casa/api.php
方法: POST
描述: 用户账号登录验证
请求参数:
{
  "action": "login_user",
  "username": "用户名或邮箱",
  "password": "密码"
}
                成功响应:
{
  "status": "success",
  "message": "登录成功",
  "data": {
    "id": 1,
    "username": "用户名",
    "email": "邮箱地址"
  }
}
                3. 开发者注册
URL: https://verify.wdsj.casa/api.php
方法: POST
描述: 注册新开发者账号并获取API密钥
请求参数:
{
  "action": "register_developer",
  "username": "开发者用户名",
  "email": "开发者邮箱",
  "password": "密码"
}
                成功响应:
{
  "status": "success",
  "message": "开发者注册成功",
  "data": {
    "api_key": "生成的API密钥"
  }
}
                4. 开发者登录
URL: https://verify.wdsj.casa/api.php
方法: POST
描述: 开发者账号登录并获取API密钥
请求参数:
{
  "action": "login_developer",
  "username": "开发者用户名或邮箱",
  "password": "密码"
}
                成功响应:
{
  "status": "success",
  "message": "登录成功",
  "data": {
    "id": 1,
    "username": "开发者用户名",
    "email": "开发者邮箱",
    "api_key": "API密钥"
  }
}
                5. 验证用户(开发者调用)
URL: https://verify.wdsj.casa/api.php
方法: POST
描述: 开发者使用API密钥验证用户身份
请求参数:
{
  "action": "verify_user",
  "api_key": "开发者API密钥",
  "username": "要验证的用户名或邮箱",
  "password": "要验证的密码"
}
                成功响应:
{
  "status": "success",
  "message": "登录成功",
  "data": {
    "id": 1,
    "username": "用户名",
    "email": "邮箱地址"
  }
}
                调用示例
PHP示例
<?php
// 验证用户示例
$apiUrl = 'https://verify.wdsj.casa/api.php';
$apiKey = '您的API密钥';
$username = '要验证的用户名';
$password = '要验证的密码';
$data = [
    'action' => 'verify_user',
    'api_key' => $apiKey,
    'username' => $username,
    'password' => $password
];
$options = [
    'http' => [
        'header'  => "Content-type: application/json\r\n",
        'method'  => 'POST',
        'content' => json_encode($data)
    ]
];
$context  = stream_context_create($options);
$result = file_get_contents($apiUrl, false, $context);
if ($result === FALSE) {
    // 处理错误
    echo "API调用失败";
} else {
    $response = json_decode($result, true);
    if ($response['status'] == 'success') {
        echo "验证成功,用户ID: " . $response['data']['id'];
    } else {
        echo "验证失败: " . $response['message'];
    }
}
?>
        JavaScript示例
// 验证用户示例
const apiUrl = 'https://verify.wdsj.casa/api.php';
const apiKey = '您的API密钥';
const username = '要验证的用户名';
const password = '要验证的密码';
fetch(apiUrl, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        action: 'verify_user',
        api_key: apiKey,
        username: username,
        password: password
    })
})
.then(response => response.json())
.then(data => {
    if (data.status === 'success') {
        console.log('验证成功,用户ID:', data.data.id);
    } else {
        console.log('验证失败:', data.message);
    }
})
.catch(error => {
    console.error('API调用失败:', error);
});