Repository navigation
✨chore: Cai API SDK开发者工具包初始化
Cai API SDK开发者工具包
介绍
这是 cai-api-sdk 项目的首个版本 v0.0.1,该 SDK 提供了与第三方 API 的简化集成,支持通过 API 调用执行签名验证和用户信息处理。
主要特性包括:
- 基于 Spring Boot 自动配置,快速集成 API 客户端
- 提供基于 Hutool 加密库的 SHA-256 签名生成功能
- 实现了基础的用户实体类用于 API 调用中的身份标识
- 支持自定义
accessKey和secretKey通过配置文件注入
主要变更
- 初始化项目结构,包含
CaiApiClient、SignUtil工具类、User实体类。 - 提供基础的 API 客户端集成与用户验证功能。
- 自动生成的 JavaDoc 注释,支持文档生成。
用法
-
添加 Maven 依赖
您可以通过 Maven 将
cai-api-sdk添加到您的项目中。在pom.xml中引入如下依赖:<dependency> <groupId>com.caiths</groupId> <artifactId>cai-api-sdk</artifactId> <version>0.0.1</version> </dependency>
-
Spring Boot 自动配置
cai-api-sdk基于 Spring Boot 自动配置,您只需在配置文件中提供accessKey和secretKey即可完成 API 客户端的初始化。以下是配置示例:# application.properties caiapi.client.accessKey=your-access-key caiapi.client.secretKey=your-secret-key
-
签名工具的使用
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); } }
-
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
accessKeyandsecretKeyfrom configuration files
Changes
- Initialized project structure, including
CaiApiClient,SignUtil, andUserclasses. - Provides basic API client integration and user authentication functionality.
- Added automatic JavaDoc annotations for documentation generation.
Usage
-
Add Maven Dependency
You can include
cai-api-sdkin your project by adding the following Maven dependency to yourpom.xml:<dependency> <groupId>com.caiths</groupId> <artifactId>cai-api-sdk</artifactId> <version>0.0.1</version> </dependency>
-
Spring Boot Auto-Configuration
The
cai-api-sdkis auto-configured with Spring Boot. You just need to provide theaccessKeyandsecretKeyin 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
-
Using the Signature Utility
The
SignUtilprovides 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); } }
-
Using the API Client
The
CaiApiClientwill 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.