目录
一.目标概述
经过对腾讯云第三方回调的了解,我们知道了当对im进行交互的时候,腾讯云im会将交互的信息以json包的形式发送给我们指定的端口,当本地服务器接收到json包之后,将交互信息保存到本地数据库,从而实现交互信息持久化。
二.剩余第三方回调的实现
需要实现的回调
在掌握清楚第三方回调的原理,并搭建好大致的框架后,开始对剩余的第三方回调进行编码。
需要实现的第三方回调如下:
在线状态
回调类型 | 回调命令字 |
---|---|
状态变更回调 | State.StateChange |
资料关系链
回调类型 | 回调命令字 |
---|---|
添加好友之前回调 | Sns.CallbackPrevFriendAdd |
添加好友回应之前回调 | Sns.CallbackPrevFriendResponse |
添加好友之后回调 | Sns.CallbackFriendAdd |
删除好友之后回调 | Sns.CallbackFriendDelete |
添加黑名单之后回调 | Sns.CallbackBlackListAdd |
删除黑名单之后回调 | Sns.CallbackBlackListDelete |
单聊消息
回调类型 | 回调命令字 |
---|---|
发单聊消息之前回调 | C2C.CallbackBeforeSendMsg |
发单聊消息之后回调 | C2C.CallbackAfterSendMsg |
单聊消息已读上报后回调 | C2C.CallbackAfterMsgReport |
单聊消息撤回后回调 | C2C.CallbackAfterMsgWithDraw |
群组系统
回调类型 | 回调命令字 |
---|---|
创建群组之前回调 | Group.CallbackBeforeCreateGroup |
创建群组之后回调 | Group.CallbackAfterCreateGroup |
申请入群之前回调 | Group.CallbackBeforeApplyJoinGroup |
拉人入群之前回调 | Group.CallbackBeforeInviteJoinGroup |
新成员入群之后回调 | Group.CallbackAfterNewMemberJoin |
群成员离开之后回调 | Group.CallbackAfterMemberExit |
群内发言之前回调 | Group.CallbackBeforeSendMsg |
群内发言之后回调 | Group.CallbackAfterSendMsg |
群组满员之后回调 | Group.CallbackAfterGroupFull |
群组解散之后回调 | Group.CallbackAfterGroupDestroyed |
群组资料修改之后回调 | Group.CallbackAfterGroupInfoChanged |
完成的回调
回调的实体类
回调的控制层
此处列举一部分
else if (callbackCommand.equals("Sns.CallbackPrevFriendAdd")){
String headStr = JSON.toJSONString(headMap);
String bodyStr = JSON.toJSONString(bodyMap);
JSONObject headJson = JSONObject.parseObject(headStr);
JSONObject bodyJson = JSONObject.parseObject(bodyStr);
String clientIP = headJson.getString("ClientIP");
Timestamp eventTime = bodyJson.getTimestamp("EventTime");
String requester_Account = bodyJson.getString("Requester_Account");
String from_Account = bodyJson.getString("From_Account");
String addType = bodyJson.getString("AddType");
String forceAddFlags = bodyJson.getString("ForceAddFlags");
JSONArray friendItem = bodyJson.getJSONArray("FriendItem");
List<CallbackPrevFriendAdd> callbackPrevFriendAddList = JSON.parseObject(friendItem.toJSONString(), new TypeReference<List<CallbackPrevFriendAdd>>() {
});
for (CallbackPrevFriendAdd add : callbackPrevFriendAddList) {
add.setClientIP(clientIP);
add.setEventTime(eventTime);
add.setRequester_Account(requester_Account);
add.setFrom_Account(from_Account);
add.setAddType(addType);
add.setForceAddFlags(forceAddFlags);
}
//System.out.println(callbackPrevFriendAddList);
List<Integer> res = callBackService.callbackPrevFriendAdd(callbackPrevFriendAddList);
int result = ResCondition.callbackPrevFriendAdd_success;
for (Integer r : res) {
if (r < 0){
result = ResCondition.callbackPrevFriendAdd_fail;
}
}
if (result == ResCondition.callbackPrevFriendAdd_success){
responseMap.put("ActionStatus","OK");
responseMap.put("ErrorCode",0);
responseMap.put("ErrorInfo","");
return responseMap;
}
else if (result == ResCondition.callbackPrevFriendAdd_fail){
responseMap.put("ActionStatus","FAIL");
responseMap.put("ErrorCode",1);
responseMap.put("ErrorInfo","写入数据库失败");
return responseMap;
}
else {
responseMap.put("ActionStatus","FAIL");
responseMap.put("ErrorCode",1);
responseMap.put("ErrorInfo","未知的错误");
return responseMap;
}
}
else if (callbackCommand.equals("Sns.CallbackPrevFriendResponse")){
String headStr = JSON.toJSONString(headMap);
String bodyStr = JSON.toJSONString(bodyMap);
JSONObject headJson = JSONObject.parseObject(headStr);
JSONObject bodyJson = JSONObject.parseObject(bodyStr);
String clientIP = headJson.getString("ClientIP");
Timestamp eventTime = bodyJson.getTimestamp("EventTime");
String requester_Account = bodyJson.getString("Requester_Account");
String from_Account = bodyJson.getString("From_Account");
JSONArray responseFriendItem = bodyJson.getJSONArray("ResponseFriendItem");
List<CallbackPrevFriendResponse> callbackPrevFriendResponseList = JSON.parseObject(responseFriendItem.toJSONString(), new TypeReference<List<CallbackPrevFriendResponse>>() {
});
System.out.println(callbackPrevFriendResponseList);
for (CallbackPrevFriendResponse add : callbackPrevFriendResponseList) {
add.setClientIP(clientIP);
add.setEventTime(eventTime);
add.setRequester_Account(requester_Account);
add.setFrom_Account(from_Account);
}
//System.out.println(callbackPrevFriendAddList);
List<Integer> res = callBackService.callbackPrevFriendResponse(callbackPrevFriendResponseList);
int result = ResCondition.callbackPrevFriendResponse_success;
for (Integer r : res) {
if (r < 0){
result = ResCondition.callbackPrevFriendResponse_fail;
}
}
if (result == ResCondition.callbackPrevFriendResponse_success){
responseMap.put("ActionStatus","OK");
responseMap.put("ErrorCode",0);
responseMap.put("ErrorInfo","");
return responseMap;
}
回调的服务层
service接口
package com.feixun.feixunshiyan.service;
import com.feixun.feixunshiyan.domain.imCallBack.*;
import java.util.List;
public interface CallBackService {
public int stateChange(StateChange stateChange);
public List<Integer> callbackPrevFriendAdd(List<CallbackPrevFriendAdd> callbackPrevFriendAddList);
public List<Integer> callbackPrevFriendResponse(List<CallbackPrevFriendResponse> callbackPrevFriendResponse);
public List<Integer> callbackFriendAdd(List<CallbackFriendAdd> callbackFriendAdd);
public List<Integer> callbackFriendDelete(List<CallbackFriendDelete> callbackFriendDelete);
public List<Integer> callbackBlackListAdd(List<CallbackBlackListAdd> callbackBlackListAdd);
public List<Integer> callbackBlackListDelete(List<CallbackBlackListDelete> callbackBlackListDelete);
public List<Integer> callbackBeforeSendMsgText(List<CallbackBeforeSendMsgText> callbackBeforeSendMsgText);
public List<Integer> callbackAfterSendMsgText(List<CallbackAfterSendMsgText> callbackAfterSendMsgText);
public int callbackAfterMsgReport(CallbackAfterMsgReport callbackAfterMsgReport);
public int callbackAfterMsgWithDraw(CallbackAfterMsgWithDraw callbackAfterMsgWithDraw);
public List<Integer> callbackBeforeCreateGroup(List<CallbackBeforeCreateGroup> callbackBeforeCreateGroup);
public List<Integer> callbackAfterCreateGroup(List<CallbackAfterCreateGroup> callbackAfterCreateGroup);
public int callbackBeforeApplyJoinGroup(CallbackBeforeApplyJoinGroup callbackBeforeApplyJoinGroup);
public List<Integer> callbackBeforeInviteJoinGroup(List<CallbackBeforeInviteJoinGroup> callbackBeforeInviteJoinGroup);
public List<Integer> callbackAfterNewMemberJoin(List<CallbackAfterNewMemberJoin> callbackAfterNewMemberJoin);
public List<Integer> callbackAfterMemberExit(List<CallbackAfterMemberExit> callbackAfterMemberExit);
public List<Integer> callbackBeforeSendMsgGroupText(List<CallbackBeforeSendMsgGroupText> callbackBeforeSendMsgGroupText);
public List<Integer> callbackAfterSendMsgGroupText(List<CallbackAfterSendMsgGroupText> callbackAfterSendMsgGroupText);
public int callbackAfterGroupFull(CallbackAfterGroupFull callbackAfterGroupFull);
public List<Integer> callbackAfterGroupDestroyed(List<CallbackAfterGroupDestroyed> callbackAfterGroupDestroyed);
public int callbackAfterGroupInfoChanged(CallbackAfterGroupInfoChanged callbackAfterGroupInfoChanged);
}
service实现
此处列举一部分
@Override
public List<Integer> callbackPrevFriendAdd(List<CallbackPrevFriendAdd> callbackPrevFriendAddList) {
List<Integer> res = new LinkedList<>();
for (CallbackPrevFriendAdd add : callbackPrevFriendAddList) {
int success = callBackMapper.callbackPrevFriendAdd(add);
if (success > 0){
res.add(ResCondition.callbackPrevFriendAdd_success);
}
else {
res.add(ResCondition.callbackPrevFriendAdd_fail);
}
}
return res;
}
@Override
public List<Integer> callbackPrevFriendResponse(List<CallbackPrevFriendResponse> callbackPrevFriendResponse) {
List<Integer> res = new LinkedList<>();
for (CallbackPrevFriendResponse add : callbackPrevFriendResponse) {
int success = callBackMapper.callbackPrevFriendResponse(add);
if (success > 0){
res.add(ResCondition.callbackPrevFriendResponse_success);
}
else {
res.add(ResCondition.callbackPrevFriendResponse_fail);
}
}
return res;
}
@Override
public List<Integer> callbackFriendAdd(List<CallbackFriendAdd> callbackFriendAdd) {
List<Integer> res = new LinkedList<>();
for (CallbackFriendAdd add : callbackFriendAdd) {
int success = callBackMapper.callbackFriendAdd(add);
if (success > 0){
res.add(ResCondition.callbackFriendAdd_success);
}
else {
res.add(ResCondition.callbackFriendAdd_fail);
}
}
return res;
}
@Override
public List<Integer> callbackFriendDelete(List<CallbackFriendDelete> callbackFriendDelete) {
List<Integer> res = new LinkedList<>();
for (CallbackFriendDelete delete : callbackFriendDelete) {
int success = callBackMapper.callbackFriendDelete(delete);
if (success > 0){
res.add(ResCondition.callbackFriendDelete_success);
}
else {
res.add(ResCondition.callbackFriendDelete_fail);
}
}
return res;
}
@Override
public List<Integer> callbackBlackListAdd(List<CallbackBlackListAdd> callbackBlackListAdd) {
List<Integer> res = new LinkedList<>();
for (CallbackBlackListAdd add : callbackBlackListAdd) {
int success = callBackMapper.callbackBlackListAdd(add);
if (success > 0){
res.add(ResCondition.callbackBlackListAdd_success);
}
else {
res.add(ResCondition.callbackBlackListAdd_fail);
}
}
return res;
}
@Override
public List<Integer> callbackBlackListDelete(List<CallbackBlackListDelete> callbackBlackListDelete) {
List<Integer> res = new LinkedList<>();
for (CallbackBlackListDelete delete : callbackBlackListDelete) {
int success = callBackMapper.callbackBlackListDelete(delete);
if (success > 0){
res.add(ResCondition.callbackBlackListDelete_success);
}
else {
res.add(ResCondition.callbackBlackListDelete_fail);
}
}
return res;
}
dao层
package com.feixun.feixunshiyan.mapper;
import com.feixun.feixunshiyan.domain.imCallBack.*;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface CallBackMapper {
public int stateChange(StateChange stateChange);
public int callbackPrevFriendAdd(CallbackPrevFriendAdd callbackPrevFriendAddList);
public int callbackPrevFriendResponse(CallbackPrevFriendResponse callbackPrevFriendResponse);
public int callbackFriendAdd(CallbackFriendAdd callbackFriendAdd);
public int callbackFriendDelete(CallbackFriendDelete callbackFriendDelete);
public int callbackBlackListAdd(CallbackBlackListAdd callbackBlackListAdd);
public int callbackBlackListDelete(CallbackBlackListDelete callbackBlackListDelete);
public int callbackBeforeSendMsgText(CallbackBeforeSendMsgText callbackBeforeSendMsgText);
public int callbackAfterSendMsgText(CallbackAfterSendMsgText callbackAfterSendMsgText);
public int callbackAfterMsgReport(CallbackAfterMsgReport callbackAfterMsgReport);
public int callbackAfterMsgWithDraw(CallbackAfterMsgWithDraw callbackAfterMsgWithDraw);
public int callbackBeforeCreateGroup(CallbackBeforeCreateGroup callbackBeforeCreateGroup);
public int callbackAfterCreateGroup(CallbackAfterCreateGroup callbackAfterCreateGroup);
public int callbackBeforeApplyJoinGroup(CallbackBeforeApplyJoinGroup callbackBeforeApplyJoinGroup);
public int callbackBeforeInviteJoinGroup(CallbackBeforeInviteJoinGroup callbackBeforeInviteJoinGroup);
public int callbackAfterNewMemberJoin(CallbackAfterNewMemberJoin callbackAfterNewMemberJoin);
public int callbackAfterMemberExit(CallbackAfterMemberExit callbackAfterMemberExit);
public int callbackBeforeSendMsgGroupText(CallbackBeforeSendMsgGroupText callbackBeforeSendMsgGroupText);
public int callbackAfterSendMsgGroupText(CallbackAfterSendMsgGroupText callbackAfterSendMsgGroupText);
public int callbackAfterGroupFull(CallbackAfterGroupFull callbackAfterGroupFull);
public int callbackAfterGroupDestroyed(CallbackAfterGroupDestroyed callbackAfterGroupDestroyed);
public int callbackAfterGroupInfoChanged(CallbackAfterGroupInfoChanged callbackAfterGroupInfoChanged);
}
xml文件操作数据库
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.feixun.feixunshiyan.mapper.CallBackMapper">
<insert id="stateChange" parameterType="StateChange">
insert into stateChange(clientIP,eventTime,action,to_Account,reason) values (#{clientIP},#{eventTime},#{action},#{to_Account},#{reason})
</insert>
<insert id="callbackPrevFriendAdd" parameterType="callbackPrevFriendAdd" >
insert into callbackPrevFriendAdd(clientIP,eventTime,requester_Account,from_Account,addType,forceAddFlags,to_Account,remark,groupName,addSource,addWording) values
(#{clientIP},#{eventTime},#{requester_Account},#{from_Account},#{addType},#{forceAddFlags},#{to_Account},#{remark},#{groupName},#{addSource},#{addWording})
</insert>
<insert id="callbackPrevFriendResponse" parameterType="callbackPrevFriendResponse" >
insert into callbackPrevFriendResponse(clientIP,eventTime,requester_Account,from_Account,to_Account,remark,tagName,responseAction) values
(#{clientIP},#{eventTime},#{requester_Account},#{from_Account},#{to_Account},#{remark},#{tagName},#{responseAction})
</insert>
<insert id="callbackFriendAdd" parameterType="callbackFriendAdd" >
insert into callbackFriendAdd(clientIP,clientCmd,admin_Account,forceFlag,from_Account,to_Account,initiator_Account) values
(#{clientIP},#{clientCmd},#{admin_Account},#{forceFlag},#{from_Account},#{to_Account},#{initiator_Account})
</insert>
<insert id="callbackFriendDelete" parameterType="callbackFriendDelete" >
insert into callbackFriendDelete(clientIP,from_Account,to_Account) values
(#{clientIP},#{from_Account},#{to_Account})
</insert>
<insert id="callbackBlackListAdd" parameterType="callbackBlackListAdd" >
insert into callbackBlackListAdd(clientIP,from_Account,to_Account) values
(#{clientIP},#{from_Account},#{to_Account})
</insert>
<insert id="callbackBlackListDelete" parameterType="callbackBlackListDelete" >
insert into callbackBlackListDelete(clientIP,from_Account,to_Account) values
(#{clientIP},#{from_Account},#{to_Account})
</insert>
<insert id="callbackBeforeSendMsgText" parameterType="callbackBeforeSendMsgText" >
insert into callbackBeforeSendMsgText(clientIP,from_Account,to_Account,msgSeq,msgRandom,msgTime,msgKey,onlineOnlyFlag,msgType,cloudCustomData,text) values
(#{clientIP},#{from_Account},#{to_Account},#{msgSeq},#{msgRandom},#{msgTime},#{msgKey},#{onlineOnlyFlag},#{msgType},#{cloudCustomData},#{text})
</insert>
<insert id="callbackAfterSendMsgText" parameterType="callbackAfterSendMsgText" >
insert into callbackAfterSendMsgText(clientIP,from_Account,to_Account,msgSeq,msgRandom,msgTime,msgKey,onlineOnlyFlag,sendMsgResult,errorInfo,unreadMsgNum,msgType,cloudCustomData,text) values
(#{clientIP},#{from_Account},#{to_Account},#{msgSeq},#{msgRandom},#{msgTime},#{msgKey},#{onlineOnlyFlag},#{sendMsgResult},#{errorInfo},#{unreadMsgNum},#{msgType},#{cloudCustomData},#{text})
</insert>
<!-- <insert id="callbackBlackListDelete" parameterType="callbackBlackListDelete" >
insert into callbackBlackListDelete(clientIP,from_Account,to_Account) values
(#{clientIP},#{from_Account},#{to_Account})
</insert>-->
<insert id="callbackAfterMsgReport" parameterType="callbackAfterMsgReport" >
insert into callbackAfterMsgReport(clientIP,report_Account,peer_Account,lastReadTime,unreadMsgNum) values
(#{clientIP},#{report_Account},#{peer_Account},#{lastReadTime},#{unreadMsgNum})
</insert>
<insert id="callbackAfterMsgWithDraw" parameterType="callbackAfterMsgWithDraw" >
insert into callbackAfterMsgWithDraw(clientIP,from_Account,to_Account,msgKey,unreadMsgNum) values
(#{clientIP},#{from_Account},#{to_Account},#{msgKey},#{unreadMsgNum})
</insert>
<insert id="callbackBeforeCreateGroup" parameterType="callbackBeforeCreateGroup" >
insert into callbackBeforeCreateGroup(clientIP,operator_Account,owner_Account,type,name,createGroupNum,member_Account) values
(#{clientIP},#{operator_Account},#{owner_Account},#{type},#{name},#{createGroupNum},#{member_Account})
</insert>
<insert id="callbackAfterCreateGroup" parameterType="callbackAfterCreateGroup" >
insert into callbackAfterCreateGroup(clientIP,groupId,operator_Account,owner_Account,type,name,member_Account) values
(#{clientIP},#{groupId},#{operator_Account},#{owner_Account},#{type},#{name},#{member_Account})
</insert>
<insert id="callbackBeforeApplyJoinGroup" parameterType="callbackBeforeApplyJoinGroup" >
insert into callbackBeforeApplyJoinGroup(clientIP,groupId,type,requestor_Account) values
(#{clientIP},#{groupId},#{type},#{requestor_Account})
</insert>
<insert id="callbackBeforeInviteJoinGroup" parameterType="callbackBeforeInviteJoinGroup" >
insert into callbackBeforeInviteJoinGroup(clientIP,groupId,type,operator_Account,member_Account) values
(#{clientIP},#{groupId},#{type},#{operator_Account},#{member_Account})
</insert>
<insert id="callbackAfterNewMemberJoin" parameterType="callbackAfterNewMemberJoin" >
insert into callbackAfterNewMemberJoin(clientIP,groupId,type,joinType,operator_Account,member_Account) values
(#{clientIP},#{groupId},#{type},#{joinType},#{operator_Account},#{member_Account})
</insert>
<insert id="callbackAfterMemberExit" parameterType="callbackAfterMemberExit" >
insert into callbackAfterMemberExit(clientIP,groupId,type,exitType,operator_Account,member_Account) values
(#{clientIP},#{groupId},#{type},#{exitType},#{operator_Account},#{member_Account})
</insert>
<insert id="callbackBeforeSendMsgGroupText" parameterType="callbackBeforeSendMsgGroupText" >
insert into callbackBeforeSendMsgGroupText(clientIP,groupId,type,from_Account,operator_Account,random,onlineOnlyFlag,msgType,text,cloudCustomData) values
(#{clientIP},#{groupId},#{type},#{from_Account},#{operator_Account},#{random},#{onlineOnlyFlag},#{msgType},#{text},#{cloudCustomData})
</insert>
<insert id="callbackAfterSendMsgGroupText" parameterType="callbackAfterSendMsgGroupText" >
insert into callbackAfterSendMsgGroupText(clientIP,groupId,type,from_Account,operator_Account,random,msgSeq,msgTime,onlineOnlyFlag,msgType,text,cloudCustomData) values
(#{clientIP},#{groupId},#{type},#{from_Account},#{operator_Account},#{random},#{msgSeq},#{msgTime},#{onlineOnlyFlag},#{msgType},#{text},#{cloudCustomData})
</insert>
<insert id="callbackAfterGroupFull" parameterType="callbackAfterGroupFull" >
insert into callbackAfterGroupFull(clientIP,groupId) values
(#{clientIP},#{groupId})
</insert>
<insert id="callbackAfterGroupDestroyed" parameterType="callbackAfterGroupDestroyed" >
insert into callbackAfterGroupDestroyed(clientIP,groupId,type,owner_Account,name,member_Account) values
(#{clientIP},#{groupId},#{type},#{owner_Account},#{name},#{member_Account})
</insert>
<insert id="callbackAfterGroupInfoChanged" parameterType="callbackAfterGroupInfoChanged" >
insert into callbackAfterGroupInfoChanged(clientIP,groupId,type,operator_Account,notification) values
(#{clientIP},#{groupId},#{type},#{operator_Account},#{notification})
</insert>
</mapper>
此时,回调的持久化已经完成
二.回调结果的处理
有些第三方回调可以向im服务器返回处理结果,以决定用户的行为是否可以进行。
如:在用户聊天的过程中,可能会产生一些违禁词,因此,可以在云服务器后台添加违禁词识别的模块,若检测到用户聊天的违禁词,则予以屏蔽,使其发送失败。
应答包示例(允许发言)
允许用户发言,同时也不修改即将下发的消息的内容。
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 0 // 0 为允许发言
}
应答包示例(禁止发言)
不允许用户发言,该消息将不会下发。
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 1 // 1 为拒绝发言
}
应答包示例(修改消息内容)
如下的应答示例为:对用户发送的单聊消息进行了修改(增加了自定义消息或消息自定义数据),即时通信 IM 后台将会下发经过修改之后的消息。App 后台可以基于这一特性在用户发送的消息中增加一些特殊内容,例如用户等级、头衔等信息。
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 0, // 必须为0,只有这样,修改之后的消息才能正常下发
"MsgBody": [ // App 修改之后的消息,如果没有,则默认使用用户发送的消息
{
"MsgType": "TIMTextElem", // 文本
"MsgContent": {
"Text": "red packet"
}
},
{
"MsgType": "TIMCustomElem", // 自定义消息
"MsgContent": {
"Desc": " CustomElement.MemberLevel ", // 描述
"Data": " LV1" // 数据
}
}
],
"CloudCustomData": "your new cloud custom data" // 消息自定义数据
}
应答包字段说明
字段 | 类型 | 属性 | 说明 |
---|---|---|---|
ActionStatus | String | 必填 | 请求处理的结果,OK 表示处理成功,FAIL 表示失败 |
ErrorCode | Integer | 必填 | 错误码,0为允许发言;1为拒绝发言。若业务希望拒绝发言的同时,将错误码 ErrorCode 和 ErrorInfo 传递至客户端,请将错误码 ErrorCode 设置在 [120001, 130000] 区间内 |
ErrorInfo | String | 必填 | 错误信息 |
MsgBody | Array | 选填 | 经过 App 修改之后的消息体,即时通信 IM 后台将把修改后的消息发送给接收方,具体格式参见 消息格式描述 |
CloudCustomData | String | 选填 | 经过 App 修改之后的消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到),即时通信 IM 后台将把修改后的消息发送给接收方 |
代码实现
应答包的实现体现在回调中,当保存好回调后,对回调信息进行判断,如消息,包含违禁词则阻止发送
if (result == ResCondition.callbackPrevFriendResponse_success){
responseMap.put("ActionStatus","OK");
responseMap.put("ErrorCode",0);
responseMap.put("ErrorInfo","");
return responseMap;
}
else if (result == ResCondition.callbackPrevFriendResponse_fail){
responseMap.put("ActionStatus","FAIL");
responseMap.put("ErrorCode",1);
responseMap.put("ErrorInfo","写入数据库失败");
return responseMap;
}
else {
responseMap.put("ActionStatus","FAIL");
responseMap.put("ErrorCode",1);
responseMap.put("ErrorInfo","未知的错误");
return responseMap;
}