集成 SDK 快速开始
启动 SecRandom,安装 SecRandom.Integration.Client 后,下面的代码列出名单并按 SecRandom 当前配置点名。除非显式提供,名单、人数和抽取策略由本体决定。
using SecRandom.Integration;using SecRandom.Integration.Client;
var client = new AutomationClient();try{ var lists = await client.GetRosterListsAsync(); Console.WriteLine(string.Join(", ", lists.Students)); var result = await client.DrawAsync(DrawChannel.RollCall); Console.WriteLine(result);}catch (AutomationException ex){ Console.Error.WriteLine($"{ex.Code}: {ex.Message}");}new DrawOptions(List: "一班", Count: 2) 可覆盖本次点名或抽奖;它不会切换默认名单。需要切换默认名单时使用 ActivateRosterAsync。快速抽取按本体设置执行,1.2 会拒绝快抽参数覆盖。抽奖可能被功能开关或安全验证拒绝。启动进程、连接失败、取消与超时还可能抛出标准 .NET 异常。
指定名单、人数等参数需要包含 IPC 参数解析修复的 SecRandom 版本;旧版本可能错误地返回 invalid_parameter。请先更新本体。1.2 还可通过 DrawOptions.Conditions 指定抽奖的奖品标签与发放对象筛选,性别或分组筛选必须同时指定 StudentList。
1.1.0 和 1.2.0 都可以通过通用入口调用服务端支持的任何 v2 方法:
var response = await client.CallAsync("state.draw");Console.WriteLine(response.Result);先调用 system.capabilities 检查目标本体支持的方法;未知方法会返回 unsupported_method。不要对可能已执行的抽取盲目重试。
Python 适配器安装后:
from secrandom_integration import AutomationClient, DrawChannel
client = AutomationClient()print(client.roster_lists())print(client.draw(DrawChannel.ROLL_CALL))print(client.call("state.draw")["result"])Rust 和 C++ 的调用示例见发行包各自的 README.md。这些适配器提供通用 call;C++ 返回原始 JSON,由调用方解析错误和结果。