wildfirechat / android-chat

即时通讯,聊天,野火IMAndroid客户端,支持Android 4.x —— 最新
http://docs.wildfirechat.cn
Other
2.54k stars 890 forks source link

自定义消息问题 #592

Closed chenlin4653 closed 2 years ago

chenlin4653 commented 2 years ago

请求 服务端 发送 自定义 消息,需要参考什么格式,移动端(android 、iOS) 消息体 content 一直没有值 ,谢谢。

heavyrain2012 commented 2 years ago

请参考 https://docs.wildfirechat.cn/base_knowledge/custom_message_content.html 里面有这么一段,服务器发送的是客户端encode之后的格式,需要跟客户端对齐。另外客户端也需要按照这个说明来定义和注册消息

使用Server API发送消息是与客户端不同的,在Server API发送的是Encode之后的MessagePayload。所以如果您想要在服务器端发送某个消息(自定义和内置消息都是一样的),就必须使用跟客户端一样的规则Encode生成MessagePayload,并且MessagePayload里的二进制数据是经过base64转码的。

chenlin4653 commented 2 years ago

目前 android 和 iOS 通过 binaryContent 字段 ,使用 JSONObject 手动解析 里面的内容,binaryContent byte[] , 服务端 MessagePayload 没有 此 此段?Server API发送消息 MessagePayload里的二进制数据是经过base64转码的? 二进制内容 是不是 对应 客户端 MessageContent ? 客户端 没有看到 base64 解码 ?

imndx commented 2 years ago
  1. 通过Server API 发送消息时,MessagePayload里面的base64edData对应客户端的binaryContent字段,base64edData需要进行base64编码。
  2. 客户端不需要进行base64解码,服务端已经处理过了,binaryContent已经是原始的二进制数据了。