开发文档
OAuth 2.0 授权码模式接入指南 · 麟泓开放平台
一、概述
本平台采用标准 OAuth 2.0 授权码模式,开发者只需三步即可让应用接入本平台账号登录。
- 在用户中心创建应用,获取
App ID和App Secret - 引导用户跳转授权页面,获取临时授权码
code - 使用 code 换取
Access Token,并获取用户信息
二、接口域名
https://open.lhwks.cn
三、创建应用
登录本平台后,进入用户中心,填写应用信息并提交审核。审核通过后即可获取:
| 参数 | 说明 |
|---|---|
| App ID | 应用唯一标识,10位纯数字 |
| App Secret | 应用密钥,32位字母数字组合 |
| 回调地址 | 授权完成后跳转的地址 |
四、授权流程
步骤一:发起授权请求
GET /authorize.php?response_type=code&client_id=APP_ID&redirect_uri=CALLBACK&state=STATE
| 参数 | 必填 | 说明 |
|---|---|---|
| response_type | 是 | 固定值 code |
| client_id | 是 | App ID |
| redirect_uri | 是 | 回调地址 |
| state | 否 | 随机字符串,防 CSRF |
code 一次性有效,有效期为 10分钟,请尽快使用。
步骤二:换取 Access Token
POST /token.php
| 参数 | 必填 | 说明 |
|---|---|---|
| grant_type | 是 | 固定值 authorization_code |
| code | 是 | 授权码 |
| client_id | 是 | App ID |
| client_secret | 是 | App Secret |
| redirect_uri | 是 | 需与上一步一致 |
{
"access_token": "xxxxxxxxxx",
"token_type": "Bearer",
"expires_in": 7200
}
Access Token 有效期为 2小时(7200秒)。
步骤三:获取用户信息
GET /userinfo.php?access_token=TOKEN
{
"openid": "1",
"nickname": "用户昵称",
"username": "username",
"avatar": "https://..."
}
五、错误码
| 错误码 | 说明 |
|---|---|
| invalid_client | App ID/Secret 错误或未审核 |
| invalid_grant | 授权码无效或过期 |
| invalid_token | Token 无效或过期 |
| unsupported_grant_type | grant_type 不支持 |
| missing_token | 缺少 Token |
六、PHP 示例
// 发起授权
$url = 'https://open.lhwks.cn/authorize.php?' . http_build_query([
'response_type' => 'code',
'client_id' => '你的AppID',
'redirect_uri' => 'https://你的网站.com/callback.php',
'state' => bin2hex(random_bytes(8)),
]);
header('Location: ' . $url);
// 回调换取 Token
$ch = curl_init('https://open.lhwks.cn/token.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'authorization_code',
'code' => $_GET['code'],
'client_id' => '你的AppID',
'client_secret' => '你的AppSecret',
'redirect_uri' => 'https://你的网站.com/callback.php',
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tokenData = json_decode(curl_exec($ch), true);
// 获取用户信息
$user = json_decode(file_get_contents('https://open.lhwks.cn/userinfo.php?access_token=' . $tokenData['access_token']), true);
七、SDK 下载
一键接入 SDK
下载 SDK 包,放到你的网站根目录即可快速接入
📄 lhouath_login.php
📄 lhouath_callback.php
📄 README.txt
下载 SDK 压缩包
如有问题请联系 admin@lhwks.cn