| 模式 | 适用场景 | 复杂度 |
|---|---|---|
| Secret 令牌模式 | 服务器端对服务器端的 API 调用 | 简单 |
| OAuth2 扫码授权模式 | 需要用户主动授权的第三方应用 | 完整 |
{
"code": 0,
"message": "success",
"data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ 第三方应用 │ │ PC端 │ │ 手机端 │ │ 平台服务 │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │ │
│ 1.申请appCode │ │ │
│<─────────────────>│ │ │
│ │ │ │
│ 2.构造授权链接 │ │ │
│──────────────────>│ │ │
│ │ │ │
│ │ 3.请求授权 │ │
│ │───────────────────────────────────────>
│ │ │ │
│ │ 4.返回二维码 │ │
│ │ │ │
│ │<──────────────────────────────────────│
│ │ │ │
│ │ 5.显示二维码 │ │
│ │<──────────────────│ │
│ │ │ │
│ │ │ 6.用户扫码 │
│ │ │──────────────────>│
│ │ │ │
│ │ │ │
│ │ │ 7.用户确认授权 │
│ │ │──────────────────>│
│ 10.授权成功, │ │ │
│ 重定向 │ │ │
│<──────────────────────────────────────│ │
│ │ │ │
│ 11.用授权码换取用户信息│ │ │
│ (含clientSecret) │ │ │
│──────────────────>│ │ │
│<──────────────────│ │ │
│ │ │ │
│ 12.用secret调用API │ │ │
│<──────────────────>│ │ │| 参数 | 说明 |
|---|---|
appCode | 应用唯一业务标识,用于构造授权链接 |
redirectUri),第三方应用需确保该地址可正常访问。https://auth.qunjielong.com/authorize| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
appCode | String | 是 | 从平台获取的应用唯一标识 |
redirect_uri | String | 是 | 授权成功后的回调地址(需与平台配置一致) |
response_type | String | 否 | 固定值 code,默认可不传 |
scope | String | 否 | 授权作用域,默认 oauth_login |
state | String | 是 | 状态 参数,用于防止 CSRF 攻击 |
https://auth.qunjielong.com/authorize?appCode=YOUR_APP_CODE&redirect_uri=https://your-app.com/callback&response_type=code&scope=oauth_login&state=random_state_stringauthorization_code{redirect_uri}?code={authorization_code}&state={state}https://your-app.com/callback?code=auth_code_xxx&state=random_state_stringGET /open/oauth2/user/info| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
authCode | String | 是 | 授权码 |
{
"code": 0,
"message": "success",
"data": {
"ghId": 123456,
"ghName": "主页名称",
"ghIntro": "主页简介",
"ghType": 1,
"logoUrl": "https://platform.com/logo.png",
"clientSecret": "client_secret_xxx"
}
}| 字段 | 说明 |
|---|---|
ghId | 主页 ID |
ghName | 主页名称 |
ghIntro | 主页简介 |
ghType | 主页类型 |
logoUrl | 主页图标 |
clientSecret | 客户端密钥,后续调用 API 需要用到 |
重要: clientSecret是后续调用 API 的凭证,请务必安全存储。
clientSecret 后,第三方应用即可使用该密钥调用其他 API 接口。GET /open/auth/token| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
secret | String | 是 | 客户端密钥 |
{
"code": 0,
"message": "success",
"data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}accessToken 后,在请求头或参数中携带令牌访问其他 API:| 错误码 | 说明 | 处理建议 |
|---|---|---|
0 | 成功 | - |
-1 | 系统错误 | 重试或联系技术支持 |
400 | 参数错误 | 检查请求参数是否正确 |
401 | 认证失败 | 检查 secret/token 是否有效 |
403 | 无权访问 | 检查应用权限配置 |
404 | 资源不存在 | 检查请求的资源 |
500 | 服务器内部错误 | 重试或联系技术支持 |
state 参数,回调时验证其值,防止 CSRF 攻击:clientSecret 是调用 API 的关键凭证,必须安全存储redirect_uri 与在平台配置的地址完全一致,包括协议、域名和路径。appCode