Skip to content

✨chore: Cai API SDK开发者工具包初始化

Choose a tag to compare

@poboll poboll released this 25 Oct 05:21
· 2 commits to main since this release

Cai API SDK开发者工具包

English | 中文

介绍

这是 cai-api-sdk 项目的首个版本 v0.0.1,该 SDK 提供了与第三方 API 的简化集成,支持通过 API 调用执行签名验证和用户信息处理。

主要特性包括:

  • 基于 Spring Boot 自动配置,快速集成 API 客户端
  • 提供基于 Hutool 加密库的 SHA-256 签名生成功能
  • 实现了基础的用户实体类用于 API 调用中的身份标识
  • 支持自定义 accessKey 和 secretKey 通过配置文件注入

主要变更

  • 初始化项目结构,包含 CaiApiClient、SignUtil 工具类、User 实体类。
  • 提供基础的 API 客户端集成与用户验证功能。
  • 自动生成的 JavaDoc 注释,支持文档生成。

用法

  1. 添加 Maven 依赖

    您可以通过 Maven 将 cai-api-sdk 添加到您的项目中。在 pom.xml 中引入如下依赖:

    <dependency>
        <groupId>com.caiths</groupId>
        <artifactId>cai-api-sdk</artifactId>
        <version>0.0.1</version>
    </dependency>
  2. Spring Boot 自动配置

    cai-api-sdk 基于 Spring Boot 自动配置,您只需在配置文件中提供 accessKey 和 secretKey 即可完成 API 客户端的初始化。以下是配置示例:

    # application.properties
    caiapi.client.accessKey=your-access-key
    caiapi.client.secretKey=your-secret-key
  3. 签名工具的使用

    SignUtil 提供了便捷的接口签名生成功能,您可以通过以下方式生成签名:

    import com.caiths.caiapisdk.utils.SignUtil;
    
    public class Example {
        public static void main(String[] args) {
            String body = "exampleBody";
            String secretKey = "yourSecretKey";
            
            String signature = SignUtil.genSign(body, secretKey);
            System.out.println("Generated Signature: " + signature);
        }
    }
  4. API 客户端的使用

    CaiApiClient 会自动加载 Spring 配置,您可以在任意需要使用 API 的类中直接注入并调用:

    import com.caiths.caiapisdk.client.CaiApiClient;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    @Service
    public class ApiService {
    
        @Autowired
        private CaiApiClient caiApiClient;
    
        public void callApi() {
            // 使用 CaiApiClient 进行 API 调用
            String response = caiApiClient.getNameByGet("exampleName");
            System.out.println("API Response: " + response);
        }
    }

其他信息

该版本标志着 cai-api-sdk 项目的首次发布,后续版本将进一步扩展功能,欢迎反馈和贡献。


Initial Release of Cai API SDK

Introduction

This is the first version v0.0.1 of the cai-api-sdk project. The SDK simplifies integration with third-party APIs and supports operations such as signature verification and user information handling via API calls.

Key Features:

  • Spring Boot auto-configuration for quick integration of the API client
  • Provides a SHA-256 signature generation feature using the Hutool encryption library
  • Basic user entity class for identity representation in API calls
  • Supports injecting accessKey and secretKey from configuration files

Changes

  • Initialized project structure, including CaiApiClient, SignUtil, and User classes.
  • Provides basic API client integration and user authentication functionality.
  • Added automatic JavaDoc annotations for documentation generation.

Usage

  1. Add Maven Dependency

    You can include cai-api-sdk in your project by adding the following Maven dependency to your pom.xml:

    <dependency>
        <groupId>com.caiths</groupId>
        <artifactId>cai-api-sdk</artifactId>
        <version>0.0.1</version>
    </dependency>
  2. Spring Boot Auto-Configuration

    The cai-api-sdk is auto-configured with Spring Boot. You just need to provide the accessKey and secretKey in the configuration file to initialize the API client. Here's a configuration example:

    # application.properties
    caiapi.client.accessKey=your-access-key
    caiapi.client.secretKey=your-secret-key
  3. Using the Signature Utility

    The SignUtil provides an easy way to generate a signature. You can use the following code to generate a signature:

    import com.caiths.caiapisdk.utils.SignUtil;
    
    public class Example {
        public static void main(String[] args) {
            String body = "exampleBody";
            String secretKey = "yourSecretKey";
            
            String signature = SignUtil.genSign(body, secretKey);
            System.out.println("Generated Signature: " + signature);
        }
    }
  4. Using the API Client

    The CaiApiClient will automatically load the Spring configuration, allowing you to inject and use it wherever needed:

    import com.caiths.caiapisdk.client.CaiApiClient;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    @Service
    public class ApiService {
    
        @Autowired
        private CaiApiClient caiApiClient;
    
        public void callApi() {
            // Use CaiApiClient to call API
            String response = caiApiClient.getNameByGet("exampleName");
            System.out.println("API Response: " + response);
        }
    }

Additional Information

This version marks the first release of the cai-api-sdk project. Future versions will expand on functionality, and contributions are welcome.