feat: get buvid3 b_nut from response header

This commit is contained in:
SessionHu 2024-07-26 15:22:32 +08:00
parent b3c3fce164
commit fa6c9c8f57
No known key found for this signature in database
GPG Key ID: 9E7E64C25FE3301A
2 changed files with 39 additions and 2 deletions

View File

@ -73,7 +73,7 @@ B站 API 采用 C/S 结构,大多数接口为 REST API 和 gRPC少部分接
- [x] [图片格式化](docs/misc/picture.md)
- [x] [bvid 说明](docs/misc/bvid_desc.md)
- [ ] [设备唯一标识BUVID](docs/misc/device_identity.md)
- [ ] [获取 buvid3 / buvid4](docs/misc/buvid3_4.md)
- [ ] [获取 buvid3 / buvid4 / b_nut](docs/misc/buvid3_4.md)
- [ ] [gRPC API 接口定义](grpc_api)
- [ ] [登录](docs/login)
- [x] [登录操作 (人机认证)](docs/login/login_action)

View File

@ -1,4 +1,4 @@
# 获取 buvid3 / buvid4
# 获取 buvid3 / buvid4 / b_nut
## 游客获取 buvid3 / buvid4
@ -46,3 +46,40 @@ curl -G 'https://api.bilibili.com/x/frontend/finger/spi'
```
</details>
## 从响应头获取 buvid3 / b_nut
使用 `GET``HEAD` 方法请求 `https://www.bilibili.com/`, 且请求头中 `User-Agent` 字段不包含 `curl` `python` `awa` 等敏感子字符串, 且相同 `User-Agent` 字段不得短时多次请求. 在响应头中的 `Set-Cookie` 字段中, 即可找到 `buvid3``b_nut`.
若不带任何 Cookie 请求, 则 `b_nut` 为响应生成时刻的 UNIX 秒级时间戳.
若请求 Cookie 仅带有 `buvid3`, 则 `b_nut``100`.
若请求 Cookie 仅带有 `b_nut`, 则与不带任何 Cookie 的响应相同.
若请求 Cookie 仅带有 `buvid3``b_nut`, 则响应无 `Set-Cookie` 字段.
若请求 Cookie 带有其他字段, 无影响.
**示例:**
```shell
curl -I "https://www.bilibili.com/" -A "awa"
```
<details>
<summary>查看响应示例:</summary>
```http
HTTP/2 200
date: Fri, 26 Jul 2024 06:38:43 GMT
content-type: text/html; charset=utf-8
support: nantianmen
set-cookie: buvid3=805E4894-96A2-0684-6F00-C6EA1FFB911023315infoc; path=/; expires=Sat, 26 Jul 2025 06:38:43 GMT; domain=.bilibili.com
set-cookie: b_nut=1721975923; path=/; expires=Sat, 26 Jul 2025 06:38:43 GMT; domain=.bilibili.com
vary: Origin,Accept-Encoding
idc: shjd
expires: Fri, 26 Jul 2024 06:38:42 GMT
cache-control: no-cache
x-cache-webcdn: MISS from blzone01
x-cache-time: 0
x-save-date: Fri, 26 Jul 2024 06:38:43 GMT
```
</details>