Message(站内消息)

GET /api/Message/List

  • 描述: 获取消息列表。

  • 参数:

    • page (integer): 页码,默认值为 1。

    • pageSize (integer): 每页大小,默认值为 10。

  • 响应: 200 OK

  • 请求示例:

    const myHeaders = new Headers();
    myHeaders.append("Authorization", "<API Key>");
    
    const requestOptions = {
      method: "GET",
      headers: myHeaders,
      redirect: "follow"
    };
    
    fetch("/api/Message/List?page=1&pageSize=10", requestOptions)
      .then((response) => response.json())
      .then((result) => console.log(result))
      .catch((error) => console.error(error));
  • 返回示例:

    {
      "success": true,
      "messages": {
        "send": [
          {
            "id": 1,
            "senderId": 123,
            "receiverId": 456,
            "content": "你好,这是一条消息!",
            "createdAt": "2023-10-01T12:00:00Z"
          }
        ],
        "receive": [
          {
            "id": 2,
            "senderId": 456,
            "receiverId": 123,
            "content": "收到,谢谢!",
            "createdAt": "2023-10-01T12:05:00Z"
          }
        ]
      }
    }

POST /api/Message/Send

  • 描述: 发送消息。

  • 请求体:

    • application/json: SendMessageRequest 对象

    • text/json: SendMessageRequest 对象

    • application/*+json: SendMessageRequest 对象

  • 请求体参数:

    • receiveId (string, required): 接收者 ID。

    • content (string, required): 消息内容。

  • 响应: 200 OK

  • 请求示例:

    {
      "Username": "petter",
      "content": "你好,这是一条新消息!"
    }
  • 示例代码:

    const myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/json");
    myHeaders.append("Authorization", "<API Key>");
    
    const raw = JSON.stringify({
      "Username": "petter",
      "content": "你好,这是一条新消息!"
    });
    
    const requestOptions = {
      method: "POST",
      headers: myHeaders,
      body: raw,
      redirect: "follow"
    };
    
    fetch("/api/Message/Send", requestOptions)
      .then((response) => response.json())
      .then((result) => console.log(result))
      .catch((error) => console.error(error));
  • 返回示例:

    {
      "success": true
    }

GET /api/Message/Delete

  • 描述: 删除消息。

  • 参数:

    • messageId (ulong, required): 消息 ID。

  • 响应: 200 OK

  • 请求示例:

    const myHeaders = new Headers();
    myHeaders.append("Authorization", "<API Key>");
    
    const requestOptions = {
      method: "GET",
      headers: myHeaders,
      redirect: "follow"
    };
    
    fetch("/api/Message/Delete?messageId=1", requestOptions)
      .then((response) => response.json())
      .then((result) => console.log(result))
      .catch((error) => console.error(error));
  • 返回示例:

    {
      "success": true
    }

注意事项

  1. 权限控制:

    • 所有接口均需要用户登录并携带有效的 Authorization 头(Bearer Token)。

  2. 消息发送限制:

    • 每个用户每秒最多发送 2 条消息,超过限制会返回错误:"send too many messages"

  3. 消息删除权限:

    • 只有消息的发送者或接收者可以删除消息,否则会返回错误:"permission denied"

Last updated