# PC 客户端授权登录
使用知音楼授权登录功能并确认登录您的系统,在您的系统内获得正在访问用户的知音楼身份,而用户无需输入账户密码。
# 获取 appId 及 appSecret
联系知音楼的产品李世东老师(工号:352989),创建用于免登过程中验证身份的 appId 及 appSecret
需提交字段 | 是否必填 | 说明 |
---|---|---|
名称 | 必填 | 授权应用的名称 |
描述 | 必填 | 应用使用的场景 |
授权页面 LOGO 地址 | 必填 | 以 http 或 https 开头 |
回调域名 | 必填 | 应用回调的 scheme 地址,e.g. yach:// |
# 获取用户授权码
客户端内通过 iframe 嵌入授权页面
# host: https://yach-work.zhiyinlou.com 正式环境
# host: https://yach-work-test.zhiyinlou.com 测试环境 (具备调试条件)
<iframe width="100%" height="100%" frameborder="0" src="https://yach-work.zhiyinlou.com/login/qrcode/deskauth?appid=xxx&redirect_uri=yachtest%3A%2F%2Ftest.com%2FwinAuth%3Fextraparam%3Dtest" ></iframe>
# 参数
参数 参数类型 必须 说明 appid String 是 扫码登录应用 appid redirect_uri String 是 scheme 地址,需要在自己的 pc 客户端中注册 scheme,授权页面会通过 scheme 与 pc 客户端通信**(要通过 encodeURIComponent 编码)** quick_sign String 否 头像快捷登录的签名(过度期,暂不是必须传。过渡期后,必须传)获取快捷登录签名 通过知音楼 App 扫码或者通过快速登录模式获取用户授权码
用户通过使用知音楼 App 扫码二维码或者通过快速登录模式(知音楼 pc 客户端唤醒并且登录状态下可以通过快速登录模式登录),此操作成功后,会跳转到 redirect_uri scheme 地址,并向 redirect_uri 参数中追加用户授权码 loginTmpCode。
# 通过用户授权码获取临时授权码
# host: https://yach-oapi.zhiyinlou.com 正式环境
# host: https://yach-oapi-dev.zhiyinlou.com 开发环境 (具备调试条件)
# host: https://yach-oapi-test.zhiyinlou.com 测试环境 (具备调试条件)
# host: https://yach-oapi-pre.zhiyinlou.com 预发布环境
# 概述
名称 | 值 |
---|---|
地址 | /connect/oauth2/sns_authorize?appid=APPID&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=REDIRECT_URI&loginTmpCode=loginTmpCode |
请求方式 | GET |
参数 | 见【参数】 |
返回值 | 见【返回值】 |
# 参数
参数 | 参数类型 | 必须 | 说明 |
---|---|---|---|
appid | String | 是 | 扫码登录应用 appid |
redirect_uri | String | 是 | 重定向地址,该地址使用应用后端提供的回调接口(接口请求方式为 GET 请求),用于应用后端获取 tmp_auth_code,并通过 tmp_auth_code 换取用户信息,参数必填 |
state | String | 是 | 用于防止重放攻击,开发者可以根据此信息来判断 redirect_uri 只能执行一次来避免重放攻击, 选填 |
response_type | String | 是 | 固定为 code,必填 |
scope | String | 是 | 固定为 snsapi_login,必填 |
loginTmpCode | String | 是 | 通过 js 获取到的 loginTmpCode,必填 |
此链接处理成功后,会 302 跳转到你 goto 参数指定的 redirect_uri,并向 url 参数中追加临时授权码 code 及 state 两个参数。
e.g.
https://yach-oapi.zhiyinlou.com/connect/oauth2/sns_authorize?appid=APPID&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=REDIRECT_URI&loginTmpCode=loginTmpCode
# 通过临时授权码获取授权用户的个人信息
# host: https://yach-oapi.zhiyinlou.com 正式环境
# host: https://yach-oapi-dev.zhiyinlou.com 开发环境 (具备调试条件)
# host: https://yach-oapi-test.zhiyinlou.com 测试环境 (具备调试条件)
# host: https://yach-oapi-pre.zhiyinlou.com 预发布环境
# 概述
名称 | 值 |
---|---|
地址 | /sns/getuserinfo_bycode |
请求方式 | POST |
参数 | 见【参数】 |
返回值 | 见【返回值】 |
# 参数
参数 | 参数类型 | 必须 | 说明 |
---|---|---|---|
tmp_auth_code | String | 是 | 用户授权的临时授权码 code,只能使用一次;在扫码后回调到设置的 redirect_uri 时会追加 code 参数 |
# URL 签名参数说明
参数 | 参数类型 | 必须 | 说明 |
---|---|---|---|
accessKey | String | 是 | 扫码应用 appid |
timestamp | String | 是 | 当前时间戳,单位是毫秒 |
signature | String | 是 | 通过扫码应用 appSecret 计算出来的签名值,签名计算方法 |
# Signature 参数
签名算法为 HmacSHA256,签名数据是当前时间戳 timestamp,密钥是 appId 对应的 appSecret 计算出来的签名值。
发送 HTTP 请求时需要把 signature 进行 urlEncode,如果您使用的是 HTTP 封装方法,请确保不要重复 urlEncode。
签名计算代码示例(PHP)
// 根据timestamp, appSecret计算签名值
$s = hash_hmac('sha256', 'timestamp', 'appSecret', true);
$signature = base64_encode($s);
var_dump($signature);
$urlencode_signature = urlencode($signature);
var_dump($urlencode_signature);
签名例子参考:
- timestamp=1546084445901
- appSecret=testappSecret
- signature=HCbG3xNE3vzhO+u7qCUL1jS5hsu2n5r2cFhnTrtyDAE=
- urlEncode 后的 signature=HCbG3xNE3vzhO%2Bu7qCUL1jS5hsu2n5r2cFhnTrtyDAE%3D
【注意】正常情况下 access_token 有效期为 7200 秒,有效期内重复获取返回相同结果。
返回值
{
"code": 200,
"msg": "",
"obj": {
"user_info": {
"nick": "晋刚",
"userid": "Yach076429"
}
}
}
返回值说明:
参数 | 说明 |
---|---|
code | 返回码 |
msg | 对返回码的文本描述内容 |
obj | 返回数据 |
userid | 员工在当前企业内的唯一标识 |
# 获取快捷登录签名
# host: https://yach-oapi.zhiyinlou.com 正式环境
# host: https://yach-oapi-test.zhiyinlou.com 测试环境
# 概述
名称 | 值 |
---|---|
地址 | /connect/oauth2/quick_login_sign?access_token=ACCESS_TOKEN |
请求方式 | GET |
参数 | 见【参数】 |
返回值 | 见【返回值】 |
# 参数
参数 | 参数类型 | 必须 | 说明 |
---|---|---|---|
access_token | String | 是 | 接口调用凭证 |
返回值
{
"code": 200,
"msg": "",
"obj": {
"quick_sign": "string"
}
}
返回值说明:
参数 | 说明 |
---|---|
code | 返回码 |
msg | 对返回码的文本描述内容 |
obj | 返回数据 |
quick_sign | 快捷登录签名 |