mirror of
https://github.com/SocialSisterYi/bilibili-API-collect.git
synced 2024-12-28 05:20:07 +08:00
update APIdoc【QR登录】
This commit is contained in:
parent
904218627e
commit
60847a83bb
@ -1,36 +1,246 @@
|
||||
# 二维码登录
|
||||
|
||||
web端流程&逻辑:
|
||||
|
||||
1. 获取`二维码内容url`以及`密钥`,以`二维码内容url`生成二维码,等待手机客户端扫描
|
||||
2. 以`密钥`作为参数进行POST
|
||||
3. if `code` == `true` goto `6` else goto 4(是否已经确认)
|
||||
4. if `data` == `-4` goto `2` else goto 5(是否已经扫描)
|
||||
5. if `data` == `-5` goto `3` & 提示`已扫描` else goto `1`&提示`二维码超时或错误`(密钥是否有效)
|
||||
6. 成功后会自动配置cookie 如需登录游戏分站则访问`data`.`url`中的url
|
||||
|
||||
TV端流程&逻辑:
|
||||
|
||||
1. 获取`二维码内容url`以及`密钥`,以`二维码内容url`生成二维码,等待手机客户端扫描
|
||||
2. 以`密钥`作为参数进行POST
|
||||
3. if `code` == `0` 提示`扫码成功`并存储`access_key`于`refersh_key` else goto `4`
|
||||
4. if `code` == `86039` 提示`未扫描`&goto `2` else goto `5`
|
||||
5. if `code` == `86038` 提示`二维码超时或错误`&goto `1`
|
||||
|
||||
<img src="/imgs/2233login.png"/>
|
||||
|
||||
|
||||
- [扫码登录流程(伪代码)](#扫码登录流程(伪代码))
|
||||
- [web端扫码登录](#web端扫码登录)
|
||||
- [申请二维码 (web端)](#申请二维码(web端))
|
||||
- [扫码登录(web端)](#扫码登录(web端))
|
||||
- [web端扫码登录-旧版](#web端扫码登录-旧版)
|
||||
- [申请二维码(web端-旧版)](#申请二维码(web端-旧版))
|
||||
- [扫码登录(web端-旧版)](#扫码登录(web端-旧版))
|
||||
- [TV端扫码登录](#TV端扫码登录)
|
||||
- [申请二维码(TV端)](#申请二维码(TV端))
|
||||
- [扫码登录(TV端)](#扫码登录(TV端))
|
||||
|
||||
---
|
||||
|
||||
- [申请二维码URL及扫码密钥(web端)](#申请二维码URL及扫码密钥(web端))
|
||||
- [使用扫码登录(web端)](#使用扫码登录(web端))
|
||||
- [申请二维码URL及扫码密钥(TV端)](#申请二维码URL及扫码密钥(TV端))
|
||||
- [使用扫码登录(TV端)](#使用扫码登录(TV端))
|
||||
## 扫码登录流程(伪代码)
|
||||
|
||||
---
|
||||
```python
|
||||
token, url = 申请二维码()
|
||||
生成二维码(url) # 等待客户端扫码
|
||||
while True:
|
||||
status, cookie = 扫码登录(token)
|
||||
match status:
|
||||
case 未扫描:
|
||||
continue
|
||||
case 二维码超时 | 二维码失效:
|
||||
提示('二维码失效或超时') # 需要用户重新操作
|
||||
break
|
||||
case 已扫描未确认:
|
||||
提示('扫描成功')
|
||||
case 登录成功:
|
||||
提示('扫描成功')
|
||||
存储cookie(cookie)
|
||||
SSO登录页面跳转()
|
||||
break
|
||||
```
|
||||
|
||||
## 申请二维码URL及扫码密钥(web端)
|
||||
## web端扫码登录
|
||||
|
||||
### 申请二维码(web端)
|
||||
|
||||
> http://passport.bilibili.com/x/passport-login/web/qrcode/generate
|
||||
|
||||
*请求方式:GET*
|
||||
|
||||
密钥超时为180秒
|
||||
|
||||
**json回复:**
|
||||
|
||||
根对象:
|
||||
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| ------- | ---- | -------- | ------- |
|
||||
| code | num | 返回值 | 0:成功 |
|
||||
| message | str | 错误信息 | |
|
||||
| ttl | num | 1 | |
|
||||
| data | obj | 信息本体 | |
|
||||
|
||||
`data`对象:
|
||||
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| ---------- | ---- | ------------------------- | ---------- |
|
||||
| url | str | 二维码内容 (登录页面 url) | |
|
||||
| qrcode_key | str | 扫码登录秘钥 | 恒为32字符 |
|
||||
|
||||
**示例:**
|
||||
|
||||
`url`中的值生成二维码,等待手机客户端扫描,并将`qrcode_key`保存备用
|
||||
|
||||
```shell
|
||||
curl 'http://passport.bilibili.com/x/passport-login/web/qrcode/generate'
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "0",
|
||||
"ttl": 1,
|
||||
"data": {
|
||||
"url": "https://passport.bilibili.com/h5-app/passport/login/scan?navhide=1\u0026qrcode_key=8587cf8106a0b863c46d6bab913537f6\u0026from=",
|
||||
"qrcode_key": "8587cf8106a0b863c46d6bab913537f6"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### 扫码登录(web端)
|
||||
|
||||
> http://passport.bilibili.com/x/passport-login/web/qrcode/poll
|
||||
|
||||
*请求方式:GET*
|
||||
|
||||
密钥超时为180秒
|
||||
|
||||
验证登录成功后会进行设置以下cookie项:
|
||||
|
||||
`DedeUserID` `DedeUserID__ckMd5` `SESSDATA` `bili_jct`
|
||||
|
||||
**url参数:**
|
||||
|
||||
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
|
||||
| ---------- | ---- | ------------ | ------ | ---- |
|
||||
| qrcode_key | str | 扫码登录秘钥 | 非必要 | |
|
||||
|
||||
**json回复:**
|
||||
|
||||
根对象:
|
||||
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| ------- | ---- | -------- | ------- |
|
||||
| code | num | 返回值 | 0:成功 |
|
||||
| message | str | 错误信息 | |
|
||||
| data | obj | 信息本体 | |
|
||||
|
||||
data 对象:
|
||||
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| ------------- | ---- | ------------------------------------------------------------ | ---------------------------------- |
|
||||
| url | str | 游戏分站跨域登录 url | 未登录为空 |
|
||||
| refresh_token | str | 刷新`refresh_token` | 未登录为空 |
|
||||
| timestamp | num | 登录时间 | 未登录为`0`<br />时间戳 单位为毫秒 |
|
||||
| code | num | 0:扫码登录成功<br />86038:二维码已失效<br />86090:二维码已扫码未确认<br />86101:未扫码 | |
|
||||
| message | str | 扫码状态信息 | |
|
||||
|
||||
**示例:**
|
||||
|
||||
使用扫描秘钥`c3bd5286a2b40a822f5f60e9bf3f602e`登录
|
||||
|
||||
```shell
|
||||
curl -G "http://passport.bilibili.com/x/passport-login/web/qrcode/poll"\
|
||||
--data-urlencode 'qrcode_key=c3bd5286a2b40a822f5f60e9bf3f602e' \
|
||||
-c 'cookie.txt'
|
||||
```
|
||||
|
||||
当密钥正确时但未扫描时`message`为`86101`
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "0",
|
||||
"ttl": 1,
|
||||
"data": {
|
||||
"url": "",
|
||||
"refresh_token": "",
|
||||
"timestamp": 0,
|
||||
"code": 86101,
|
||||
"message": "未扫码"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
扫描成功但手机端未确认时`message`为`86038`
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "0",
|
||||
"ttl": 1,
|
||||
"data": {
|
||||
"url": "",
|
||||
"refresh_token": "",
|
||||
"timestamp": 0,
|
||||
"code": 86090,
|
||||
"message": "二维码已扫码未确认"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
扫描成功手机端确认登录后,`message`为`0`,并向浏览器写入cookie
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "0",
|
||||
"ttl": 1,
|
||||
"data": {
|
||||
"url": "https://passport.biligame.com/crossDomain?DedeUserID=***\u0026DedeUserID__ckMd5=***\u0026Expires=***\u0026SESSDATA=***\u0026bili_jct=***\u0026gourl=https%3A%2F%2Fpassport.bilibili.com",
|
||||
"refresh_token": "***",
|
||||
"timestamp": 1662363009601,
|
||||
"code": 0,
|
||||
"message": ""
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
**响应头部抓包信息:**
|
||||
|
||||
可明显看见设置了几个cookie
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```http
|
||||
HTTP/1.1 200 OK
|
||||
Date: Mon, 05 Sep 2022 07:30:09 GMT
|
||||
Expires: Mon, 05 Sep 2022 07:30:08 GMT
|
||||
Cache-control: no-cache
|
||||
Content-encoding: br
|
||||
Content-type: application/json; charset=utf-8
|
||||
bili-status-code: 0
|
||||
bili-trace-id: 0d23fe044a6315a5
|
||||
set-cookie: SESSDATA=***; Path=/; Domain=bilibili.com; Expires=Sat, 04 Mar 2023 07:30:09 GMT; HttpOnly; Secure
|
||||
set-cookie: bili_jct=***; Path=/; Domain=bilibili.com; Expires=Sat, 04 Mar 2023 07:30:09 GMT
|
||||
set-cookie: DedeUserID=***; Path=/; Domain=bilibili.com; Expires=Sat, 04 Mar 2023 07:30:09 GMT
|
||||
set-cookie: DedeUserID__ckMd5=***; Path=/; Domain=bilibili.com; Expires=Sat, 04 Mar 2023 07:30:09 GMT
|
||||
set-cookie: sid=***; Path=/; Domain=bilibili.com; Expires=Sat, 04 Mar 2023 07:30:09 GMT
|
||||
x-bili-trace-id: 2fbd8abd97dbd4db0d23fe044a6315a5
|
||||
x-cache-webcdn: BYPASS from blzone02
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## web端扫码登录-旧版
|
||||
|
||||
以下为旧版扫码登录api,尚可正常访问
|
||||
|
||||
### 申请二维码(web端-旧版)
|
||||
|
||||
> http://passport.bilibili.com/qrcode/getLoginUrl
|
||||
|
||||
@ -51,14 +261,14 @@ TV端流程&逻辑:
|
||||
|
||||
`data`对象:
|
||||
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| -------- | ---- | ------------- | ---------- |
|
||||
| url | str | 二维码内容url | 恒为87字符 |
|
||||
| oauthKey | str | 扫码登录秘钥 | 恒为32字符 |
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| -------- | ---- | ------------------------- | ---------- |
|
||||
| url | str | 二维码内容 (登录页面 url) | |
|
||||
| oauthKey | str | 扫码登录秘钥 | 恒为32字符 |
|
||||
|
||||
**示例:**
|
||||
|
||||
用申请到的`data`.`url`中的值生成二维码,等待手机客户端扫描,并将`data`.`oauthKey`保存等待使用
|
||||
`url`中的值生成二维码,等待手机客户端扫描,并将`oauthKey`保存备用
|
||||
|
||||
```shell
|
||||
curl 'http://passport.bilibili.com/qrcode/getLoginUrl'
|
||||
@ -67,6 +277,7 @@ curl 'http://passport.bilibili.com/qrcode/getLoginUrl'
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
@ -81,7 +292,7 @@ curl 'http://passport.bilibili.com/qrcode/getLoginUrl'
|
||||
|
||||
</details>
|
||||
|
||||
## 使用扫码登录(web端)
|
||||
### 扫码登录(web端-旧版)
|
||||
|
||||
> http://passport.bilibili.com/qrcode/getLoginInfo
|
||||
|
||||
@ -107,15 +318,16 @@ curl 'http://passport.bilibili.com/qrcode/getLoginUrl'
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| ------- | ---------------------------- | ----------------------------------------- | ------------------------------------------------------------ |
|
||||
| code | num | 返回值 | 0:成功 |
|
||||
| message | str | 错误信息 | 正确无 |
|
||||
| message | str | | 正确无 |
|
||||
| ts | num | 扫码时间 | 错误无 |
|
||||
| status | bool | 扫码是否成功 | true:成功<br />false:未成功 |
|
||||
| data | 正确时:obj<br />错误时:num | 正确时:游戏分站url<br />错误时:错误代码 | 未成功时:<br />-1:密钥错误<br />-2:密钥超时<br />-4:未扫描<br />-5:未确认 |
|
||||
|
||||
data 对象:
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| ---- | ---- | ------------------- | ---- |
|
||||
| url | str | 游戏分站跨域登录url | |
|
||||
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| ---- | ---- | -------------------- | ---- |
|
||||
| url | str | 游戏分站跨域登录 url | |
|
||||
|
||||
**示例:**
|
||||
|
||||
@ -127,11 +339,12 @@ curl "http://passport.bilibili.com/qrcode/getLoginInfo"\
|
||||
-c 'cookie.txt'
|
||||
```
|
||||
|
||||
当密钥正确时但未扫描时`status`为`false`,`data`为num值`-4`
|
||||
当密钥正确时但未扫描时`status`为`false`,`data`为`-4`
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"status":false,
|
||||
@ -142,11 +355,12 @@ curl "http://passport.bilibili.com/qrcode/getLoginInfo"\
|
||||
|
||||
</details>
|
||||
|
||||
扫描成功但手机端未确认时`status`为`false`,`data`为num值`-5`
|
||||
扫描成功但手机端未确认时`status`为`false`,`data`为`-5`
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"status":false,
|
||||
@ -162,6 +376,7 @@ curl "http://passport.bilibili.com/qrcode/getLoginInfo"\
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
@ -177,11 +392,12 @@ curl "http://passport.bilibili.com/qrcode/getLoginInfo"\
|
||||
|
||||
**响应头部抓包信息:**
|
||||
|
||||
可明显看见设置了几个cookie(填入浏览器即可成功登录)
|
||||
可明显看见设置了几个cookie
|
||||
|
||||
<details>
|
||||
<summary>查看响应示例:</summary>
|
||||
|
||||
|
||||
```http
|
||||
HTTP/1.1 200 OK
|
||||
Date: Wed, 04 Mar 2020 10:36:37 GMT
|
||||
@ -201,27 +417,11 @@ X-Cache-Webcdn: BYPASS from ks-sxhz-dx-w-01
|
||||
|
||||
</details>
|
||||
|
||||
**游戏分站跨域登录url:**
|
||||
## TV端扫码登录
|
||||
|
||||
游戏分站跨域登录url与cookie的值一一对应,可用于不方便设置cookie的场合提取使用
|
||||
### 申请二维码(TV端)
|
||||
|
||||
https://passport.biligame.com/crossDomain?
|
||||
|
||||
DedeUserID=(登录mid)&
|
||||
|
||||
DedeUserID__ckMd5=(登录mid MD5值)&
|
||||
|
||||
Expires=(过期时间 秒)&
|
||||
|
||||
SESSDATA=(登录token)&
|
||||
|
||||
bili_jct=(csrf)&
|
||||
|
||||
gourl=(跳转网址 默认为主页)
|
||||
|
||||
## 申请二维码URL及扫码密钥(TV端)
|
||||
|
||||
> http://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code
|
||||
> http://passport.snm0516.aisee.tv/x/passport-tv-login/qrcode/auth_code
|
||||
|
||||
*请求方式:POST*
|
||||
|
||||
@ -229,14 +429,14 @@ gourl=(跳转网址 默认为主页)
|
||||
|
||||
密钥超时为180秒
|
||||
|
||||
本接口可申请用于APP方式登录的`access_key`
|
||||
本接口可申请用于TV端APP方式登录的`access_key`
|
||||
|
||||
**正文参数( application/x-www-form-urlencoded ):**
|
||||
|
||||
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
|
||||
| -------- | ---- | ---------- | ----------- | ------------------------ |
|
||||
| appkey | str | APP密钥 | APP方式必要 | 仅可用`4409e2ce8ffd12b8` |
|
||||
| local_id | str | TV端id | TV端必要 | 可为0 |
|
||||
| local_id | str | TV端id | TV端必要 | 可为`0` |
|
||||
| ts | num | 当前时间戳 | APP方式必要 | |
|
||||
| sign | str | APP签名 | APP方式必要 | |
|
||||
|
||||
@ -255,13 +455,13 @@ gourl=(跳转网址 默认为主页)
|
||||
|
||||
| 字段 | 类型 | 内容 | 备注 |
|
||||
| -------- | ---- | ------------- | ---------- |
|
||||
| url | str | 二维码内容url | 恒为87字符 |
|
||||
| url | str | 二维码内容url | |
|
||||
| oauthKey | str | 扫码登录秘钥 | 恒为32字符 |
|
||||
|
||||
**示例:**
|
||||
|
||||
```shell
|
||||
curl 'http://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code' \
|
||||
curl 'http://passport.snm0516.aisee.tv/x/passport-tv-login/qrcode/auth_code' \
|
||||
--data-urlencode 'appkey=4409e2ce8ffd12b8' \
|
||||
--data-urlencode 'local_id=0' \
|
||||
--data-urlencode 'ts=0' \
|
||||
@ -277,7 +477,7 @@ curl 'http://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code' \
|
||||
"message": "0",
|
||||
"ttl": 1,
|
||||
"data": {
|
||||
"url": "https://passport.bilibili.com/x/passport-tv-login/h5/qrcode/auth?auth_code=0eeb635a64526709d70cb4c854a3b001",
|
||||
"url": "https://passport.snm0516.aisee.tv/x/passport-tv-login/h5/qrcode/auth?auth_code=0eeb635a64526709d70cb4c854a3b001",
|
||||
"auth_code": "0eeb635a64526709d70cb4c854a3b001"
|
||||
}
|
||||
}
|
||||
@ -285,9 +485,9 @@ curl 'http://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code' \
|
||||
|
||||
</details>
|
||||
|
||||
## 使用扫码登录(TV端)
|
||||
### 扫码登录(TV端)
|
||||
|
||||
> http://passport.bilibili.com/x/passport-tv-login/qrcode/poll
|
||||
> http://passport.snm0516.aisee.tv/x/passport-tv-login/qrcode/poll
|
||||
|
||||
*请求方式:POST*
|
||||
|
||||
@ -297,7 +497,7 @@ curl 'http://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code' \
|
||||
|
||||
验证登录成功后会返回可用于APP方式登录的`access_key`以及`refresh_token`
|
||||
|
||||
**正文参数( application/x-www-form-urlencoded ):**
|
||||
**正文参数 (application/x-www-form-urlencoded):**
|
||||
|
||||
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
|
||||
| --------- | ---- | ---------- | ----------- | ------------------------ |
|
||||
@ -332,7 +532,7 @@ curl 'http://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code' \
|
||||
使用扫描秘钥`6214464b3025541abf6f654cf7569a01`进行验证登录
|
||||
|
||||
```shell
|
||||
curl 'http://passport.bilibili.com/x/passport-tv-login/qrcode/poll' \
|
||||
curl 'http://passport.snm0516.aisee.tv/x/passport-tv-login/qrcode/poll' \
|
||||
--data-urlencode 'appkey=4409e2ce8ffd12b8' \
|
||||
--data-urlencode 'auth_code=6214464b3025541abf6f654cf7569a01' \
|
||||
--data-urlencode 'local_id=0' \
|
||||
@ -357,4 +557,4 @@ curl 'http://passport.bilibili.com/x/passport-tv-login/qrcode/poll' \
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user