Files
verify/sdk/cpp
admin ed4a561704 feat: add application API documentation and C++ SDK
- Add complete API documentation for application integration (docs/API_DOCUMENT.md)
- Fix check-update API to use version ID comparison instead of string comparison
- Add validation: client version must exist in server version list
- Add support for patch/incremental updates with base_version check
- Add C++ SDK with HTTP client, JSON parser, and crypto support
- Add simple_test.cpp for standalone testing on Windows

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 11:58:44 +08:00
..

验证平台 C++ SDK

用于对接验证平台的C++ SDK库。

依赖

  • C++17 或更高版本
  • libcurl
  • nlohmann/json
  • OpenSSL (可选,用于AES加密)

编译

使用 CMake

mkdir build
cd build
cmake ..
make

编译选项

  • USE_OPENSSL=ON/OFF - 启用/禁用 OpenSSL (默认: ON)
  • BUILD_TESTS=ON/OFF - 构建/不构建测试程序 (默认: ON)

Ubuntu/Debian 依赖安装

sudo apt-get install libcurl4-openssl-dev libssl-dev nlohmann-json3-dev cmake g++

Windows (vcpkg)

vcpkg install curl nlohmann-json openssl
cmake -DCMAKE_TOOLCHAIN_FILE=[vcpkg路径]/scripts/buildsystems/vcpkg.cmake ..

使用示例

基本用法

#include "verify_client.hpp"

int main() {
    // 创建客户端
    verify::Client client("https://gendan.xyz", "your_app_key");
    
    // 获取应用信息
    auto info = client.getAppInfo();
    std::cout << "应用名称: " << info.name << std::endl;
    
    // 用户登录
    auto loginResult = client.login("username", "password", "device_id");
    std::string token = loginResult["token"].get<std::string>();
    std::cout << "Token: " << token << std::endl;
    
    // 心跳上报
    client.heartbeat(loginResult["user_id"].get<uint64_t>(), "device_id", "instance_id");
    
    return 0;
}

使用加密

// 设置AES加密
client.setEncryptType(verify::EncryptType::AES, "your_secret_key_32_bytes_long");

// 设置RC4加密
client.setEncryptType(verify::EncryptType::RC4, "your_secret_key");

设备管理

// 获取设备列表
auto devices = client.getDevices();
for (const auto& d : devices) {
    std::cout << "设备: " << d.deviceName << std::endl;
}

// 解绑设备
client.unbindDevice(userId, "device_id_to_unbind");

云端数据

// 获取云端变量
auto variables = client.getVariables();
std::cout << "变量值: " << variables["key"]["value"] << std::endl;

// 更新云端变量
std::map<std::string, std::string> vars = {{"key1", "value1"}, {"key2", "value2"}};
client.updateVariables(vars);

// 创建变量记录
json record = {{"field1", "value1"}, {"field2", 123}};
client.createVariableRecord("stream_key", record);

API 参考

Client 类

方法 说明
getAppInfo() 获取应用信息
checkUpdate(version) 检查更新
getAnnouncements() 获取公告列表
registerUser(...) 用户注册
login(username, password, deviceId) 用户登录
getAccount(userId) 获取账户信息
heartbeat(userId, deviceId, instanceId) 心跳上报
recharge(username, cardKey, deviceId) 卡密充值
getDevices() 获取设备列表
unbindDevice(userId, deviceId) 解绑设备
getConstants() 获取云端常量
getVariables() 获取云端变量
updateVariables(vars) 更新云端变量
executeDynamicCode(key, params) 执行动态代码

运行测试

./verify_test

测试选项:

  • --help 显示帮助
  • --crypto 仅测试加密
  • --perf 仅测试性能

许可证

MIT License