消息相关回调
更新时间: 2024/07/17 17:57:34
本文介绍会话消息回调和消息撤回回调的使用示例以及相关的参数说明。
本文示例代码中的 POST 接入点仅为示例,您在实际使用中需使用您在 网易云信控制台 配置的第三方回调地址。
会话消息回调
HTTP 示例
HTTPPOST /receiveMsg.action HTTP/1.1
Host: yunxinservice.com.cn
AppKey: 158983***453d6542
CurTime: 1541583920979
MD5: e89c284a5ad9a76b3176e23108920f81
CheckSum: 6f08c5ee2dd16a5fc34a12005e5d5f1411e657a1
Content-Type: application/json
Cache-Control: no-cache
{"body":"Hello","eventType":1,"fromAccount":"000266","fromClientType":"WEB","fromDeviceId":"617715aa8579db03f0cf054c199*****","fromNick":"yj000266","msgTimestamp":"1541560157286","msgType":"TEXT","msgidClient":"","to":"005877","fromClientIp":"115.211.51.**","fromClientPort":"568**"}
cURL 示例
cURLcurl -X POST \
http://yunxinservice.com.cn/receiveMsg.action \
-H 'appkey: 1589**19453d6542' \
-H 'cache-control: no-cache' \
-H 'checksum: 6f08c5ee2dd16a5fc34a12005e5d5f1411e657a1' \
-H 'content-type: application/json' \
-H 'curtime: 1541583920979' \
-H 'md5: e89c284a5ad9a76b3176e23108920f81' \
-d '{"body":"Hello","eventType":1,"fromAccount":"000266","fromClientType":"WEB","fromDeviceId":"617715aa8579db03f0cf054c199****","fromNick":"yj000266","msgTimestamp":"1541560157286","msgType":"TEXT","msgidClient":"","to":"005877","fromClientIp":"115.211.51.**","fromClientPort":"568**"}'
消息体字段说明
- 回调的 JSON 格式消息中并不是每个字段都一定会抄送,请注意对各字段的判空处理。
- 针对聊天室消息,
body
为空,文本内容、图片内容等均承载在attach
中。
名称 |
类型 | 必须 | 说明 | |
---|---|---|---|---|
eventType |
Integer | 是 | 参考第三方回调事件类型,包括:点对点消息、群消息、聊天室消息、超大群消息,具体请参考 第三方回调事件类型 | |
fromAccount |
String | 是 | 消息发送者的用户账号 | |
fromNick |
String | 否 | 发送方昵称 | |
fromClientType |
String | 是 |
|
|
fromDeviceId |
String | 是 | 发送设备 ID | |
to |
String | 是 |
eventType 为 22 ,则 to 为 tid ,即超大群 ID,可转为 Long 型数据 |
|
msgTimestamp |
String | 是 | 消息发送时间 | |
msgType |
String | 是 |
|
|
fromClientIp |
String | 否 | 消息发送方的客户端 IP 地址 | |
fromClientPort |
String | 否 | 消息发送方的客户端端口号 | |
msgidClient |
String | 否 | 客户端消息 ID | |
body |
String | 否 | 消息内容,部分消息类型不需要传入该参数,但需传入 attach ,示例以及具体说明请参考 回调的消息格式示例 |
|
attach |
String | 否 | 消息附件,部分消息类型不需要传入该参数,但需传入 body ,示例以及具体说明请参考 回调的消息格式示例 |
|
ext |
String | 否 | 消息扩展字段 |
消息撤回回调
HTTP 示例
HTTPPOST /receiveMsg.action HTTP/1.1
Host: yunxinservice.com.cn
AppKey: 158983**219453d6542
CurTime: 1541583920979
MD5: e89c284a5ad9a76b3176e23108920f81
CheckSum: 6f08c5ee2dd16a5fc34a12005e5d5f1411e657a1
Content-Type: application/json
Cache-Control: no-cache
{"eventType":35,"fromAccount":"wm1","fromClientIp":"36.18.111.***","fromClientPort":"39***","fromClientType":"AOS","fromDeviceId":"ef6b789c-3079-463b-a52b-4924ae5*****","msgFromAccid":"wm1","msgId":184409700039655569,"msgidClient":"b897b26234d246858031291f12bc498d","opeType":8,"time":1590482455336,"timestamp":"1590482457381","toAccount":"2747918666"}
cURL 示例
cURLcurl -X POST \
http://yunxinservice.com.cn/receiveMsg.action \
-H 'appkey: 1589838**453d6542' \
-H 'cache-control: no-cache' \
-H 'checksum: 6f08c5ee2dd16a5fc34a12005e5d5f1411e657a1' \
-H 'content-type: application/json' \
-H 'curtime: 1541583920979' \
-H 'md5: e89c284a5ad9a76b3176e23108920f81' \
-d '{"eventType":35,"fromAccount":"wm1","fromClientIp":"36.18.111.***","fromClientPort":"396**","fromClientType":"AOS","fromDeviceId":"ef6b789c-3079-463b-a52b-4924ae5*****","msgFromAccid":"wm1","msgId":184409700039655569,"msgidClient":"b897b26234d246858031291f12bc498d","opeType":8,"time":1590482455336,"timestamp":"1590482457381","toAccount":"2747918666"}'
消息体字段说明
回调的 JSON 格式消息中并不是每个字段都会一定抄送,请注意对各字段的判空处理。
名称 |
类型 | 必须 | 说明 |
---|---|---|---|
eventType |
Integer | 是 | 值为 35 ,表示是消息撤回回调 |
fromAccount |
String | 是 | 操作者账号 |
fromDeviceId |
String | 是 | 操作者设备 ID |
fromClientType |
String | 是 | 操作者的客户端类型:
|
fromClientIp |
String | 否 | 操作者的客户端 IP 地址 |
fromClientPort |
String | 否 | 操作者的客户端端口号 |
msgFromAccid |
String | 是 | 被撤回消息的消息发送者 |
msgId |
Long | 是 | 被撤回消息的消息 ID(服务器 ID) |
time |
Long | 是 | 被撤回消息的消息发送时间 |
opeType |
int | 是 | 7 表示单聊消息撤回,8 表示群消息撤回 |
toAccount |
String | 是 | 消息接收者的 accid ,或者,群的 tid |
msgidClient |
String | 否 | 被撤回消息的消息 ID(客户端 ID) |
msg |
String | 否 | 消息撤回附言 |
attach |
String | 否 | 消息撤回扩展字段 |
timestamp |
String | 是 | 操作时间,字符串类型 |
回调消息示例
文本消息
配置文本消息回调,body
与 attach
两个参数仅需传入 body
。
JSON {
"body":"文本消息测试-foewv38e8t",
"eventType":1,
"ext":"ext-sdk-p2p",
"fromAccount":"yx",
"fromClientIp":"115.236.119.***",
"fromClientPort":"346**",
"fromClientType":"AOS",
"fromDeviceId":"8cd34559-5180-480f-9813-a803dd8*****",
"fromNick":"yx",
"msgTimestamp":"1652176290246",
"msgType":"TEXT",
"msgidClient":"3cc0abf7-4edb-45fb-bd8c-3ea3539*****",
"to":"yx1"
}
图片消息
配置图片消息回调,body
与 attach
两个参数仅需传入 attach
。
JSON{
"attach":"{\"name\":\"msgPic1652172360227\",\"md5\":\"3c2536b2-8beb-4163-a78d-45c43ff*****\",\"url\":\"https://nim-nosdn.netease.im/MTAxMTAxMA==/bmltd18wXzE2NTIxNzIzNjE2MDlfNTViMTcytYjdlNC00MWFlLTk4ZjItYTkw*******\",\"ext\":\"png\",\"w\":434,\"h\":524,\"size\":50790}",
"eventType":1,
"ext":"ext-sdk-p2p",
"fromAccount":"yx",
"fromClientIp":"115.236.119.***",
"fromClientPort":"44**",
"fromClientType":"AOS",
"fromDeviceId":"8474fe54-38df-4078-9f2f-c590ecd*****",
"fromNick":"yx",
"msgTimestamp":"1652172362176",
"msgType":"PICTURE",
"msgidClient":"eb0ed5c0-269e-4aa8-9125-ed8a645*****",
"to":"yx1"
}
语音消息
配置语音消息回调,body
与 attach
两个参数仅需传入 attach
。
JSON{
"attach":"{\"dur\":4272,\"md5\":\"58f886a6-f8fc-4296-a987-8071219*****\",\"url\":\"https://nim-nosdn.netease.im/MTAxMTAxMA==/bmltd18wXzE2NTIxNzY0MzIxNzJfMDE5YjRkZDMtM2IyNC00OGE1NzUtZjg4ODRiMz******\",\"ext\":\"aac\",\"size\":15469}",
"eventType":1,
"ext":"ext-sdk-p2p",
"fromAccount":"yx",
"fromClientIp":"115.236.119.***",
"fromClientPort":"32**",
"fromClientType":"AOS",
"fromDeviceId":"cbea0328-8358-4008-9871-f0bc6a0*****",
"fromNick":"yx",
"msgTimestamp":"1652176432609",
"msgType":"AUDIO",
"msgidClient":"dc9a86e6-4ba1-4796-b906-c1acb1d*****",
"to":"yx1"
}
视频消息
配置视频消息回调,body
与 attach
两个参数仅需传入 attach
。
JSON{
"attach":"{\"dur\":4085,\"md5\":\"3da918f8-76cf-4d37-90cc-b5f553b*****\",\"url\":\"https://nim.nosdn.127.net/MTAxMTAxMA==/bmltYV84NDg1MV8xNjE3MTYxOTAwNjgzXzYzMDM5OWQ2LWE1ZTctNGQ2MS05YmY5LTdhNTExNjdmZA==\",\"ext\":\"mp4\",\"w\":320,\"h\":568,\"size\":450553}",
"eventType":1,
"ext":"ext-sdk-p2p",
"fromAccount":"yx",
"fromClientIp":"115.236.119.***",
"fromClientPort":"204**",
"fromClientType":"AOS",
"fromDeviceId":"cd0f5be1-cbb5-4bb9-a9f5-3426bcf*****",
"fromNick":"yx",
"msgTimestamp":"1652176585581",
"msgType":"VIDEO",
"msgidClient":"932f2fae-9fc5-463d-aaef-7716c3e*****",
"to":"yx1"
}
地理位置消息
配置地理位置消息回调,body
与 attach
两个参数仅需传入 attach
。
JSON{
"attach":"{\"title\":\"浙江省 杭州市 滨江区 网商路 599 号\",\"lng\":120.1908686708565,\"lat\":30.18704515647036}",
"eventType":1,
"ext":"ext-sdk-p2p",
"fromAccount":"yx",
"fromClientIp":"115.236.119.***",
"fromClientPort":"437**",
"fromClientType":"AOS",
"fromDeviceId":"db2cc47c-7c26-4db3-882a-c50fdb746***",
"fromNick":"yx",
"msgTimestamp":"1652176764047",
"msgType":"LOCATION",
"msgidClient":"84566917-e2fd-44f3-982f-4cd2c0f*****",
"to":"yx1"
}
文件消息
配置文件消息回调,body
与 attach
两个参数仅需传入 attach
。
JSON{
"attach":"{\"name\":\"test.ttf\",\"url\":\"http://nimtest.nos.netease.com/08c9859d\",\"ext\":\"ttf\",\"size\":91680,\"md5\":\"aa4057aa-eef1-4a0c-84b9-72a45b0*****\"}",
"eventType":1,
"ext":"ext-sdk-p2p",
"fromAccount":"yx",
"fromClientIp":"115.236.119.***",
"fromClientPort":"46***",
"fromClientType":"AOS",
"fromDeviceId":"b4d8b465-f308-48ed-a46f-5083697*****",
"fromNick":"yx",
"msgTimestamp":"1652176858782",
"msgType":"FILE",
"msgidClient":"ce418ee9-c56e-42be-8c84-e75b464*****",
"to":"yx1"
}
提示消息
配置提示消息回调,body
与 attach
两个参数仅需传入 body
。
JSON{
"body": "您收到一份礼物",
"eventType":1,
"fromAccount":"yx1",
"fromClientIp":"183.136.182.140",
"fromClientPort":"44996",
"fromClientType":"WEB",
"fromDeviceId":"785b4b7bed112510c3e77a3d312db6dd",
"fromNick":"yx1",
"msgTimestamp":"1652177773071",
"msgType":"TIPS",
"msgidClient":"7431e4208ef53efeb0d52d38d26fec38",
"to":"yx2"
}
自定义消息
配置自定义消息回调,body
与 attach
两个参数仅需传入 attach
。
JSON{
"attach":"{\"data\":\"{\"value\":3}\",\"type\":1}",
"eventType":1,
"ext":"ext-sdk-p2p",
"fromAccount":"yx",
"fromClientIp":"115.236.119.*****",
"fromClientPort":"220**",
"fromClientType":"AOS",
"fromDeviceId":"6d34b999-e16d-421f-adba-5f7cf4e*****",
"fromNick":"yx",
"msgTimestamp":"1652177102140",
"msgType":"CUSTOM",
"msgidClient":"51ea3405-743e-41c6-9346-3fd9e9c*****",
"to":"yx1"
}
此文档是否对你有帮助?