Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

168 lignes
5.3 KiB

  1. using Learun.Application.IM;
  2. using Learun.Util;
  3. using Nancy;
  4. using System;
  5. namespace Learun.Application.WebApi.Modules
  6. {
  7. /// <summary>
  8. /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园
  9. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  10. /// 创建人:数字化智慧校园-框架开发组
  11. /// 日 期:2018.06.14
  12. /// 描 述:即时通讯接口
  13. /// </summary>
  14. public class IMApi : BaseApi
  15. {
  16. public IMApi()
  17. : base("/learun/adms/im")
  18. {
  19. Get["/contacts"] = GetContactsList;
  20. Post["/send"] = SendMsg;
  21. Post["/addcontact"] = AddContact;
  22. Post["/updete"] = UpdateContactState;
  23. Get["/msg/lastlist"] = GetMsgList;
  24. Get["/msg/list"] = GetMsgList1;
  25. Get["/msg/list2"] = GetMsgList2;
  26. }
  27. private IMSysUserIBLL iMSysUserIBLL = new IMSysUserBLL();
  28. private IMMsgIBLL iMMsgIBLL = new IMMsgBLL();
  29. private IMContactsIBLL iMContactsIBLL = new IMContactsBLL();
  30. /// <summary>
  31. /// 获取最近联系人列表
  32. /// <summary>
  33. /// <returns></returns>
  34. public Response GetContactsList(dynamic _)
  35. {
  36. var sysUserList = iMSysUserIBLL.GetList("");
  37. string time = this.GetReqData();// 获取模板请求数据
  38. DateTime beginTime = DateTime.Now;
  39. var data = iMContactsIBLL.GetList(userInfo.userId,DateTime.Parse(time));
  40. var jsondata = new
  41. {
  42. data = data,
  43. sysUserList,
  44. time = beginTime
  45. };
  46. return Success(jsondata);
  47. }
  48. /// <summary>
  49. /// 发送消息
  50. /// </summary>
  51. /// <param name="_"></param>
  52. /// <returns></returns>
  53. public Response SendMsg(dynamic _)
  54. {
  55. MsgModel msyModel = this.GetReqData<MsgModel>();// 获取模板请求数据
  56. IMMsgEntity entity = new IMMsgEntity();
  57. entity.F_SendUserId = userInfo.userId;
  58. entity.F_RecvUserId = msyModel.userId;
  59. entity.F_Content = msyModel.content;
  60. iMMsgIBLL.SaveEntity(entity);
  61. // 向即时消息服务器发送一条信息
  62. SendHubs.callMethod("sendMsg2", userInfo.userId, msyModel.userId, msyModel.content, 0);
  63. var jsonData = new
  64. {
  65. time = entity.F_CreateDate,
  66. msgId = entity.F_MsgId
  67. };
  68. return Success(jsonData);
  69. }
  70. /// <summary>
  71. /// 添加一条最近的联系人
  72. /// </summary>
  73. /// <param name="_"></param>
  74. /// <returns></returns>
  75. public Response AddContact(dynamic _)
  76. {
  77. string otherUserId = this.GetReqData();// 获取模板请求数据
  78. IMContactsEntity entity = new IMContactsEntity();
  79. entity.F_MyUserId = userInfo.userId;
  80. entity.F_OtherUserId = otherUserId;
  81. iMContactsIBLL.SaveEntity(entity);
  82. return Success("添加成功!");
  83. }
  84. /// <summary>
  85. /// 更新消息读取状态
  86. /// </summary>
  87. /// <param name="_"></param>
  88. /// <returns></returns>
  89. public Response UpdateContactState(dynamic _)
  90. {
  91. string otherUserId = this.GetReqData();// 获取模板请求数据
  92. iMContactsIBLL.UpdateState(userInfo.userId, otherUserId);
  93. return Success("更新成功!");
  94. }
  95. /// <summary>
  96. /// 获取最近10条聊天记录
  97. /// </summary>
  98. /// <param name="_"></param>
  99. /// <returns></returns>
  100. public Response GetMsgList(dynamic _) {
  101. string otherUserId = this.GetReqData();// 获取模板请求数据
  102. var data = iMMsgIBLL.GetList(userInfo.userId, otherUserId);
  103. return Success(data);
  104. }
  105. /// <summary>
  106. /// 获取小于某时间点的5条记录
  107. /// </summary>
  108. /// <param name="_"></param>
  109. /// <returns></returns>
  110. public Response GetMsgList1(dynamic _)
  111. {
  112. MsgReqModel msgReqModel = this.GetReqData<MsgReqModel>();// 获取模板请求数据
  113. var data = iMMsgIBLL.GetListByTime(userInfo.userId, msgReqModel.otherUserId, msgReqModel.time);
  114. return Success(data);
  115. }
  116. /// <summary>
  117. /// 获取大于某时间点的所有数据
  118. /// </summary>
  119. /// <param name="_"></param>
  120. /// <returns></returns>
  121. public Response GetMsgList2(dynamic _)
  122. {
  123. MsgReqModel msgReqModel = this.GetReqData<MsgReqModel>();// 获取模板请求数据
  124. var data = iMMsgIBLL.GetListByTime2(userInfo.userId, msgReqModel.otherUserId, msgReqModel.time);
  125. return Success(data);
  126. }
  127. }
  128. public class MsgModel {
  129. /// <summary>
  130. /// 发送给人员Id
  131. /// </summary>
  132. public string userId { get; set; }
  133. /// <summary>
  134. /// 消息内容
  135. /// </summary>
  136. public string content { get; set; }
  137. }
  138. public class MsgReqModel
  139. {
  140. /// <summary>
  141. /// 发送给人员Id
  142. /// </summary>
  143. public string otherUserId { get; set; }
  144. /// <summary>
  145. /// 消息内容
  146. /// </summary>
  147. public DateTime time { get; set; }
  148. }
  149. }