MessageServiceImpl.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.ym.service.Impl;
  2. import com.ym.service.MessageService;
  3. import io.rong.methods.message._private.Private;
  4. import io.rong.methods.message.chatroom.Chatroom;
  5. import io.rong.methods.message.group.Group;
  6. import io.rong.methods.message.history.History;
  7. import io.rong.methods.message.system.MsgSystem;
  8. import io.rong.methods.push.Push;
  9. import io.rong.models.Result;
  10. import io.rong.models.message.*;
  11. import io.rong.models.push.BroadcastModel;
  12. import io.rong.models.push.PushModel;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.stereotype.Service;
  16. @Slf4j
  17. @Service
  18. public class MessageServiceImpl implements MessageService {
  19. @Value("${cn.rongcloud.im.appkey}")
  20. private String appKey;
  21. @Value("${cn.rongcloud.im.secret}")
  22. private String appSecret;
  23. private Private getPrivate(){
  24. return new Private(appKey,appSecret);
  25. }
  26. private Group getGroup(){
  27. return new Group(appKey,appSecret);
  28. }
  29. private Chatroom getChatroom(){
  30. return new Chatroom(appKey,appSecret);
  31. }
  32. private MsgSystem getMsgSystem(){
  33. return new MsgSystem(appKey,appSecret);
  34. }
  35. private History getHistory(){
  36. return new History(appKey,appSecret);
  37. }
  38. private Push getPush(){
  39. return new Push(appKey,appSecret);
  40. }
  41. @Override
  42. public Result privateSend(PrivateMessage privateMessage) throws Exception {
  43. return getPrivate().send(privateMessage);
  44. }
  45. @Override
  46. public Result privateRecall(RecallMessage recallMessage) throws Exception {
  47. return getPrivate().recall(recallMessage);
  48. }
  49. @Override
  50. public Result privateSendTemplate(TemplateMessage templateMessage) throws Exception {
  51. return getPrivate().sendTemplate(templateMessage);
  52. }
  53. @Override
  54. public Result groupSend(GroupMessage groupMessage) throws Exception {
  55. return getGroup().send(groupMessage);
  56. }
  57. @Override
  58. public Result groupSendDirection(GroupMessage groupMessage) throws Exception {
  59. return getGroup().sendDirection(groupMessage);
  60. }
  61. @Override
  62. public Result groupSendMention(MentionMessage mentionMessage) throws Exception {
  63. return getGroup().sendMention(mentionMessage);
  64. }
  65. @Override
  66. public Result groupRecall(RecallMessage recallMessage) throws Exception {
  67. return getGroup().recall(recallMessage);
  68. }
  69. @Override
  70. public Result chatroomSend(ChatroomMessage chatroomMessage) throws Exception {
  71. return getChatroom().send(chatroomMessage);
  72. }
  73. @Override
  74. public Result chatroomBroadcast(ChatroomMessage chatroomMessage) throws Exception {
  75. return getChatroom().broadcast(chatroomMessage);
  76. }
  77. @Override
  78. public Result systemSend(SystemMessage systemMessage) throws Exception {
  79. return getMsgSystem().send(systemMessage);
  80. }
  81. @Override
  82. public Result systemBroadcast(BroadcastMessage broadcastMessage) throws Exception {
  83. return getMsgSystem().broadcast(broadcastMessage);
  84. }
  85. @Override
  86. public Result systemSendTemplate(TemplateMessage templateMessage) throws Exception {
  87. return getMsgSystem().sendTemplate(templateMessage);
  88. }
  89. @Override
  90. public Result historyGet(String date) throws Exception {
  91. return getHistory().get(date);
  92. }
  93. @Override
  94. public Result historyRemove(String date) throws Exception {
  95. return getHistory().remove(date);
  96. }
  97. @Override
  98. public Result pushPush(PushModel pushModel) throws Exception {
  99. return getPush().push(pushModel);
  100. }
  101. @Override
  102. public Result pushMessage(BroadcastModel broadcastModel) throws Exception {
  103. return getPush().message(broadcastModel);
  104. }
  105. }