# soho-open-sdk **Repository Path**: work-soho/soho-open-sdk ## Basic Information - **Project Name**: soho-open-sdk - **Description**: SOHO开放平台调用SDK - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-26 - **Last Updated**: 2026-01-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Soho Open SDK SOHO 开放平台 Java SDK,支持签名鉴权与 OAuth2(client_credentials / authorization_code)。 ## 安装 按需打包本地 jar 或发布到你的 Maven 仓库后引用。 ## 快速开始(签名模式) ```java SohoClientConfig config = SohoClientConfig.builder() .serverUrl("http://localhost:6677") .appKey("test") .appSecret("test") .build(); SohoClient client = new SohoClient(config); ExampleListRequest request = new ExampleListRequest(); ExampleListApiRequest apiRequest = new ExampleListApiRequest(request); ApiResponse response = client.execute(apiRequest); System.out.println(response); ``` ## OAuth2:客户端凭证(client_credentials) ```java SohoClientConfig config = SohoClientConfig.builder() .serverUrl("http://localhost:6677") .appKey("test") .appSecret("test") .authMode(AuthMode.OAUTH2) .oauth2GrantType("client_credentials") .build(); SohoClient client = new SohoClient(config); ApiResponse response = client.execute(apiRequest); ``` ## OAuth2:授权码(authorization_code) 步骤 1:引导用户授权,获取 code(浏览器跳转): ``` GET https://open.demo.soho.work/oauth/authorize?response_type=code&client_id=APP_KEY&redirect_uri=CALLBACK&state=xxx ``` 步骤 2:使用 code 交换 token: ```java SohoClientConfig config = SohoClientConfig.builder() .serverUrl("http://localhost:6677") .appKey("test") .appSecret("test") .authMode(AuthMode.OAUTH2) .oauth2GrantType("authorization_code") .oauth2RedirectUri("http://localhost:8080/callback") .build(); SohoClient client = new SohoClient(config); String token = client.exchangeAuthorizationCode("code-from-redirect", "http://localhost:8080/callback"); System.out.println("access_token=" + token); ApiResponse response = client.execute(apiRequest); ``` ## RequestOptions(单次调用覆盖) ```java RequestOptions options = RequestOptions.builder() .header("x-trace-id", "test") .connectTimeoutMs(2000) .readTimeoutMs(5000) .signEnabled(false) // 可选 .build(); ApiResponse response = client.execute(apiRequest, options); ``` ## 示例代码位置 示例入口已移至测试目录:`src/test/java/work/soho/open/sdk/Main.java`。 ## 配置说明 - 默认 token 地址:`{serverUrl}/open/guest/oauth/2.0` - OAuth2 返回结构读取 `payload.access_token` 与 `payload.expires_in` - OAuth2 模式会自动添加 `Authorization: Bearer `