Skip to content

客户端 SDK ​

端游、插件只接一份 KeepSDK.dll。不要自己加载各家官方 dll。密钥不要写进客户端,也不要写进 keepsdk.json。

位数必须和游戏 exe 一致:32 位 exe 只能加载 32 位 dll。字符串一律 UTF-8。不要链 .lib,用 LoadLibrary + GetProcAddress。

主窗口出来之后、在引擎主线程再 Init / Login / Pay。Init 返回非 0 必须退出游戏。进程退出前主线程调 Shutdown。必须由渠道大厅启动,本地双击 exe 通常登不上。

回调里的 json 返回后失效,立刻拷贝。打点、聊天审核的回调可能不在主线程。

调用顺序 ​

  1. KeepSDK_Init
  2. KeepSDK_Login
  3. KeepSDK_GetSession / KeepSDK_GetParam 记住登录参数
  4. 支付、特权、打点等
  5. KeepSDK_Shutdown
c
typedef void (*KeepSDK_Callback)(int code, const char* json);

code == 0 成功。失败 json 形如 {"message":"..."}。

接口 ​

KeepSDK_Init ​

读 keepsdk.json(先 dll 旁,再 exe 旁),初始化。

参数说明
json_override一般传 NULL,不要自己拼配置

返回 0 成功,非 0 失败并退出游戏。

c
if (KeepSDK_Init(NULL) != 0) {
    ExitProcess(1);
}

KeepSDK_Shutdown ​

释放。退出前主线程调用。无参数。

KeepSDK_Login ​

登录。成功后才能取会话、支付。

参数说明
cb回调。code==0 时 json 为登录会话

登录成功后把会话交给游戏服建档。不要再回调 KeepSDK。字段与 登录 相同:app_id、uid、server_id、adult、client,以及游戏 login_url 回的 ticket(没有则为空)。渠道票留在 dll 里,支付时自动带,不要从会话里取。

c
void OnLogin(int code, const char* json) {
    if (code != 0) return;
    /* 立刻拷贝 json,发给游戏服 */
}
KeepSDK_Login(OnLogin);

KeepSDK_GetSession ​

登录后的整包会话 JSON。返回值是所需字节数(不含结尾 0);buf==NULL 或 buflen<=0 只探长度。

c
int n = KeepSDK_GetSession(NULL, 0);
char buf[4096];
if (n > 0 && n < (int)sizeof(buf)) {
    KeepSDK_GetSession(buf, sizeof(buf));
}

KeepSDK_GetParam ​

按 key 取单个字段。返回值规则与 GetSession 相同。

可取:uid、app_id、server_id、adult、client、ticket。账号用 uid,不要用渠道原名当主键。

c
char uid[256];
int n = KeepSDK_GetParam("uid", NULL, 0);
if (n > 0 && n < (int)sizeof(uid)) {
    KeepSDK_GetParam("uid", uid, sizeof(uid));
}

KeepSDK_Pay ​

拉起支付。没有回调。入参是游戏服用 pay_key 签好的 JSON 字符串,字段见 支付。不要传完整 URL。会话里已有的 app_id / uid 等可省略,dll 会补,但 sign 必须覆盖最终会出现的字段。

返回 0 表示已去拉起支付窗。

c
KeepSDK_Pay(pay_json_from_gameserver);

KeepSDK_GetPrivilegeEntry ​

要挂哪些特权入口。不打网关。写入 buf 的 JSON 见 平台特权入口。返回值规则与 GetSession 相同。

KeepSDK_OpenPrivilegePage ​

点了 privilege、要用系统特权页时再调。页游用 JS,端游用本函数。

参数必填说明
server_id是区服
server_name是区服名
role_id是角色 ID
role_name是角色名
c
KeepSDK_OpenPrivilegePage("{\"server_id\":\"1\",\"server_name\":\"1区\",\"role_id\":\"10001\",\"role_name\":\"角色名\"}", cb);

KeepSDK_ChatFilter ​

发言送审。JSON 字段见 聊天审核。游戏服直打网关也可以。

KeepSDK_ReportRole / KeepSDK_ReportEvent ​

打点。JSON 字段见 打点。游戏服直打网关也可以。

KeepSDK_GetVipProfile / KeepSDK_ReportBenefit ​

查平台 VIP、上报加赠。字段见 平台VIP信息、平台VIP收益。游戏服直打网关也可以。