网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

商业化IM客户端设计---Message模型-创新互联

在IM开发中,一个问题是怎么管理传输,包括处理消息发送,消息接受和怎么转发等等,就是上一篇文章提到的IMService扮演的角色。另一个问题就是传输的具体数据是怎么定义的,既包括业务数据(文字,语音,图片,地理位置等),也包括控制数据(音频请求,加群请求,离群请求)。现在通过分析Message实体类来学习一下。

十载的前进网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整前进建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联建站从事“前进网站设计”,“前进网站推广”以来,每个客户项目都认真落实执行。

下面一系列的常量定义了Message的type

#define MSG_HEARTBEAT 1  //心跳
#define MSG_AUTH 2 //认证
#define MSG_AUTH_STATUS 3 //认证状态
#define MSG_IM 4
#define MSG_ACK 5 //ACK
#define MSG_RST 6 
#define MSG_GROUP_NOTIFICATION 7 //群消息
#define MSG_GROUP_IM 8 //群消息
#define MSG_PEER_ACK 9 //ACK
#define MSG_INPUTING 10 //输入
#define MSG_SUBSCRIBE_ONLINE_STATE 11 //在线状态
#define MSG_ONLINE_STATE 12 //在线状态
#define MSG_PING 13  //
#define MSG_PONG 14  //
#define MSG_AUTH_TOKEN 15 //TOKEN
#define MSG_LOGIN_POINT 16 //多点登录
#define MSG_RT 17
#define MSG_ENTER_ROOM 18 //进入聊天室
#define MSG_LEAVE_ROOM 19 //离开聊天室
#define MSG_ROOM_IM 20  //聊天室消息
#define MSG_SYSTEM 21  //系统消息
#define MSG_UNREAD_COUNT 22   //未读消息数
#define MSG_CUSTOMER_SERVICE 23  //客服服务消息
#define MSG_CUSTOMER 24  //客服消息
#define MSG_CUSTOMER_SUPPORT 25 //客服支持
#define MSG_VOIP_CONTROL 64  //VOIP命令

下面几个常量定义了平台type

#define PLATFORM_IOS  1       
#define PLATFORM_ANDROID 2
#define PLATFORM_WEB 3

IMMessage类由接受者ID,发送者ID,时间戳,消息本地存储ID,消息内容构成,见下面代码。

@interface IMMessage : NSObject
@property(nonatomic, assign)int64_t sender;
@property(nonatomic, assign)int64_t receiver;
@property(nonatomic, assign)int32_t timestamp;
@property(nonatomic, assign)int32_t msgLocalID;
@property(nonatomic, copy)NSString *content;
@end

CustomerMessage,客服消息类,和通用的IM消息格式差别在,customerID,sellerID,customerAppID,storeID这几个属性需要根据客服消息特定的使用场景来理解。

@interface CustomerMessage : NSObject
//本地消息id 不会序列化传到服务器
@property(nonatomic, assign)int32_t msgLocalID;本地存储ID
@property(nonatomic, assign)int64_t customerAppID;//APPid
@property(nonatomic, assign)int64_t customerID;//客服用户ID
@property(nonatomic, assign)int64_t storeID;//商铺ID
@property(nonatomic, assign)int64_t sellerID;//客服ID
@property(nonatomic, assign)int32_t timestamp;
@property(nonatomic, copy)NSString *content;
@end

RoomMessage 聊天室消息

@interface RoomMessage : NSObject
@property(nonatomic, assign)int64_t sender;
@property(nonatomic, assign)int64_t receiver;
@property(nonatomic, copy)NSString *content;
@end

消息输入状态

typedef RoomMessage RTMessage;

@interface MessageInputing : NSObject
@property(nonatomic, assign)int64_t sender;
@property(nonatomic, assign)int64_t receiver;
@end

授权结构体

@interface AuthenticationToken : NSObject
@property(nonatomic, copy) NSString *token;
@property(nonatomic, assign) int8_t platformID;
@property(nonatomic, copy) NSString *deviceID;
@end

多点登录结构体

@interface LoginPoint : NSObject
@property(nonatomic, assign) int32_t upTimestamp;
@property(nonatomic, assign) int8_t platformID;
@property(nonatomic, copy) NSString *deviceID;
@end

@interface VOIPControl : NSObject
@property(nonatomic, assign) int64_t sender;
@property(nonatomic, assign) int64_t receiver;
@property(nonatomic) NSData *content;

@end

@interface Message : NSObject
@property(nonatomic, assign)int cmd;
@property(nonatomic, assign)int seq;
@property(nonatomic) NSObject *body;

-(NSData*)pack;

-(BOOL)unpack:(NSData*)data;
@end

如果想要在现有的消息类型上支持新的消息类型,比如(实时定位,阅后即焚,(T)一下)。需要在Message基础上做扩展。

完整的代码和DEMO可以到[Gobelieve IM]查看。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:商业化IM客户端设计---Message模型-创新互联
文章来源:http://bjjierui.cn/article/dsjgej.html

其他资讯