🛡 ShieldPHP · 客户端验证 API ← 返回首页

客户端验证 API

对标米验验证体系:RSA-2048 签名 + AES-256-CBC 业务加密 + TS+Nonce 防重放。
所有对接标配双层加密,签名校验和业务加密分离。

⚠ 重要 verify_rsa 永远明文返回;auth / use / unbind 请求和响应均使用 RSA+AES 双层加密。

对接流程

  1. 获取公钥 (verify_rsa)客户端用应用 API Key 请求 RSA-2048 公钥,明文返回。
  2. 生成 AES 密钥客户端随机生成 32 字节 AES-256 密钥 + 16 字节随机 IV。
  3. RSA 加密 AES 密钥用服务端公钥(RSA-2048 OAEP)加密 AES 密钥。
  4. AES 加密业务数据用 AES-256-CBC 加密 JSON 业务数据(含 card_key、machine_id、nonce、timestamp)。
  5. 发起请求POST encrypted_key + encrypted_data + iv(均为 Base64)到 auth / use / unbind。
  6. 解密响应服务端返回 encrypted=true 时,用同样方式(RSA 解 AES 密钥 → AES 解数据)。

接口清单

action功能说明加密方式
verify_rsa获取应用 RSA-2048 公钥明文
auth验证卡密并激活设备RSAAES
use次数卡扣减RSAAES
unbind解绑设备RSAAES
check_update版本检测 + 云配置Base64

1. verify_rsa——获取公钥

GET 请求,明文。返回应用对应的 RSA-2048 公钥。

请求参数

参数类型必填说明
actionstring固定值 verify_rsa
api_keystring应用 API Key

响应示例

{
  "ok": true,
  "action": "verify_rsa",
  "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAO...\n-----END PUBLIC KEY-----",
  "key_bits": 2048
}

2. auth——验证卡密并激活设备

POST 请求。需要双层加密:RSA 加密 AES 密钥 → AES 加密业务数据。

请求参数

参数类型必填说明
actionstringauth
api_keystring应用 API Key
encrypted_keystringRSA 加密的 AES 密钥 (Base64)
encrypted_datastringAES 加密的业务数据 (Base64)
ivstring16 字节随机 IV (Base64)

业务数据 JSON(AES 解密后)

{
  "card_key": "DEMO-2026-PRO",
  "machine_id": "device-fingerprint-abc123",
  "nonce": "random-nonce-at-least-16-chars",
  "timestamp": 1752330000
}

加密响应示例

{
  "ok": true,
  "action": "ok",
  "encrypted": true,
  "encrypted_key": "RSA加密的AES密钥(Base64)",
  "encrypted_data": "AES加密的响应数据(Base64)",
  "iv": "16字节随机IV(Base64)"
}

响应 JSON(AES 解密后)

{
  "status": "ok",
  "plan": "permanent",
  "expires_at": "unlimited",
  "remaining": 500,
  "quota": 500,
  "machine_bound": true
}

3. use——次数扣减

次数卡需要每次操作调一次。encrypted_data 包含 machine_id

参数类型必填说明
actionstringuse
api_keystring应用 API Key
encrypted_keystringRSA 加密的 AES 密钥
encrypted_datastringAES 加密 { machine_id, nonce, timestamp }
ivstring16 字节随机 IV

4. unbind——解绑设备

应用需开启"允许解绑"。encrypted_data 包含 card_keymachine_id

解绑次数不能超过解绑次数上限,每次解绑扣除设定的小时数。黑名单设备禁止解绑。

5. check_update——版本检测

明文 + Base64 JSON。用于检查新版本和下发云端配置。

参数类型必填说明
actionstringcheck_update
api_keystring应用 API Key
datastringBase64 编码的 JSON

data JSON(Base64 解码后)

{
  "version": "1.0.0"
}

响应示例

{
  "ok": true,
  "action": "check_update",
  "need_update": false,
  "latest_version": "1.0.0",
  "current_version": "1.0.0",
  "force_update": false,
  "update_url": "",
  "announcement": "",
  "cloud_config": {}
}

加密参数说明

参数说明
AES 密钥客户端随机生成 32 字节 (AES-256),用 RSA 公钥加密后传输
AES IV客户端随机生成 16 字节,Base64 编码明文传输
timestampUnix 时间戳(秒),允许与服务器误差 ±5 分钟,超出判定请求过期
nonce随机字符串,最少 16 位,同一 nonce 5 分钟内不可重复使用
RSA 加密RSA-2048 + OAEP (SHA-256) 填充
AES 加密AES-256-CBC,PKCS7 填充
响应加密auth / use / unbind 返回 encrypted=true 需解密;verify_rsa / check_update 永远明文

对接代码示例 (PHP)

<?php
// 1. 获取公钥
$resp = file_get_contents('https://php.3xt.top/api/client.php?action=verify_rsa&api_key=YOUR_API_KEY');
$data = json_decode($resp, true);
$pubKey = $data['public_key'];

// 2. 生成 AES 密钥和 IV
$aesKey = random_bytes(32); // AES-256
$iv = random_bytes(16);
$nonce = bin2hex(random_bytes(16));
$timestamp = time();

// 3. RSA 加密 AES 密钥
openssl_public_encrypt($aesKey, $encKey, $pubKey, OPENSSL_PKCS1_OAEP_PADDING);

// 4. AES 加密业务数据
$payload = json_encode([
    'card_key' => 'DEMO-2026-PRO',
    'machine_id' => 'device-fingerprint-abc123',
    'nonce' => $nonce,
    'timestamp' => $timestamp,
]);
$encData = openssl_encrypt($payload, 'aes-256-cbc', $aesKey, OPENSSL_RAW_DATA, $iv);

// 5. 发送 auth 请求
$ch = curl_init('https://php.3xt.top/api/client.php');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => http_build_query([
        'action' => 'auth',
        'api_key' => 'YOUR_API_KEY',
        'encrypted_key' => base64_encode($encKey),
        'encrypted_data' => base64_encode($encData),
        'iv' => base64_encode($iv),
    ]),
    CURLOPT_RETURNTRANSFER => true,
]);
$resp = json_decode(curl_exec($ch), true);
curl_close($ch);

// 6. 解密响应 (如果 encrypted=true)
if (!empty($resp['encrypted'])) {
    openssl_private_decrypt(base64_decode($resp['encrypted_key']), $aesKey, $privKey, OPENSSL_PKCS1_OAEP_PADDING);
    $plain = openssl_decrypt(
        base64_decode($resp['encrypted_data']),
        'aes-256-cbc', $aesKey, OPENSSL_RAW_DATA,
        base64_decode($resp['iv'])
    );
    print_r(json_decode($plain, true));
}

错误码

错误信息说明处理建议
应用不存在或 API Key 错误api_key 无效检查 API Key 是否正确
卡密不存在卡密输入错误检查卡密是否正确
设备数量已达上限已绑定其他设备联系开发者解绑或使用解绑接口
卡密已过期使用时间到期续期或更换卡密
次数已用完次数卡已耗尽续期或更换卡密
重复请求nonce 重复或超时每次生成新 nonce,检查时间同步
请求已过期timestamp 超时检查设备系统时间