| 
					
				 | 
			
			
				@ -17,11 +17,14 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				数据库设计是将消息按通道分开:系统消息,个人消息及群消息。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- msg_system: 系统消息,通过系统端发出去的消息存储在此表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- msg_p2p: 私信,通过私信端发出去的消息存储在此表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- msg_group: 群消息,通过群消息端发出去的消息存储在此表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- msg_statistic: 消息统计,当有系统,个人或群消息的时候,除了在上述三个记录数据外,还会在表中插入相关的消息统计,如:接收人有多少条未读消息,最后消息时间,内容或群ID等 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- msg_push: 消息推送,当消息需要推送到设备的时候,先将消息记录在此表中,再用个推服务推送到目标设备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- system_messages: 系统消息,通过系统端发出去的消息存储在此表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- p2p_messages: 私信,通过私信端发出去的消息存储在此表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- group_messages: 群消息,通过群消息端发出去的消息存储在此表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- muc_messages:muc患者咨询消息,通过咨询发送出去的消息存储在此表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- app_status: 消息推送获取应用状态的表,当消息需要推送到设备的时候,先从此表获取客户端信息,再用个推服务推送到目标设备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- participants:会话成员表,所有的会话成员创建都创建到此表中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- sessions:所有的消息对话的主体对象,会话表,记录所有会话记录,根据type和business_type来区分对应的信息type=1 muc模式,type=2 p2p模式,type=3  group模式 type = 0 系统会话 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- topics:所有的咨询(包括名医咨询都存储在此表中)关联会话信息,每个会话跟议题是一对多的关系。议题的消息根据会话类型不同分别存储在p2p_messages(会话类型type = 2)和muc_messages(会话类型type = 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				## 运行 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -98,56 +101,83 @@ Node.js支持同步与异步调用,也导致了异常错误处理与众不同 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				REST API遵循REST最佳实践,规范命名URL中的每个部分。注意POST请求是将数据作为请求体发送。下文中的host:port分别表示服务所在的主机地址及端口。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				1 发送系统消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    POST http://host:port/api/v1/chats/sm 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				参数格式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        to: "Rose", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        title: "System Message", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        summary: "You have new job", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        contentType: "1", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        content: "The patient has been followed in the scheduler, please make new follow plan as soon as possible." 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * IM客户端SDK。此SDK可以连接开发、测试或生产环境,根据需要配置环境参数以连接到不同的服务器。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				const APIv2 = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    Application: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Base: '/api/v2/application',   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BadgeNo: '/badge_no' //获取角  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    Users: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Base: '/api/v2/users', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Login: '/login',  //用户登录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Logout: '/logout', //用户登出 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        User: '/:user_id', //获取用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserStatus: '/:user_id/status',//用户状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserConsultTime:'/:user_id/consult/time'//用户咨询时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    Sessions: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Base: '/api/v2/sessions', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Session: '/:session_id/session', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SessionSticky: '/:session_id/sticky',                           // 会话置顶,置顶使用PUT,取消置顶使用DELETE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SessionStatus: '/:session_id/status',                           //更新状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RecentSessions: '/recent',                                      // 最近会话,使用类型过滤出'患者'或'医生'会话 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Topics: '/:topic_id/topics', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Topic: '/topics/:topic_id',                          // 议题,指定ID的议题将返回其信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TopicEnded: '/:session_id/topics/:topic_id/ended',              // 议题是否已结束,若top_id为current,则检查最后一个议题的状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TopicList:'/topics', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TopicReplyCount:"/topics/count/reply", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TopicMessages:'/topic/:topic_id/messages', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Messages: '/:session_id/messages',                             // 会话消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        MessagesByTopic: '/:session_id/topics/:topic_id/messages',      // 议题消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Message: '/:session_id/messages/:message_id',                   // 单条消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SessionsUnreadMessageCount: '/unread_message_count',            // 所有会话的未读消息数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SessionUnreadMessageCount: '/:session_id/unread_message_count', // 指定会话的未读消息数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SessionUnreadMessages: '/:session_id/messages/unread',           // 会话未读消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ParticipantUpdate:'/:session_id/participant/update',//更新成员=删除旧成员,新增新成员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Participants: '/:session_id/participants',                      // 会话所有成员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ParticipantsAvatar: '/:session_id/participants/avatars',        // 会话所有成员头像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Participant: '/:session_id/participants/:participant_id',       // 会话单个成员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ParticipantAvatar: '/:session_id/participants/:participant_id/avatars'  // 会话单个成员头像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				2 发送P2P消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    GET http://192.168.131.115:3000/api/v1/chats/pm 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				参数格式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        from: 发送人ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        to: 接收人ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        contentType: 内容类型,1为普通文本,2为图片,3为语音,4为超链接, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        content: "消息内容" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				3 发送群消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    POST http://192.168.131.115:3000/api/v1/chats/gm 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				参数格式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        from: 发送人ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        at: at对象ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        group: 组ID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        groupType: 组类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        contentType: 内容类型,1为普通文本,2为图片,3为语音,4为超链接, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        content: "消息内容" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				4 获取消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    GET http://192.168.131.115:3000/api/v1/chats/pm?user_id=xxx 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				参数: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- user_id: 用户ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				### 业务分析 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    消息类型:muc_messsges,p2p_messages,group_messages,system_messages表对应的type字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        0:系统消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        1:文本消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        2:图片消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        3:语音消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        4:文章消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        5:跳转消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        6:议题开始 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        7:议题结束 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        8:转发的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        9:转发的图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        10:议题结束发送的消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        11:预留 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        12:小视频消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        13:预留 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    会话类型  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sessions的type字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            type =1消息保存muc_messsges、患者的三师、家庭咨询会话 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            type=2消息保存p2p_messages、患者的名医咨询,医生间的p2p、名医咨询会话 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            type =3消息保存group_messages、行政团队聊天会话 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            type =0 消息保存system_messages 系统聊天会话 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sessions的business_type字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            business_type =1 此会话不包含患者 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            business_type =2 此会话包含患者 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sessions的status字段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            **此字段只针对议题的会话有效** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                标示当前会话是否有活跃的议题 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				### Web Socket 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				Web Socket提供页面内长连接,并且能够通过Web Socket收发消息。 
			 |