UNPKG

@tongji_api/sdk

Version:

同济大学开放平台SDK

75 lines (55 loc) 1.37 kB
# @tongji_api/sdk 同济大学开发者平台官方SDK,提供OAuth2.0认证和API调用功能。 通过scripts/generate-oauth-client.mjs脚本自动生成sdk。 ## 安装 ```bash npm install @tongji_api/sdk # 或 yarn add @tongji_api/sdk ``` ## 快速开始 ```typescript import { createOAuthClient } from '@tongji_api/sdk'; const client = createOAuthClient({ clientId: 'YOUR_CLIENT_ID', clientSecret: 'YOUR_CLIENT_SECRET', tokenUrl: 'https://api.tongji.edu.cn/oauth2/token' }); // 获取用户信息 const user = await client.getSingleInfo('20666093'); console.log(user); ``` ## API 文档 ### OAuthClient #### 构造函数 ```typescript new OAuthClient(config: OAuthConfig) ``` #### 方法 - `getSingleInfo(studentId: string): Promise<UserInfo>` - `getOrganization(orgId: string): Promise<Organization>` - `refreshToken(refreshToken: string): Promise<TokenResponse>` ### 类型定义 ```typescript interface OAuthConfig { clientId: string; clientSecret: string; tokenUrl: string; } interface UserInfo { id: string; name: string; email: string; studentId: string; department: string; } // 其他类型定义... ``` ## 开发 1. 克隆仓库 2. 安装依赖: `npm install` 3. 修改package.json中的版本号等信息 4. 构建: `npm run build` ## 发布 1. 登录npm: `npm login` 2. 发布: `npm publish --access public`