2020-04-07 10:58:59 +08:00
|
|
|
|
# 私信
|
|
|
|
|
|
2020-11-20 20:13:12 +08:00
|
|
|
|
- [未读私信数](#未读私信数)
|
|
|
|
|
- [发送私信(web端)](#发送私信(web端))
|
|
|
|
|
|
|
|
|
|
---
|
2020-04-07 10:58:59 +08:00
|
|
|
|
|
|
|
|
|
## 未读私信数
|
|
|
|
|
|
|
|
|
|
> http://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread
|
|
|
|
|
|
2020-07-14 18:44:44 +08:00
|
|
|
|
*请求方式:GET*
|
2020-04-07 10:58:59 +08:00
|
|
|
|
|
2020-07-18 23:56:10 +08:00
|
|
|
|
认证方式:Cookie(SESSDATA)
|
|
|
|
|
|
2020-04-07 10:58:59 +08:00
|
|
|
|
**json回复:**
|
|
|
|
|
|
2020-04-16 18:47:19 +08:00
|
|
|
|
根对象:
|
|
|
|
|
|
2020-04-07 10:58:59 +08:00
|
|
|
|
| 字段 | 类型 | 内容 | 备注 |
|
|
|
|
|
| ------- | ---- | -------- | --------------------------- |
|
|
|
|
|
| code | num | 返回值 | 0:成功<br />-6:账号未登录 |
|
|
|
|
|
| message | str | 错误信息 | 默认为ok |
|
2020-07-27 23:49:37 +08:00
|
|
|
|
| ttl | num | 1 | |
|
2020-04-07 10:58:59 +08:00
|
|
|
|
| data | obj | 信息本体 | |
|
|
|
|
|
|
2020-07-23 15:33:20 +08:00
|
|
|
|
`data` 对象:
|
2020-04-07 10:58:59 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
| 字段 | 类型 | 内容 | 备注 |
|
|
|
|
|
| --------------- | ---- | -------------------- | ---- |
|
|
|
|
|
| unfollow_unread | num | 未关注用户未读私信数 | |
|
|
|
|
|
| follow_unread | num | 已关注用户未读私信数 | |
|
|
|
|
|
| _gt_ | num | 0 | |
|
2020-04-07 10:58:59 +08:00
|
|
|
|
|
2020-04-16 18:47:19 +08:00
|
|
|
|
**示例:**
|
2020-04-07 10:58:59 +08:00
|
|
|
|
|
2021-07-06 21:28:36 +08:00
|
|
|
|
以下信息代表了为未关注用户未读私信数为`1`条,已关注用户未读私信数为`6`条
|
2020-04-07 10:58:59 +08:00
|
|
|
|
|
2020-07-18 23:56:10 +08:00
|
|
|
|
```shell
|
2020-10-16 19:31:41 +08:00
|
|
|
|
curl 'http://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread' \
|
2020-07-18 23:56:10 +08:00
|
|
|
|
-b 'SESSDATA=xxx'
|
|
|
|
|
```
|
2020-04-07 10:58:59 +08:00
|
|
|
|
|
2020-08-31 16:37:38 +08:00
|
|
|
|
<details>
|
|
|
|
|
<summary>查看响应示例:</summary>
|
|
|
|
|
|
2020-04-07 10:58:59 +08:00
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"code": 0,
|
|
|
|
|
"msg": "ok",
|
|
|
|
|
"message": "ok",
|
|
|
|
|
"data": {
|
|
|
|
|
"unfollow_unread": 1,
|
|
|
|
|
"follow_unread": 6,
|
|
|
|
|
"_gt_": 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-08-31 16:37:38 +08:00
|
|
|
|
</details>
|
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
## 发送私信(web端)
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
|
|
|
|
> http://api.vc.bilibili.com/web_im/v1/web_im/send_msg
|
|
|
|
|
|
|
|
|
|
*请求方式:POST*
|
|
|
|
|
|
|
|
|
|
认证方式:Cookie(SESSDATA)
|
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
**正文参数(application/x-www-form-urlencoded):**
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2021-06-20 21:25:31 +08:00
|
|
|
|
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
|
2020-07-27 23:49:37 +08:00
|
|
|
|
| ------------------ | ------------------------------------ | ------------------------ | ------ | -------------------------------------- |
|
|
|
|
|
| msg[sender_uid] | num | 发送者UID | 必要 | |
|
|
|
|
|
| msg[receiver_id] | num | 接收者UID | 必要 | |
|
|
|
|
|
| msg[receiver_type] | num | 1 | 必要 | 固定为1 |
|
2021-06-20 21:25:31 +08:00
|
|
|
|
| msg[msg_type] | num | 消息类型 | 必要 | 1:发送文字<br>2:发送图片<br>5:撤回消息 |
|
2020-07-27 23:49:37 +08:00
|
|
|
|
| msg[msg_status] | num | 0 | 非必要 | |
|
2021-06-20 21:25:31 +08:00
|
|
|
|
| msg[dev_id] | string | 372778FD-E359-461D-86A3-EA2BCC6FF52A | 必要 | **获取方式在下面** |
|
|
|
|
|
| msg[timestamp] | num | 时间戳(秒) | 必要 | |
|
|
|
|
|
| msg[content] | 发送文字时:str<br />撤回消息时:num | 消息内容 | 必要 | **详见下表** |
|
2020-07-27 23:49:37 +08:00
|
|
|
|
| csrf_token | str | CSRF Token(位于cookie) | 必要 | |
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2021-06-20 21:25:31 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
**dev_id的获取**
|
|
|
|
|
|
|
|
|
|
以JS为例:
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
const deviceid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (function (name) {
|
|
|
|
|
let randomInt = 16 * Math.random() | 0;
|
|
|
|
|
return ("x" === name ? randomInt : 3 & randomInt | 8).toString(16).toUpperCase()
|
|
|
|
|
}));
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
代码来自 [andywang425/BLTH](https://github.com/andywang425/BLTH/blob/45fe93e31754ca8bf07059d46266398e787dbf45/B%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B.js#L6618)
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
`msg[content]`消息内容:
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
当发送文字时(`msg[msg_type]=1`):
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
该参数为json序列字串
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
根对象:
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
| 字段 | 类型 | 内容 | 备注 |
|
|
|
|
|
| ------- | ---- | -------- | ---- |
|
|
|
|
|
| content | str | 私信内容 | |
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
当发送图片时(`msg[msg_type]=2`):
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
该参数为json序列字串
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
根对象:
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
| 字段 | 类型 | 内容 | 备注 |
|
|
|
|
|
| -------- | ---- | -------- | :-------------------------------------------- |
|
|
|
|
|
| url | str | 图片url | 默认为B站相簿图片上传通道<br />也可用三方图床 |
|
|
|
|
|
| width | num | 图片的宽 | 单位:像素(非必要) |
|
|
|
|
|
| height | num | 图片的高 | 单位:像素(非必要) |
|
|
|
|
|
| type | str | 图片格式 | (非必要) |
|
|
|
|
|
| original | num | 1 | **作用未知**(非必要) |
|
|
|
|
|
| size | num | 文件大小 | 单位:千字节(非必要)<br>__向上取整__ |
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
当撤回消息时(`msg[msg_type]=5`):
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
该参数为数值,为目标消息的` msg_key `
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
|
|
|
|
**json回复:**
|
|
|
|
|
|
|
|
|
|
根对象:
|
|
|
|
|
| 字段 | 类型 | 内容 | 备注 |
|
|
|
|
|
| ------- | ---- | -------- | ----------- |
|
|
|
|
|
| code | num | 返回值 | 0:成功<br> |
|
|
|
|
|
| message | str | 错误信息 | 默认为ok |
|
|
|
|
|
| msg | str | 错误信息 | 默认为ok |
|
|
|
|
|
| data | obj | 主体 | 出错时为空 |
|
|
|
|
|
|
|
|
|
|
`data`对象:
|
|
|
|
|
|
|
|
|
|
| 字段 | 类型 | 内容 | 备注 |
|
|
|
|
|
| ------- | ---- | ---- | ------------ |
|
|
|
|
|
| msg_key | num | | 作用尚不明确 |
|
|
|
|
|
| \_gt\_ | num | 0 | 作用尚不明确 |
|
|
|
|
|
|
|
|
|
|
**示例:**
|
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
给目标用户`UID=1`发一条文字私信:
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
|
|
|
|
> up主你好,
|
|
|
|
|
>
|
2020-07-27 23:49:37 +08:00
|
|
|
|
> 催更[doge]
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
|
|
|
|
```shell
|
2020-10-16 19:31:41 +08:00
|
|
|
|
curl 'http://api.vc.bilibili.com/web_im/v1/web_im/send_msg' \
|
|
|
|
|
--data-urlencode 'msg[sender_uid]=293793435' \
|
|
|
|
|
--data-urlencode 'msg[receiver_id]=1' \
|
|
|
|
|
--data-urlencode 'msg[receiver_type] =1' \
|
|
|
|
|
--data-urlencode 'msg[msg_type]=1' \
|
|
|
|
|
--data-urlencode 'msg[content]={"content":"up主你好,\n催更[doge]"}' \
|
|
|
|
|
--data-urlencode 'csrf_token=xxx' \
|
2020-07-27 23:49:37 +08:00
|
|
|
|
-b 'SESSDATA=xxx'
|
2020-07-23 15:33:20 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-08-31 16:37:38 +08:00
|
|
|
|
<details>
|
|
|
|
|
<summary>查看响应示例:</summary>
|
|
|
|
|
|
2020-07-23 15:33:20 +08:00
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"code":0,
|
|
|
|
|
"msg":"ok",
|
|
|
|
|
"message":"ok",
|
|
|
|
|
"data":{
|
2020-07-23 15:37:42 +08:00
|
|
|
|
"msg_key":6852559688104417870,
|
|
|
|
|
"_gt_":0
|
2020-07-23 15:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-08-31 16:37:38 +08:00
|
|
|
|
</details>
|
|
|
|
|
|
2020-07-27 23:49:37 +08:00
|
|
|
|
给目标用户`UID=1`发一条图片私信:
|
2020-07-23 15:33:20 +08:00
|
|
|
|
|
|
|
|
|
> <img src="https://i1.hdslb.com/bfs/face/aebb2639a0d47f2ce1fec0631f412eaf53d4a0be.jpg" style="zoom:50%;" >
|
|
|
|
|
|
|
|
|
|
```shell
|
2020-10-16 19:31:41 +08:00
|
|
|
|
curl 'http://api.vc.bilibili.com/web_im/v1/web_im/send_msg' \
|
|
|
|
|
--data-urlencode 'msg[sender_uid]=293793435' \
|
|
|
|
|
--data-urlencode 'msg[receiver_id]=1' \
|
|
|
|
|
--data-urlencode 'msg[receiver_type] =1' \
|
|
|
|
|
--data-urlencode 'msg[msg_type]=2' \
|
|
|
|
|
--data-urlencode 'msg[content]={"url":https://i1.hdslb.com/bfs/face/aebb2639a0d47f2ce1fec0631f412eaf53d4a0be.jpg}' \
|
|
|
|
|
--data-urlencode 'csrf_token=xxx' \
|
2020-07-27 23:49:37 +08:00
|
|
|
|
-b 'SESSDATA=xxx'
|
2020-07-23 15:33:20 +08:00
|
|
|
|
```
|
|
|
|
|
|
2020-08-31 16:37:38 +08:00
|
|
|
|
<details>
|
|
|
|
|
<summary>查看响应示例:</summary>
|
|
|
|
|
|
2020-07-23 15:33:20 +08:00
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"code":0,
|
|
|
|
|
"msg":"ok",
|
|
|
|
|
"message":"ok",
|
|
|
|
|
"data":{
|
|
|
|
|
"msg_key":6852570013146024354,
|
|
|
|
|
"_gt_":0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-08-31 16:37:38 +08:00
|
|
|
|
</details>
|