-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
461 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 回调功能 | ||
|
||
<Toc /> | ||
|
||
## 概述 | ||
|
||
环信即时通讯云支持回调功能,即会在事件发生之前或之后,环信 IM 服务器会以 HTTP POST 请求的形式向你的应用服务器发送通知。根据是否干预消息投递,回调分为两类: | ||
|
||
- **发送前回调**:旨在让 app 后台干预该事件的处理逻辑,环信服务器会根据响应中的返回值确定后续处理流程。**该类回调仅适用于从你的客户端应用发送的消息。** | ||
|
||
该类回调一般是对用户发送的消息内容的处理,典型的应用场景为内容审核:当环信服务器收到来自客户端应用的消息时,会向你的应用服务器发送请求并等待响应,从而决定是否通过或拒绝消息投递。 | ||
|
||
- **发送后回调**:旨在让 app 后台实现必要的数据同步,环信服务器忽略回调返回码。 | ||
|
||
发送后回调包括发送消息、发送消息已读回执、进行群组或聊天室操作、好友关系操作和用户状态变化等事件,详见[发送后回调过滤规则设置](/product/enable_and_configure_IM.html#配置回调规则)。 | ||
|
||
使用回调功能前,请查看你的产品套餐是否支持,详见[增值服务说明](/product/pricing.html#增值服务费用)。若不支持,你需首先在[环信即时通讯云控制台](https://console.easemob.com/user/login)[开通该功能](/product/enable_and_configure_IM.html#开通消息回调),然后[配置发送前回调规则发送后回调规则](/product/enable_and_configure_IM.html#配置回调规则)。 | ||
|
||
:::tip | ||
若使用了一段时间回调功能后需要将其关闭,请联系环信商务。关闭该功能会导致回调所有相关配置删除,请谨慎操作。 | ||
::: | ||
|
||
## 两类回调的区别 | ||
|
||
| 类别 | 发送前回调 | 发送后回调 | | ||
| ---------- | ---------- | ---------------------- | | ||
| 支持的消息发送方式 | 客户端 SDK | 客户端 SDK 和 RESTful API | | ||
| 支持的范围 | 仅限消息 | 消息和其他事件 | | ||
| 发生的时间 | 环信服务器收到用户发送的上行单聊和群聊消息之后、且将该消息下发给目标用户之前 | 发送消息后或进行单聊、群聊、聊天室、联系人等相关的操作后 | | ||
| 是否需要响应 | 是 | 否 | | ||
| 典型用例 | 内容审核 | 聊天记录同步 | | ||
|
||
## 回调安全 | ||
|
||
对于发送前和发送后回调,环信服务器会向你的应用服务器发送带有 JSON 负载的 HTTP/HTTPS POST 请求。请求采用 UTF-8 编码,每个请求中的消息都使用 MD5 签名。在每个请求头中,`Content-Type` 字段为 `application/json`。 | ||
|
||
对于发送后回调,请求中的消息使用通过 `org.apache.commons.codec.digest.DigestUtils#md5Hex` 计算的 MD5 签名。 | ||
|
||
你可以通过以下步骤验证签名检查回调是否从环信服务器发送: | ||
|
||
1. 查找以下信息: | ||
|
||
- 回调 ID:回调请求体中的 `callId` 参数。 | ||
|
||
- 环信服务器为回调规则生成的 secret:你可以在[环信即时通讯云控制台](https://console.easemob.com/user/login)的**消息回调**页面的回调规则列表中查看。 | ||
|
||
![img](1.png) | ||
|
||
- 回调时间戳:回调请求体中的时间戳参数。 | ||
|
||
2. 计算回调 ID、secret、回调时间戳拼接后的字符串的 MD5 值。 | ||
|
||
3. 检查计算的值是否与请求体中的 secret 参数相同。若相同,则表示该回调请求由环信服务器发送。 | ||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.