mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 01:50:30 +08:00
feat: add native/Java auth SDK, docs, CI, and examples
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* C++ 调用示例:初始化、校验许可、销毁句柄。
|
||||
*
|
||||
* 版权所有 © 广州创飞人工智能技术有限公司
|
||||
* 开发者:huangping@craftlabs.cn
|
||||
*/
|
||||
#include "craftlabs_auth.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
int main() {
|
||||
AuthHandle h = auth_initialize("{}");
|
||||
if (!h) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
AuthResult r = auth_check_license(h);
|
||||
if (r.success == 0) {
|
||||
auth_destroy(h);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auth_destroy(h);
|
||||
std::printf("example cpp ok\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import cn.craftlabs.auth.AuthProvider;
|
||||
import cn.craftlabs.auth.AuthResult;
|
||||
import cn.craftlabs.auth.bitanswer.BitAnswerProvider;
|
||||
|
||||
/**
|
||||
* 演示:通过 {@link BitAnswerProvider} 完成初始化与许可校验。
|
||||
*
|
||||
* <p>版权所有 © 广州创飞人工智能技术有限公司
|
||||
*
|
||||
* @author huangping@craftlabs.cn
|
||||
*/
|
||||
public class ExampleApp {
|
||||
public static void main(String[] args) {
|
||||
try (AuthProvider p = new BitAnswerProvider()) {
|
||||
AuthResult r = p.initialize("{}");
|
||||
System.out.println("init: " + r.isSuccess() + " " + r.getMessage());
|
||||
r = p.checkLicense();
|
||||
System.out.println("check: " + r.isSuccess() + " " + r.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
"""示例:设置 CRAFTLABS_AUTH_LIBRARY 或 PYTHONPATH 后运行。
|
||||
|
||||
版权所有 © 广州创飞人工智能技术有限公司
|
||||
开发者:huangping@craftlabs.cn
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
sys.path.insert(0, os.path.join(ROOT, "python"))
|
||||
|
||||
from craftlabs_auth import AuthApi # noqa: E402
|
||||
|
||||
|
||||
def main() -> None:
|
||||
lib = os.path.join(ROOT, "native", "build", "libcraftlabs_auth_bitanswer.so")
|
||||
if os.path.isfile(lib):
|
||||
os.environ.setdefault("CRAFTLABS_AUTH_LIBRARY", lib)
|
||||
|
||||
with AuthApi() as api:
|
||||
print(api.initialize("{}"))
|
||||
print(api.check_license())
|
||||
print(api.get_license_info())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user