目录

参数列表

Variable Meanings
$appId 小米开放平台申请的AppId
$token 查询方的token(使用user.getToken()获取)
$account 查询方在APP系统内唯一ID
$fromAccount 消息发送方在APP帐号系统内唯一ID
$toAccount 消息接收方在APP帐号系统内唯一ID
$topicId 表示群ID
$utcFromTime 表示查询开始时间,UTC时间,单位毫秒
$utcToTime 表示查询结束时间,UTC时间,单位毫秒
$startSeq 表示查询开始序列号
$stopSeq 表示查询结束序列号
$count 表示查询的消息条数
$row 表示返回的消息条数
$timestamp 表示返回的消息中最早的时间戳
$messages 表示返回的消息集合
$sequence sequence主要用来做消息的排序和去重,全局唯一
$payload 表示经过Base64编码的消息体,app端需要进行Base64解码
$ts 表示消息时间戳
$bizType 可用于表示消息类型扩展字段(可选)
$extra 可用于表示消息全局扩展字段值(可选)
$extraKey 可用于表示单条消息扩展字段Key(可选)
$extraValue 可用于表示单条消息扩展字段值(可选)
$sequenceExtraMap Map 格式 对应
$sextraKeyMap Map 格式 对应

保存多久

API名称 保存时间
拉取指定时间单聊消息记录 6个月
拉取指定数目单聊消息记录 6个月
拉取指定序列号单聊消息记录 7天
拉取指定时间群聊消息记录 6个月
拉取指定数目群聊消息记录 6个月
拉取指定序列号群聊消息记录 7天

拉取指定时间单聊消息记录

指的是拉取[utcFromTime, utcToTime)的时间范围内的A与B之间的聊天记录,单聊是相对于群聊而言的一对一聊天。
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2p/query/ -XPOST
  -d '{"toAccount":$toAccount,"fromAccount":$fromAccount,"utcFromTime":$utcFromTime,"utcToTime":$utcToTime,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
curl https://mimc.chat.xiaomi.net/api/msg/p2p/queryOnTime -XPOST
  -d '{"toAccount":$toAccount,"fromAccount":$fromAccount,"utcFromTime":$utcFromTime,"utcToTime":$utcToTime,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
{
     "code": 200,
     "message": "success",
     "data": {
         "appId": $appId,
         "messages": [
             {
                 "sequence": $sequence,
                 "payload": $payload,
                 "ts": $ts,
                 "fromAccount":$fromAccount,
                 "toAccount": $toAccount,
                 "bizType":$bizType,
                 "extra":$extra
             }
         ],
         "row": $row
     }
 }

备注

1. utcFromTime和utcToTime的时间间隔不能超过24小时,查询状态为[utcFromTime,utcToTime);
2. timestamp字段在这个请求的响应中没有意义。
3. extra 为消息扩展字段,可以根据业务需求灵活定义格式和内容,这里也可以通过extra对查询结果进行过滤。

拉取指定数目单聊消息记录

指的是拉取从指定的时间戳utcToTime(不包含utcToTime)向前count条的A与B之间的聊天记录。
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2p/queryOnCount/ -XPOST
  -d '{"toAccount":$toAccount,"fromAccount":$fromAccount,"utcToTime":$utcToTime,"count":$count,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
{
     "code": 200,
     "message": "success",
     "data": {
         "appId": $appId,
         "messages": [
             {
                 "sequence": $sequence,
                 "payload": $payload,
                 "ts": $ts,
                 "fromAccount":$fromAccount,
                 "toAccount": $toAccount,
                 "bizType":$bizType,
                 "extra":$extra
             }
         ],
         "row": $row,
         "timestamp":$timestamp
     }
 }

备注

timestamp字段在这个请求的响应中表示当前的聊天记录最早的时间戳(单位:毫秒)。

拉取指定序列号单聊消息记录

指的是拉取从[startSeq, stopSeq)之间的A与B之间的聊天记录。
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2p/queryOnSequence/ -XPOST
  -d '{"toAccount":$toAccount,"fromAccount":$fromAccount,"startSeq":$startSeq,"stopSeq":$stopSeq}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
{
     "code": 200,
     "message": "success",
     "data": {
         "appId": $appId,
         "messages": [
             {
                 "sequence": $sequence,
                 "payload": $payload,
                 "ts": $ts,
                 "fromAccount":$fromAccount,
                 "toAccount": $toAccount,
                 "bizType":$bizType,
                 "extra":$extra
             }
         ],
         "row": $row,
         "timestamp":$timestamp
     }
 }

备注

timestamp字段表示当前的聊天记录最早的时间戳(单位:毫秒)。

拉取指定时间群聊消息记录

  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2t/query/ -XPOST
  -d '{"account":$account,"topicId":$topicId,"utcFromTime":$utcFromTime,"utcToTime":$utcToTime,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
curl https://mimc.chat.xiaomi.net/api/msg/p2t/queryOnTime/ -XPOST
  -d '{"account":$account,"topicId":$topicId,"utcFromTime":$utcFromTime,"utcToTime":$utcToTime,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
PS:URL中的$account与$token需要相匹配(即$token应该是$account用户的token信息)。
  • JSON结果示例
{
     "code": 200,
     "message": "success",
     "data": {
         "appId": $appId,
         "topicId": $topicId,
         "row": $row,
         "timestamp":$timestamp,
         "messages": [
             {
                 "sequence": $sequence,
                 "fromAccount": $fromAccount,
                 "payload": $payload,
                 "ts": $ts,
                 "bizType":$bizType,
                 "extra":$extra
             },
             {
                 "sequence": $sequence,
                 "fromAccount": $fromAccount,
                 "payload": $payload,
                 "ts": $ts,
                 "bizType":$bizType,
                 "extra":$extra
             }
         ]
     }
 }

备注

timestamp字段在这个请求的响应中表示当前的聊天记录最早的时间戳(单位:毫秒)。。

拉取指定数目群聊消息记录

指的是拉取从指定的时间戳utcToTime(不包含utcToTime)向前count条的指定的topicId的群聊天记录。
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2t/queryOnCount/ -XPOST
  -d '{"account":$account,"topicId":$topicId,"utcToTime":$utcToTime,"count":$count,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
PS:URL中的$account与$token需要相匹配(即$token应该是$account用户的token信息)。
  • JSON结果示例
    {
       "code": 200,
       "message": "success",
       "data": {
           "appId": $appId,
           "topicId": $topicId,
           "row": $row,
           "timestamp":$timestamp,
           "messages": [
               {
                   "sequence": $sequence,
                   "payload": $payload,
                   "ts": $ts,
                   "fromAccount":$fromAccount,
                   "bizType":$bizType,
                   "extra":$extra
               }
           ]
       }
    }
    

    备注

    timestamp字段在这个请求的响应中表示当前的聊天记录最早的时间戳(单位:毫秒)。
    

拉取指定序列号群聊消息记录

指的是拉取[startSeq, stopSeq)的指定的topicId的群聊天记录。

如下为拉取[startSeq, stopSeq)的群聊消息记录

  • HTTPS请求(POST)

    curl https://mimc.chat.xiaomi.net/api/msg/p2t/queryOnSequence/ -XPOST
    -d '{"account":$account,"topicId":$topicId,"startSeq":$startSeq,"stopSeq":$stopSeq}'
    -H "Content-Type: application/json;charset=UTF-8"
    -H "Accept:application/json;charset=UTF-8"
    -H "token:$token"
    
    PS:URL中的$account与$token需要相匹配(即$token应该是$account用户的token信息)。
    
  • JSON结果示例

    {
       "code": 200,
       "message": "success",
       "data": {
           "appId": $appId,
           "topicId": $topicId,
           "row": $row,
           "timestamp":$timestamp,
           "messages": [
               {
                   "sequence": $sequence,
                   "payload": $payload,
                   "ts": $ts,
                   "fromAccount":$fromAccount,
                   "bizType":$bizType,
                   "extra":$extra
               }
           ]
       }
    }
    

备注

timestamp字段表示当前的聊天记录最早的时间戳(单位:毫秒)。

拉取指定时间超级大群聊消息记录

  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2u/queryOnTime/ -XPOST
  -d '{"account":$account,"topicId":$topicId,"utcFromTime":$utcFromTime,"utcToTime":$utcToTime,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
PS:URL中的$account与$token需要相匹配(即$token应该是$account用户的token信息)。
  • JSON结果示例
{
     "code": 200,
     "message": "success",
     "data": {
         "appId": $appId,
         "topicId": $topicId,
         "row": $row,
         "timestamp":$timestamp,
         "messages": [
             {
                 "fromAccount": $fromAccount,
                 "payload": $payload,
                 "ts": $ts,
                 "bizType":$bizType,
                 "extra":$extra
             },
             {
                 "fromAccount": $fromAccount,
                 "payload": $payload,
                 "ts": $ts,
                 "bizType":$bizType,
                 "extra":$extra
             }
         ]
     }
 }

备注

timestamp字段在这个请求的响应中表示当前的聊天记录最早的时间戳(单位:毫秒)。

拉取指定数目超级大群聊消息记录

指的是拉取从指定的时间戳utcToTime(不包含utcToTime)向前count条的指定的topicId的群聊天记录。
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2u/queryOnCount/ -XPOST
  -d '{"account":$account,"topicId":$topicId,"utcToTime":$utcToTime,"count":$count,"bizType":$bizType,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
PS:URL中的$account与$token需要相匹配(即$token应该是$account用户的token信息)。
  • JSON结果示例
    {
       "code": 200,
       "message": "success",
       "data": {
           "appId": $appId,
           "messages": [
               {
                   "payload": $payload,
                   "ts": $ts,
                   "fromAccount":$fromAccount,
                   "bizType":$bizType,
                   "extra":$extra
               }
           ],
           "row": $row,
           "timestamp":$timestamp
       }
    }
    

    备注

    timestamp字段在这个请求的响应中表示当前的聊天记录最早的时间戳(单位:毫秒)。
    

更新单聊消息扩展extra

更新指定sequence的某条单聊消息的消息扩展属性extra
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2p/extra/update -XPOST
  -d '{"fromAccount":$fromAccount,"toAccount":$toAccount,"sequence":$sequence,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": {
          "fromAccount": $fromAccount, 
          "toAccount": $toAccount, 
          "sequence": $sequence, 
          "extra": $extra
      }
    }
    

更新群聊消息扩展extra

更新指定sequence的某条群聊消息的消息扩展属性extra
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2t/extra/update -XPOST
  -d '{"account":$account,"topicId":$topicId,"sequence":$sequence,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
curl https://mimc.chat.xiaomi.net/api/msg/p2u/extra/update -XPOST
  -d '{"account":$account,"topicId":$topicId,"sequence":$sequence,"extra":$extra}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": {
          "topicId": $topicId, 
          "sequence": $sequence, 
          "extra": $extra
      }
    }
    

批量更新单聊消息扩展extra

批量更新指定sequence的单聊消息的消息扩展属性extra
sequenceExtraMap  Map<String,String> 格式 对应<sequence,extra>
updateCode 成功返回00  失败返回01
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2p/extra/multiupdate -XPOST
  -d '{"fromAccount":$fromAccount,"toAccount":$toAccount,"sequenceExtraMap":$sequenceExtraMap}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": [
          {
              "updateCode": "01", 
              "updateMsg": "Records do not exist and cannot be updated", 
              "fromAccount": "$fromAccount", 
              "toAccount": "$toAccount", 
              "sequence": "$sequence", 
              "extra": "$extra"
          }, 
          {
              "updateCode": "00", 
              "updateMsg": "success", 
              "fromAccount": "$fromAccount", 
              "toAccount": "$toAccount", 
              "sequence": "$sequence", 
              "extra": "$extra"
          }
      ]
    }
    

批量更新群聊消息扩展extra

同上
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2t/extra/multiupdate -XPOST
  -d '{"account":$account,"topicId":$topicId,"sequenceExtraMap":$sequenceExtraMap}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
curl https://mimc.chat.xiaomi.net/api/msg/p2u/extra/multiupdate -XPOST
  -d '{"account":$account,"topicId":$topicId,"sequenceExtraMap":$sequenceExtraMap}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": [
          {
              "updateCode": "00", 
              "updateMsg": "success", 
              "account": "$account", 
              "topicId": "$topicId", 
              "sequence": "$sequence", 
              "extra": "$extra"
          }
      ]
    }
    

v2 版本增加对每一条消息的多扩展设计,原来的消息扩展属性extra可作为消息全局扩展对待,开发者可自行传入extrakey设置多条特定扩展属性,以适应业务上的需要。

更新单聊消息扩展extra V2

更新指定sequence的某条单聊消息的消息扩展属性extra
如果不传extraKey,默认更新全局消息extra属性。
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2p/extra/update/v2 -XPOST
  -d '{"fromAccount":$fromAccount,"toAccount":$toAccount,"sequence":$sequence,"extraKey":$extraKey,"extraValue":$extraValue}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": {
          "fromAccount": $fromAccount, 
          "toAccount": $toAccount, 
          "sequence": $sequence, 
          "extraKey": $extraKey,
          "extraValue": $extraValue
      }
    }
    

更新群聊消息扩展extra V2

更新指定sequence的某条群聊消息的消息扩展属性extra
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2t/extra/update/v2 -XPOST
  -d '{"account":$account,"topicId":$topicId,"sequence":$sequence,"extraKey":$extraKey,"extraValue":$extraValue}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
curl https://mimc.chat.xiaomi.net/api/msg/p2u/extra/update/v2 -XPOST
  -d '{"account":$account,"topicId":$topicId,"sequence":$sequence,"extraKey":$extraKey,"extraValue":$extraValue}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": {
          "topicId": $topicId, 
          "sequence": $sequence, 
          "extraKey": $extraKey,
          "extraValue":$extraValue
      }
    }
    

更新单聊消息多扩展extra

批量更新指定sequence的单聊消息的消息扩展属性extra
extraKeyMap  Map<String,String> 格式 对应<extrakey,extraValue>
updateCode 成功返回00  失败返回01
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2p/extra/batchupdate -XPOST
  -d '{"fromAccount":$fromAccount,"toAccount":$toAccount,"sequence":$sequence,"extraKeyMap":$extraKeyMap}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": [
          {
              "updateCode": "01", 
              "updateMsg": "Records do not exist and cannot be updated", 
              "fromAccount": "$fromAccount", 
              "toAccount": "$toAccount", 
              "sequence": "$sequence", 
              "extraKey": "$extraKey",
              "extraValue": "$extraValue",
          }, 
          {
              "updateCode": "00", 
              "updateMsg": "success", 
              "fromAccount": "$fromAccount", 
              "toAccount": "$toAccount", 
              "sequence": "$sequence", 
              "extraKey": "$extraKey",
              "extraValue": "$extraValue"
          }
      ]
    }
    

更新群聊消息多扩展extra

同上
  • HTTPS请求(POST)
curl https://mimc.chat.xiaomi.net/api/msg/p2t/extra/batchupdate -XPOST
  -d '{"account":$account,"topicId":$topicId,"sequence":$sequence,"extraKeyMap":$extraKeyMap}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
curl https://mimc.chat.xiaomi.net/api/msg/p2u/extra/batchupdate -XPOST
  -d '{"account":$account,"topicId":$topicId,"extraKeyMap":extraKeyMap}'
  -H "Content-Type: application/json;charset=UTF-8"
  -H "Accept:application/json;charset=UTF-8"
  -H "token:$token"
  • JSON结果示例
    {
      "code": 200, 
      "message": "success", 
      "data": [
          {
              "updateCode": "00", 
              "updateMsg": "success", 
              "account": "$account", 
              "topicId": "$topicId", 
              "sequence": "$sequence", 
              "extraKey": "$extraKey",
              "extraValue": "$extraValue"
          }
      ]
    }
    

回到顶部

results matching ""

    No results matching ""