Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

165 řádky
5.2 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 IMMsgIBLL iMMsgIBLL = new IMMsgBLL();
  28. private IMContactsIBLL iMContactsIBLL = new IMContactsBLL();
  29. /// <summary>
  30. /// 获取最近联系人列表
  31. /// <summary>
  32. /// <returns></returns>
  33. public Response GetContactsList(dynamic _)
  34. {
  35. string time = this.GetReqData();// 获取模板请求数据
  36. DateTime beginTime = DateTime.Now;
  37. var data = iMContactsIBLL.GetList(userInfo.userId,DateTime.Parse(time));
  38. var jsondata = new
  39. {
  40. data = data,
  41. time = beginTime
  42. };
  43. return Success(jsondata);
  44. }
  45. /// <summary>
  46. /// 发送消息
  47. /// </summary>
  48. /// <param name="_"></param>
  49. /// <returns></returns>
  50. public Response SendMsg(dynamic _)
  51. {
  52. MsgModel msyModel = this.GetReqData<MsgModel>();// 获取模板请求数据
  53. IMMsgEntity entity = new IMMsgEntity();
  54. entity.F_SendUserId = userInfo.userId;
  55. entity.F_RecvUserId = msyModel.userId;
  56. entity.F_Content = msyModel.content;
  57. iMMsgIBLL.SaveEntity(entity);
  58. // 向即时消息服务器发送一条信息
  59. SendHubs.callMethod("sendMsg2", userInfo.userId, msyModel.userId, msyModel.content, 0);
  60. var jsonData = new
  61. {
  62. time = entity.F_CreateDate,
  63. msgId = entity.F_MsgId
  64. };
  65. return Success(jsonData);
  66. }
  67. /// <summary>
  68. /// 添加一条最近的联系人
  69. /// </summary>
  70. /// <param name="_"></param>
  71. /// <returns></returns>
  72. public Response AddContact(dynamic _)
  73. {
  74. string otherUserId = this.GetReqData();// 获取模板请求数据
  75. IMContactsEntity entity = new IMContactsEntity();
  76. entity.F_MyUserId = userInfo.userId;
  77. entity.F_OtherUserId = otherUserId;
  78. iMContactsIBLL.SaveEntity(entity);
  79. return Success("添加成功!");
  80. }
  81. /// <summary>
  82. /// 更新消息读取状态
  83. /// </summary>
  84. /// <param name="_"></param>
  85. /// <returns></returns>
  86. public Response UpdateContactState(dynamic _)
  87. {
  88. string otherUserId = this.GetReqData();// 获取模板请求数据
  89. iMContactsIBLL.UpdateState(userInfo.userId, otherUserId);
  90. return Success("更新成功!");
  91. }
  92. /// <summary>
  93. /// 获取最近10条聊天记录
  94. /// </summary>
  95. /// <param name="_"></param>
  96. /// <returns></returns>
  97. public Response GetMsgList(dynamic _) {
  98. string otherUserId = this.GetReqData();// 获取模板请求数据
  99. var data = iMMsgIBLL.GetList(userInfo.userId, otherUserId);
  100. return Success(data);
  101. }
  102. /// <summary>
  103. /// 获取小于某时间点的5条记录
  104. /// </summary>
  105. /// <param name="_"></param>
  106. /// <returns></returns>
  107. public Response GetMsgList1(dynamic _)
  108. {
  109. MsgReqModel msgReqModel = this.GetReqData<MsgReqModel>();// 获取模板请求数据
  110. var data = iMMsgIBLL.GetListByTime(userInfo.userId, msgReqModel.otherUserId, msgReqModel.time);
  111. return Success(data);
  112. }
  113. /// <summary>
  114. /// 获取大于某时间点的所有数据
  115. /// </summary>
  116. /// <param name="_"></param>
  117. /// <returns></returns>
  118. public Response GetMsgList2(dynamic _)
  119. {
  120. MsgReqModel msgReqModel = this.GetReqData<MsgReqModel>();// 获取模板请求数据
  121. var data = iMMsgIBLL.GetListByTime2(userInfo.userId, msgReqModel.otherUserId, msgReqModel.time);
  122. return Success(data);
  123. }
  124. }
  125. public class MsgModel {
  126. /// <summary>
  127. /// 发送给人员Id
  128. /// </summary>
  129. public string userId { get; set; }
  130. /// <summary>
  131. /// 消息内容
  132. /// </summary>
  133. public string content { get; set; }
  134. }
  135. public class MsgReqModel
  136. {
  137. /// <summary>
  138. /// 发送给人员Id
  139. /// </summary>
  140. public string otherUserId { get; set; }
  141. /// <summary>
  142. /// 消息内容
  143. /// </summary>
  144. public DateTime time { get; set; }
  145. }
  146. }