1 Star 0 Fork 10

chestnut / 歪fChat桌面端后端

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
接口文档.md 54.62 KB
一键复制 编辑 原始数据 按行查看 历史
lantianyu 提交于 2023-12-04 23:17 . update

接口文档

baseUrl: http://127.0.0.1:7878

1. 注册接口

  • 请求url:/register
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
phone String 手机号
password String 密码
nick String 昵称
  • 返回值

注册成功返回

{
  status: 200,
  msg: '注册成功',
  data: {
      token,
      _id,
      phone,
      nick,
      imgUrl,
      sex,
      birthday,
      start,
      sign
  }
}

该用户已注册

{
  status: 400,
	msg: '该用户已注册'
}

服务器错误

{
  status: 404,
	msg: '注册失败'	
}

参数缺省

{
    "status": 405,
    "msg": "参数错误",
    "data": [
        {
            "type": "field",
            "msg": "手机号不合法",
            "path": "phone",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "手机号不能为空",
            "path": "phone",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "密码不能为空",
            "path": "password",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "昵称不能为空",
            "path": "nick",
            "location": "body"
        }
    ]
}

2. 登陆接口

  • 请求url:/login
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
phone String 手机号
password String 密码
  • 返回值

登陆成功

{
  status: 200,
  msg: '登录成功',
  data: {
      token,
      _id,
      phone,
      nick,
      imgUrl,
      sex,
      birthday,
      start,
      sign
  }
}

该用户不存在

{
  status: 400,
	msg: '该用户不存在'
}

密码错误

{
  status: 401,
	msg: '密码错误'
}

服务器错误

{
  status: 404,
	msg: '登录失败'
}

3. 获取用户主页信息接口

  • 请求url:/home/user

  • 请求方式:get

  • 请求参数:

参数名 类型 是否必填 描述
_id String 用户id(自己的)
urlId String 用户主页id
  • 返回值

friendState

  1. friendState = 0,好友申请中(发送方)
  2. friendState = 1,已添加好友
  3. friendState = 2,未添加好友
  4. friendState = 3,用户自己主页
  5. friendState = 4,申请方(接收方)

示例代码

{
  status: 200,
	data: {
      user,
      friendState: 0
  }
}

服务器错误 加载失败

{
  status: 404,
	msg: '加载失败'
}

4. message列表页顶部用户头像和昵称

  • 请求url:/tabbar/message/userinfo
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
_id String 用户id(自己的)
  • 返回值

success

{
    "status": 200,
    "data": {
        "_id": "64eec06fa61f50ab31295296",
        "nick": "wifi歪f",
        "imgUrl": "/user_pic1.jpeg"
    }
}

error

{
  status: 404,
	data: '服务器错误'
}

5. 用户头像上传接口

  • 请求url:/upload/user
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
file File 文件对象(name名: file)
_id String 用户id(自己的)
  • 返回值

success

{
  res_code: 0,
  name: 文件名,
  url: 文件路径
}

error

{
  res_code: 404,
  msg: '服务器错误'
}

6. 更新用户信息接口

  • 请求url:/update/user
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
_id String 用户id(自己的)
nick String 昵称
sex String 性别
birthday String 密码(xxxx-xx-xx)
sign String 个性签名
imgUrl String 头像图片
  • 返回值

success

{
  status: 200,
  msg: '保存成功',
  start
}

error

{
  status: 404,
  msg: '保存失败'
}

参数缺省

{
    "status": 405,
    "msg": "参数错误",
    "data": [
        {
            "type": "field",
            "msg": "_id参数不能为空",
            "path": "_id",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "昵称不能为空",
            "path": "nick",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "性别不能为空",
            "path": "sex",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "性别必须为未知/男/女",
            "path": "sex",
            "location": "body"
        }
    ]
}

7. 搜索好友/群接口

  • 请求url:/search
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
keyword String 关键字
  • 返回值

关键字空

{
    status: 400,
    msg: '关键字为空, 暂无数据',
    data: [],
    result: false
}

暂无数据

{
    status: 400,
    msg: '暂无数据',
    result: false
}

服务器错误

{
    status: 404,
    msg: '服务器错误'
    result: false
}

success

{
    "status": 200,
    "data": {
        "friendList": [
            {
                "_id": "64eec06fa61f50ab31295296",
                "nick": "wifi歪f",
                "imgUrl": "/user_pic1.jpeg",
                "sign": "能失去的从来不属于我"
            }
        ],
        "groupList": [
            {
                "_id": "65552471a63c59f4e6755e44",
                "groupName": "wifi群",
                "imgUrl": "/group_pic.png"
            }
        ]
    }
}

8. 发送好友申请

  • 请求url:/friend/add
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
friendId String 好友id(对方的)
  • 返回值

参数缺省

{
    "status": 405,
    "msg": "参数错误",
    "data": [
        {
            "type": "field",
            "msg": "userId参数不能为空",
            "path": "userId",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "friendId参数不能为空",
            "path": "friendId",
            "location": "body"
        }
    ]
}

success

{
  status: 200,
  msg: '申请中'
}

error

{
    status: 404,
    msg: '申请失败,请重试'
}

9. 联系人页面展示好友列表

只返回好友状态state为1的 => 已为好友

  • 请求url:/contacts/friend
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
  • 返回值

success

{
    "status": 200,
    "data": [
        {
            "_id": "65623e9fde6678fd1d5a0061",
            "userId": "64eec06fa61f50ab31295296",
            "friendId": {
                "_id": "65151e1dcf14fef88682e039",
                "nick": "ces4",
                "imgUrl": "/user_pic1.jpeg",
                "sign": "这个人很高冷, 暂时没有留下什么"
            },
            "time": "2023-11-25T18:36:15.748Z",
            "state": 1,
            "__v": 0
        },
        {
            "_id": "65623ec9de6678fd1d5a008e",
            "userId": "64eec06fa61f50ab31295296",
            "friendId": {
                "_id": "65151e2ccf14fef88682e03c",
                "nick": "ces5",
                "imgUrl": "/user_pic1.jpeg",
                "sign": "这个人很高冷, 暂时没有留下什么"
            },
            "time": "2023-11-25T18:36:57.664Z",
            "state": 1,
            "__v": 0
        },
        {
            "_id": "65624244de6678fd1d5a02d9",
            "userId": "64eec06fa61f50ab31295296",
            "friendId": {
                "_id": "64fb10adad117203367263fb",
                "nick": "臭粑卡皮巴拉",
                "imgUrl": "/user2.png",
                "sign": "这个人很高冷, 暂时没有留下什么"
            },
            "time": "2023-11-25T18:51:48.855Z",
            "state": 1,
            "__v": 0
        }
    ]
}

error

{
  status: 404,
  msg: '请求失败'
}

10. 删除好友

  • 请求url:/del/friend
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
friendId String 好友id(对方的)
  • 返回值

success

{
  status: 200,
  msg: '删除成功'
}

error

{
  status: 404,
  msg: '删除失败'
}

11. 获取到当前未同意的好友申请列表

  • 请求url:/get/friend/noagree
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
  • 返回值

success

{
    "status": 200,
    "data": [
        {
            "_id": "656d9c576a6427f7d143529e",
            "userId": "64eec06fa61f50ab31295296",
            "friendId": {
                "_id": "64fb10adad117203367263fb",
                "nick": "臭粑卡皮巴拉",
                "imgUrl": "/user2.png"
            },
            "time": "2023-12-04T09:31:03.791Z",
            "state": 0,
            "__v": 0
        }
    ]
}

error

{
  status: 404,
  msg: '服务器错误'
}

12. 同意好友申请接口

  • 请求url:/friend/agree
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
friendId String 好友id(对方的)
  • 返回值

参数缺省

{
    "status": 405,
    "msg": "参数错误",
    "data": [
        {
            "type": "field",
            "msg": "userId参数不能为空",
            "path": "userId",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "friendId参数不能为空",
            "path": "friendId",
            "location": "body"
        }
    ]
}

success

{
  status: 200,
  msg: '添加成功'
}

error

{
  status: 404,
  msg: '添加失败'
}

13. 拒绝好友申请接口

  • 请求url:/friend/refuse
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
friendId String 好友id(对方的)
  • 返回值

参数缺省

{
    "status": 405,
    "msg": "参数错误",
    "data": [
        {
            "type": "field",
            "msg": "userId参数不能为空",
            "path": "userId",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "friendId参数不能为空",
            "path": "friendId",
            "location": "body"
        }
    ]
}

success

{
  status: 200,
  msg: '已拒绝'
}

error

{
  status: 404,
  msg: '服务器错误'
}

14. 新建群聊接口

  • 请求url:/create/group
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
groupName String 群名
sign String 群简介
imgUrl String 群头像(url地址)
  • 返回值

参数缺省

{
    "status": 405,
    "msg": "参数错误",
    "data": [
        {
            "type": "field",
            "msg": "userId参数不能为空",
            "path": "userId",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "群名不能为空",
            "path": "groupName",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "群简介不能为空",
            "path": "sign",
            "location": "body"
        }
    ]
}

success

{
  status: 200,
  msg: '创建成功'
}

error

{
  status: 404,
  msg: '创建失败'
}

15. 群头像上传接口

  • 请求url:/upload/group
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
file File 文件对象(name:file)
  • 返回值

success

{
  res_code: 0,
  name: 文件名,
  url: 文件路径
}

16. 获取群主页信息接口

  • 请求url:/home/group
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
groupId String 群id
userId String 用户id(自己的)
  • 返回值

success

{
    "status": 200,
    "data": {
        "group": {
            "_id": "65552471a63c59f4e6755e44",
            "userId": "64eec06fa61f50ab31295296",
            "groupName": "wifi群",
            "groupNumber": 1700078705941,
            "sign": "test",
            "imgUrl": "/group_pic.png",
            "creatTime": "2023年11月16日",
            "__v": 0
        },
        "groupUser": [
            {
                "_id": "65552471a63c59f4e6755e46",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg",
                    "sex": "男",
                    "birthday": "2003-06-26"
                },
                "state": 1,
                "__v": 0
            },
            {
                "_id": "65562496c99b878403209080",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png",
                    "sex": "男",
                    "birthday": "2003-06-26"
                },
                "time": "2023-11-16T14:17:58.333Z",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "65623ecbde6678fd1d5a009c",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "65151e2ccf14fef88682e03c",
                    "nick": "ces5",
                    "imgUrl": "/user_pic1.jpeg",
                    "sex": "未知",
                    "birthday": ""
                },
                "time": "2023-11-25T18:36:59.533Z",
                "state": 1,
                "__v": 0
            }
        ],
        "statis": {
            "maleNum": 2,
            "femaleNum": 0,
            "is00sBornNum": 2
        }
    },
    "state": 1
}

state:0 => 群聊申请中

state:1 => 已经加入该群

state:2 => 未加入该群

error

{
  status: 404,
  data: '服务器错误'
}

17. 获取群成员接口

  • 请求url:/get/groupUser
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
groupId String 群id
  • 返回值

success

{
    "status": 200,
    "data": {
        "groupUser": [
            {
                "_id": "65552471a63c59f4e6755e46",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "state": 1,
                "__v": 0
            },
            {
                "_id": "65562496c99b878403209080",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "time": "2023-11-16T14:17:58.333Z",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "65623ecbde6678fd1d5a009c",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "65151e2ccf14fef88682e03c",
                    "nick": "ces5",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "time": "2023-11-25T18:36:59.533Z",
                "state": 1,
                "__v": 0
            }
        ],
        "groupCreateUserId": "64eec06fa61f50ab31295296"
    }
}

error

{
  status: 404,
  msg: '服务器错误'
}

18. 加入群聊(发送入群申请)接口

  • 请求url:/login
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
groupId String 群id
userId String 用户id(自己的)
  • 返回值

参数缺省

{
    "status": 405,
    "msg": "参数错误",
    "data": [
        {
            "type": "field",
            "msg": "groupId参数不能为空",
            "path": "groupId",
            "location": "body"
        },
        {
            "type": "field",
            "msg": "userId参数不能为空",
            "path": "userId",
            "location": "body"
        }
    ]
}

success

{
  status: 200,
  msg: '已发送'
}

error

{
  status: 404,
  msg: '申请失败'
}

19. 拒绝入群申请接口

  • 请求url:/group/refuse
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
phone String 手机号
password String 密码
  • 返回值

success

{
  status: 200,
  msg: '已拒绝'
}

error

{
  status: 404,
  msg: '服务器错误'
}

20. 联系人页面展示群列表接口

  • 请求url:/contacts/group
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id(自己的)
  • 返回值

success

{
    "status": 200,
    "data": [
        {
            "_id": "65552471a63c59f4e6755e46",
            "groupId": {
                "_id": "65552471a63c59f4e6755e44",
                "groupName": "wifi群",
                "imgUrl": "/group_pic.png"
            },
            "userId": "64eec06fa61f50ab31295296",
            "state": 1,
            "__v": 0
        },
        {
            "_id": "655a4bfac4c28d775a763a0e",
            "groupId": {
                "_id": "655a4bfac4c28d775a763a0c",
                "groupName": "group2",
                "imgUrl": "/group_pic.png"
            },
            "userId": "64eec06fa61f50ab31295296",
            "state": 1,
            "__v": 0
        },
        {
            "_id": "655e945ef968f563f1ec6b2e",
            "groupId": {
                "_id": "655e945ef968f563f1ec6b2c",
                "groupName": "1",
                "imgUrl": "/group_pic.png"
            },
            "userId": "64eec06fa61f50ab31295296",
            "state": 1,
            "__v": 0
        }
    ]
}

error

{
  status: 404,
  msg: '请求失败'
}

21. 获取当前需要修改的群信息接口

  • 请求url:/get/update/group
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
groupId String 群id
groupLeaderId String 群主id
  • 返回值

success

{
    "status": 200,
    "data": {
        "groupInfo": {
            "_id": "65552471a63c59f4e6755e44",
            "groupName": "wifi群",
            "sign": "test",
            "imgUrl": "/group_pic.png"
        },
        "groupUserList": [
            {
                "_id": "65562496c99b878403209080",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "time": "2023-11-16T14:17:58.333Z",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "65623ecbde6678fd1d5a009c",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "65151e2ccf14fef88682e03c",
                    "nick": "ces5",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "time": "2023-11-25T18:36:59.533Z",
                "state": 1,
                "__v": 0
            }
        ]
    }
}

error

{
  status: 404,
  msg: '服务器错误'
}

22. 修改群聊信息接口

  • 请求url:/update/groupInfo
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
_id String 群id
groupName String 群名
sign String 群简介
imgUrl String 群头像
  • 返回值

success

{
  status: 200,
  msg: '修改成功'
}

error

{
  status: 404,
  msg: '修改失败'
}

23. 删除群成员接口

  • 请求url:/del/groupUser
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
groupId String 群id
  • 返回值

success

{
  status: 200,
  msg: '已退出'
}

error

{
  status: 404,
  msg: '移除失败'
}

24. 退出群聊(分为群主退群和群成员退群)

1、群主退群(解散该群)

2、群成员退群(删除该成员) => 用上面的 No.23/del/groupUser 这个接口

  • 请求url:/del/group
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
groupId String 群id
  • 返回值

success

{
  status: 200,
  msg: '已解散'
}

error

{
  status: 404,
  msg: 'error'
}

25. 获取群申请通知列表接口

  • 请求url:/get/group/noagree
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
  • 返回值

success

{
    "status": 200,
    "data": [
        {
            "_id": "656dac826a6427f7d1435313",
            "groupId": {
                "_id": "65552471a63c59f4e6755e44",
                "groupName": "wifi群",
                "imgUrl": "/group_pic.png"
            },
            "userId": {
                "_id": "64fb10adad117203367263fb",
                "nick": "臭粑卡皮巴拉",
                "imgUrl": "/user2.png"
            },
            "time": "2023-12-04T10:40:02.156Z",
            "__v": 0
        }
    ]
}

error

{
  status: 404,
  data: '服务器错误'
}

26. 同意入群申请接口

  • 请求url:/group/agree
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
groupId String 群id
  • 返回值

success

{
  status: 200,
  msg: '添加成功'
}

error

{
  status: 404,
  msg: '添加失败'
}

27. 空间动态图片上传接口(多文件)

  • 请求url:/space/upload/photos
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
File File 文件对象,最多可以上传9张图片,后端没有作文件类型校验,请前端处理(name:photos)
  • 返回值

success

{ res_code: 200, url: 文件url }

error

{ res_code: 500, msg: 'error' }

28. 空间动态发布接口

  • 请求url:/space/add
  • 请求方式:post
  • 请求参数:

textDesc 和 photos有一个不能为空

参数名 类型 是否必填 描述
userId String 用户id
textDesc String 动态文字信息
photos File 照片url(传入数组对象,请使用JSON.stringify转为字符串
  • 返回值

success

{
  status: 200,
  msg: '发布成功'
}

error

{
  status: 404,
  msg: '发布失败'
}

29. 获取空间动态列表

  • 请求url:/space/get
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
  • 返回值

success

{
    "status": 200,
    "data": [
        {
            "_id": "656235cb6e8c66289e155057",
            "userId": {
                "_id": "64fb10adad117203367263fb",
                "nick": "臭粑卡皮巴拉",
                "imgUrl": "/user2.png"
            },
            "textDesc": "WebRTC 的诞生,就是基于浏览器的多媒体即时通信,对于在 Web 端实现会议这个需求而言,它简直天生自带光环。而且 WebRTC 能够实现:实时双向音视频、主流浏览器支持、开发者容易入手、使用范围广且技术开源成熟等条件,且具有毫秒级的延迟特性。",
            "photos": [
                "/1700935111845-fan.jpg"
            ],
            "time": "2023-11-26 1:58",
            "isLike": false,
            "likeList": [],
            "commentList": [],
            "replyList": []
        },
        {
            "_id": "656235a26e8c66289e155037",
            "userId": {
                "_id": "64fb10adad117203367263fb",
                "nick": "臭粑卡皮巴拉",
                "imgUrl": "/user2.png"
            },
            "textDesc": "测试",
            "photos": [
                "/1700935073298-黄鼠狼.jpg"
            ],
            "time": "2023-11-26 1:57",
            "isLike": false,
            "likeList": [],
            "commentList": [],
            "replyList": []
        },
        {
            "_id": "650026f0ad11720336726630",
            "userId": {
                "_id": "64fb10adad117203367263fb",
                "nick": "臭粑卡皮巴拉",
                "imgUrl": "/user2.png"
            },
            "textDesc": "过去的回忆",
            "photos": [
                "/1694508782089-he.jpeg",
                "/1694508782092-me.jpeg"
            ],
            "time": "2023-9-12 16:53",
            "isLike": false,
            "likeList": [],
            "commentList": [
                {
                    "_id": "6505e73a6406b9caf54f9233",
                    "userId": {
                        "_id": "64fb10adad117203367263fb",
                        "nick": "臭粑卡皮巴拉",
                        "imgUrl": "/user2.png"
                    },
                    "spaceId": "650026f0ad11720336726630",
                    "type": 0,
                    "textarea": "lovefan",
                    "fromId": "64fb10adad117203367263fb",
                    "toId": "64fb10adad117203367263fb",
                    "time": "2023-9-17 1:34",
                    "__v": 0
                },
                {
                    "_id": "6505ef786406b9caf54f957d",
                    "userId": {
                        "_id": "64fb10adad117203367263fb",
                        "nick": "臭粑卡皮巴拉",
                        "imgUrl": "/user2.png"
                    },
                    "spaceId": "650026f0ad11720336726630",
                    "type": 0,
                    "textarea": "想你了",
                    "fromId": "64fb10adad117203367263fb",
                    "toId": "64fb10adad117203367263fb",
                    "time": "2023-9-17 2:10",
                    "__v": 0
                }
            ],
            "replyList": [
                [],
                [
                    {
                        "_id": "6505f0246406b9caf54f9716",
                        "userId": {
                            "_id": "64eec06fa61f50ab31295296",
                            "nick": "wifi歪f",
                            "imgUrl": "/user_pic1.jpeg"
                        },
                        "spaceId": "650026f0ad11720336726630",
                        "spaceCommentId": "6505ef786406b9caf54f957d",
                        "type": 1,
                        "textarea": "xxx",
                        "fromId": {
                            "_id": "64eec06fa61f50ab31295296",
                            "nick": "wifi歪f",
                            "imgUrl": "/user_pic1.jpeg"
                        },
                        "toId": {
                            "_id": "64fb10adad117203367263fb",
                            "nick": "臭粑卡皮巴拉",
                            "imgUrl": "/user2.png"
                        },
                        "time": "2023-9-17 2:12",
                        "__v": 0
                    }
                ]
            ]
        }
    ]
}

error

{
  status: 404,
  msg: '服务器错误'
}

30. 删除动态接口

  • 请求url:/space/del
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
_id String 该条动态id
  • 返回值

success

{
  status: 200,
  msg: '删除成功'
}

error

{
  status: 404,
  msg: '删除失败'
}

31. 用户空间详情接口

  • 请求url:/space/details
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
  • 返回值

success

{
    "status": 200,
    "data": {
        "spaces": [
            {
                "_id": "656242bdde6678fd1d5a046c",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "textDesc": "123",
                "photos": [
                    "/1700938428030-fan.jpg"
                ],
                "time": "2023-11-26 2:53",
                "__v": 0
            }
        ],
        "user": {
            "_id": "64eec06fa61f50ab31295296",
            "WaiFCode": "WaiFCode_15583251761",
            "nick": "wifi歪f",
            "imgUrl": "/user_pic1.jpeg"
        }
    }
}

error

{
  status: 404,
  msg: 'error'
}

32. 空间动态点赞

  • 请求url:/space/like
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
spaceId String 动态id
userId String 用户id
  • 返回值

success

{
  status: 200,
  msg: 'success'
}

error

{
  status: 404,
  msg: '服务器错误'
}

33. 动态评论接口(评论, 回复)

  • 请求url:/space/comment/add/:type
  • 请求方式:post
  • 请求参数:

评论类型(0 => 自己评论, 1 => 回复评论)

body:
参数名 类型 是否必填 描述
userId String 用户id
spaceId String 空间动态id
textarea String 评论文字内容
fromId String 发送方id(主动发评论的人)
toId String 回复者id(收到评论的人),如果 type 为0, fromId 和 toId 都是用户自己
spaceCommentId String 要回复评论的那条id
params:
参数名 类型 是否必填 描述
type Number 评论类型(0 => 自己评论, 1 => 回复评论)
  • 返回值

success

{
  status: 200,
  msg: 'success'
}

error

{
  status: 404,
  msg: 'error'
}

34. 评论删除接口

  • 请求url:/space/comment/del/:type
  • 请求方式:get
  • 请求参数:
query:
参数名 类型 是否必填 描述
_id String 动态id
type:
参数名 类型 是否必填 描述
type String 评论类型(0 => 自己评论, 1 => 回复评论
  • 返回值

success

{
  status: 200,
  msg: '删除成功'
}

error

{
  status: 404,
  msg: '服务器错误'
}

35. 删除动态接口

  • 请求url:/space/del
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
_id String 动态id
  • 返回值

success

{
  status: 200,
  msg: '删除成功'
}

error

{
  status: 404,
  msg: '删除失败'
}

36. 获取当前聊天好友的信息

  • 请求url:/message/friend
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
friendId String 好友id
pageNum Number 页数(聊天记录采取分页查询的方式,每页20条数据)
  • 返回值

与该用户还不是好友

{
  status: 202,
  data: {
    "friendNick": {
        "_id": "64eec06fa61f50ab31295296",
        "nick": "wifi歪f"
    }
  },
  msg: '您与ta还不是好友哦'
}

暂无更多

{
    "status": 201,
    "data": {
        "_id": "64eec06fa61f50ab31295296",
        "nick": "wifi歪f"
    },
    "msg": "暂无更多"
}

success

{
    "status": 200,
    "data": {
        "friendNick": {
            "_id": "64eec06fa61f50ab31295296",
            "nick": "wifi歪f"
        },
        "messageList": [
            {
                "_id": "65669a890b61d69dd01c256a",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "friendId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "message": "# Hello 歪fChat Editor",
                "msgType": 5,
                "time": "Wed Nov 29 2023 09:57:29 GMT+0800 (中国标准时间)",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "65669a900b61d69dd01c256d",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "friendId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "message": "{\"fileName\":\"index.js\",\"size\":1192,\"fileSuffixName\":\"js\",\"url\":\"/adc960a0c14c9a143ca0266005633c53.js\"}",
                "msgType": 3,
                "time": "Wed Nov 29 2023 09:57:36 GMT+0800 (中国标准时间)",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "65669a979a2f15e8b4a0a4ff",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "friendId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "message": "{\"url\":\"/1701223063717-fan.jpg\",\"height\":110.92592592592594}",
                "msgType": 1,
                "time": "Wed Nov 29 2023 09:57:43 GMT+0800 (中国标准时间)",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "6566a2029a2f15e8b4a0a5e0",
                "userId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "friendId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "message": "Hh",
                "msgType": 0,
                "time": "Wed Nov 29 2023 10:29:22 GMT+0800 (中国标准时间)",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "6566a20a9a2f15e8b4a0a5eb",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "friendId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "message": "a",
                "msgType": 0,
                "time": "Wed Nov 29 2023 10:29:30 GMT+0800 (中国标准时间)",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "6566a2bd9a2f15e8b4a0a630",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "friendId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "message": "12",
                "msgType": 0,
                "time": "Wed Nov 29 2023 10:32:29 GMT+0800 (中国标准时间)",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "6566a2c09a2f15e8b4a0a633",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "friendId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "message": "<img src=\"./gif/17.gif\" width=\"65\" height=\"65\">",
                "msgType": 4,
                "time": "Wed Nov 29 2023 10:32:32 GMT+0800 (中国标准时间)",
                "state": 1,
                "__v": 0
            },
            {
                "_id": "656dcf867594f2bfc3e9e46f",
                "userId": {
                    "_id": "64fb10adad117203367263fb",
                    "nick": "臭粑卡皮巴拉",
                    "imgUrl": "/user2.png"
                },
                "friendId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "message": "{\"url\":\"/1701695366668-黄鼠狼.jpg\",\"height\":112.0607787274454}",
                "msgType": 1,
                "time": "Mon Dec 04 2023 21:09:26 GMT+0800 (中国标准时间)",
                "state": 0,
                "__v": 0
            }
        ]
    }
}

error

{
  status: 404,
  msg: '服务器错误'
}

37. 获取当前聊天群聊的信息

  • 请求url:/message/group
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
groupId String 群id
pageNum Number pageNum当前页码,从1开始
  • 返回值

未加入该群

{
    "status": 202,
    "data": {
        "_id": "65552471a63c59f4e6755e44",
        "groupName": "wifi群"
    },
    "msg": "您还未加入该群哦"
}

success

{
    "status": 200,
    "data": {
        "groupNick": {
            "_id": "65552471a63c59f4e6755e44",
            "groupName": "wifi群"
        },
        "messageList": [
            {
                "_id": "65626a027171e3582f99bc25",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "message": "1",
                "msgType": 0,
                "time": "Sun Nov 26 2023 05:41:22 GMT+0800 (中国标准时间)",
                "__v": 0
            },
            {
                "_id": "65626a027171e3582f99bc30",
                "groupId": "65552471a63c59f4e6755e44",
                "userId": {
                    "_id": "64eec06fa61f50ab31295296",
                    "nick": "wifi歪f",
                    "imgUrl": "/user_pic1.jpeg"
                },
                "message": "1",
                "msgType": 0,
                "time": "Sun Nov 26 2023 05:41:22 GMT+0800 (中国标准时间)",
                "__v": 0
            }
        ]
    }
}

暂无更多

{
  status: 201,
  "data": {
    "_id": "65552471a63c59f4e6755e44",
    "groupName": "wifi群"
  },
  msg: '暂无更多'
}

error

{
  status: 404,
  msg: '服务器错误'
}

38. 私聊图片上传接口

  • 请求url:/chat/private/photo
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
File File 文件对象,name:photo
  • 返回值

success

{res_code: 200, name: 文件名, url: 文件路径}

error

{ res_code: 500, msg: 'error' }

39. 群聊图片上传接口

  • 请求url:/chat/group/photo
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
File File 文件对象
  • 返回值

success

{ res_code: 200, name: 文件名, url: 文件路径 }

40. 上传分片(大文件上传)

  • 请求url:/chat/file/:type
  • 请求方式:post
  • 请求参数:
params:
参数名 类型 是否必填 描述
type String 类型(private或group)
body:
参数名 类型 是否必填 描述
blob Blob 文件切割,blob对象
  • 返回值

error

{
  status: 404,
  msg: '上传失败'
}

success

{
  status: 200,
  msg: '上传成功'
}

41. 合并切片

  • 请求url:/merge/:type
  • 请求方式:post
  • 请求参数:
params:
参数名 类型 是否必填 描述
type String 类型(private或group)
body:
参数名 类型 是否必填 描述
fileHash String 文件Hash
fileName String 文件名
size Number 文件切片大小
  • 返回值

success

{
  status: 200,
  msg: '合并成功',
  url: 文件路径
}

error

{
  status: 401,
  msg: '合并失败,请重新上传'
}

42. 文件秒传

  • 请求url:/verify/:type
  • 请求方式:post
  • 请求参数:
params:
参数名 类型 是否必填 描述
type String 类型(private或group)
body:
参数名 类型 是否必填 描述
fileHash String 文件hash
fileName String 文件名
  • 返回值

success:文件不需要重新上传

{
  status: 200,
  data: {
    shouldUpload: false, // 不需要重新上传
    url: 文件路径
  }
}

success:文件需要重新上传

{
    status: 200,
    data: {
        shouldUpload: true, // 重新上传
        existChunks: chunkPaths // 数组,存放已经上传过的部分切片(若没有上传过就是空)
    }
}

error

{
    status: 404,
    data: {
        shouldUpload: true,
        msg: '上传失败'
    }
}

43. 获取tabar消息页的消息列表(前提是发送过消息的好友/群)

  • 请求url:/message/list
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
  • 返回值

success

{
    "status": 200,
    "data": [
        {
            "_id": "64eec06fa61f50ab31295296",
            "nick": "wifi歪f",
            "imgUrl": "/user_pic1.jpeg",
            "lastMsg": {
                "_id": "656dcf867594f2bfc3e9e46f",
                "message": "{\"url\":\"/1701695366668-黄鼠狼.jpg\",\"height\":112.0607787274454}",
                "msgType": 1,
                "time": "Mon Dec 04 2023 21:09:26 GMT+0800 (中国标准时间)"
            },
            "type": "friendChat"
        },
        {
            "_id": "65552471a63c59f4e6755e44",
            "groupName": "wifi群",
            "imgUrl": "/group_pic.png",
            "lastMsg": {
                "message": "?",
                "msgType": 0,
                "time": "Mon Nov 27 2023 17:33:29 GMT+0800 (中国标准时间)"
            },
            "type": "groupChat",
            "unreadMsgCount": 0
        }
    ]
}

error

{
  status: 404,
  msg: '服务器错误'
}

44. 将好友聊天记录设置为已读

  • 请求url:/message/read/:type
  • 请求方式:get
  • 请求参数:
params:
参数名 类型 是否必填 描述
phone String 类型(值为friendgroup
query:
参数名 类型 是否必填 描述
userId String 用户id
id String 如果type为friend就是好友id,如果是group就是群id
  • 返回值

success

{
  status: 200,
  msg: '已读'
}

error

{
  status: 404,
  msg: '服务器错误'
}

45. 新增便签接口

  • 请求url:/notes/add
  • 请求方式:post
  • 请求参数:
参数名 类型 是否必填 描述
userId String 用户id
text String 便签内容
color String 便签颜色
time String 发布时间(xxxx-xx-xx)
  • 返回值

success

status: 200,
  msg: '已发布',
  _id: 便签id
}

error

{
  status: 404,
  msg: '服务器错误'
}

46. 获取所有便签接口

  • 请求url:/notes/get
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
pageNum Number 当前分页数(每页12条)
  • 返回值

success

{
    "status": 200,
    "data": [
        {
            "_id": "6514522318f60a765cf4593f",
            "userId": {
                "_id": "64eec06fa61f50ab31295296",
                "nick": "wifi歪f",
                "imgUrl": "/user_pic1.jpeg"
            },
            "text": "...",
            "color": "#fbdc7c",
            "time": "Thu Sep 28 2023 00:02:43 GMT+0800 (中国标准时间)",
            "__v": 0
        },
        {
            "_id": "64f85897dc7c6cf85d756b24",
            "userId": {
                "_id": "64eec06fa61f50ab31295296",
                "nick": "wifi歪f",
                "imgUrl": "/user_pic1.jpeg"
            },
            "text": "test",
            "color": "#fff5a8",
            "time": "Wed Sep 06 2023 18:46:47 GMT+0800 (中国标准时间)",
            "__v": 0
        }
    ]
}

error

{
  status: 404,
  data: '服务器错误'
}

47. 删除便签的接口

  • 请求url:/notes/del
  • 请求方式:get
  • 请求参数:
参数名 类型 是否必填 描述
_id String 便签id
  • 返回值

success

{
  status: 200,
  msg: '删除成功'
}

error

{
  status: 404,
  msg: '删除失败, 请稍后再试'
}

socketUrl: http://127.0.0.1:24000(以下是后端部分,前端触发和监听的事件名一致)

使用的socket.io

1. login事件

用户登陆后触发,前端传递的参数为:userId

  • 返回
socket.emit('login', socket.id)

2. private_chat事件

私聊事件,用户发送完消息后,前端通过该事件通知后端,后端接收到后返回给前端两个事件。前端传递的参数为:dataMsg, uId, fId

  • 参数

dataMsg:参考前端ts类型

type MessageType = {
	fromId?: string;
	toId?: string;
	userId: {
		_id: string;
		nick: string;
		imgUrl: string;
	},
	groupInfo?: {
		_id: string;
		groupName: string;
		imgUrl: string;
	};
	/*
		msgType: 0 => 文字消息,
				 1 => 图片消息,
				 2 => 视频消息,
				 3 => 文件消息,
				 4 => 单个emoji(变成大的emoji),
				 5 => markdown,
				 6 => 语音通话,
				 7 => 视频通话,
				 8 => 屏幕共享
	*/
	time: string | Date;
	msgType: number;
	message: string;
	loading?: boolean; // 临时图片loading
	progressNum?: number; // 进度条数字
	uid?: number; // 临时图片uid
}

uId:发送方id

fId:接受方id

  • 返回
socket.to(users[fId]).emit('private_chat', data) // 未读好友消息
socket.to(users[fId]).emit('unread_message', uId)

data:

let data = {
  userId: dataMsg.userId,
  msgType: dataMsg.msgType,  // msgType 消息类型(0:文字(包括表情包),1:图片)
  message: dataMsg.message,
  time: new Date(),
  fromId: uId, // 发送方id
  toId: fId // 接收方id
}

3. join_group事件

用户通过群聊发送消息,必须先触发join_group事件,传递gId群id,将该好友加入到不同的群聊房间

4. group_chat事件

用户群聊事件,通过该事件,用户b可以获取到用户a发送的信息,前提是必须有join_group事件,接收参数dataMsg, uId, gId

dataMsg同私聊事件的dataMsg

uId是发送者id

gId是发送到哪个群的id(群id)

  • 返回
socket.to(gId).emit('group_chat', data)
socket.to(gId).emit('unread_message', gId)

返回的data:

let data = {
  userId: dataMsg.userId, // 发消息好友信息
  groupInfo: {
      _id: info._id,
      groupName: info.groupName,
      imgUrl: info.imgUrl
  }, // 群聊信息
  msgType: dataMsg.msgType,  // msgType 消息类型(0:文字(包括表情包),1:图片)
  message: dataMsg.message,
  time: new Date(),
  fromId: uId,
  toId: gId
}

5. init_apply_notice初始化申请消息通知事件

在tabbar(h5)端,在侧边栏中(桌面端应用),初始化消息通知数,传递userId给后端

  • 返回
socket.emit('init_apply_notice', { friendNoticeNum, groupNoticeNum })
// friendNoticeNum 好友消息数
// groupNoticeNum 群消息数

6. apply_notice好友、群申请通知事件

参数同5

  • 返回

apply_notice,前端需要接收该事件

socket.to(users[userId]).emit('apply_notice', { friendNoticeNum, groupNoticeNum })

7. agree_apply同意好友/群申请事件

前端需要传递给接收者id(toId),接收者id就是用户a给用户b发送好友/群聊申请,那么用户b的id就是接收者id

  • 返回
socket.to(users[toId]).emit('agree_apply')

8. logout退出登陆事件

前端需要向后端传递userId

JavaScript
1
https://gitee.com/lichen-y/weif-chat-desktop-backend.git
git@gitee.com:lichen-y/weif-chat-desktop-backend.git
lichen-y
weif-chat-desktop-backend
歪fChat桌面端后端
master

搜索帮助