zouxuan 5 年之前
父节点
当前提交
127834749f

+ 13 - 1
mec-client-api/src/main/java/com/ym/mec/im/ImFeignService.java

@@ -1,5 +1,6 @@
 package com.ym.mec.im;
 
+import com.ym.mec.common.entity.ImPrivateMessage;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -25,7 +26,7 @@ public interface ImFeignService {
 	ImResult register(@RequestBody ImUserModel userModel);
 
 	/**
-	 * 用户注册
+	 * 用户信息修改
 	 * @param userModel
 	 * @return
 	 */
@@ -87,4 +88,15 @@ public interface ImFeignService {
 	 */
 	@PostMapping(value = "group/batchQuit")
 	Object groupBatchQuit(@RequestBody List<ImGroupModel> groupModels);
+
+	/**
+	 * 发送私聊消息
+	 * @param privateMessage
+	 * @return
+	 */
+	@PostMapping(value = "private/send")
+	//body模板
+	//{"senderId":"325","targetId":[1094986],"objectName":"RC:TxtMsg",
+	// "content":{"content":"www.baidu.com"}}
+	Object privateSend(@RequestBody ImPrivateMessage privateMessage);
 }

+ 6 - 0
mec-client-api/src/main/java/com/ym/mec/im/fallback/ImFeignServiceFallback.java

@@ -1,5 +1,6 @@
 package com.ym.mec.im.fallback;
 
+import com.ym.mec.common.entity.ImPrivateMessage;
 import org.springframework.stereotype.Component;
 
 import com.ym.mec.common.entity.ImGroupModel;
@@ -57,4 +58,9 @@ public class ImFeignServiceFallback implements ImFeignService {
     public Object groupBatchQuit(List<ImGroupModel> groupModels) {
         return null;
     }
+
+    @Override
+    public Object privateSend(ImPrivateMessage privateMessage) {
+        return null;
+    }
 }

+ 10 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/ImBaseMessage.java

@@ -0,0 +1,10 @@
+package com.ym.mec.common.entity;
+
+public abstract class ImBaseMessage {
+    public ImBaseMessage() {
+    }
+
+    public abstract String getType();
+
+    public abstract String toString();
+}

+ 81 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/ImMessageModel.java

@@ -0,0 +1,81 @@
+package com.ym.mec.common.entity;
+
+public class ImMessageModel {
+    //	发送人 Id  必填
+    private String senderId;
+    //接收人 Id  必填
+    private String[] targetId;
+    //消息类型, 分为两类: 内置消息类型 、自定义消息类型  RC:TxtMsg,RC:ImgMsg,RC:VcMsg,RC:ImgTextMsg,RC:FileMsg,RC:LBSMsg  必填
+    private String objectName;
+    //消息内容  必填
+    private ImTxtMessage content;
+    //push 内容, 分为两类 内置消息 Push 、自定义消息 Push  RC:TxtMsg,RC:ImgMsg,RC:VcMsg,RC:ImgTextMsg,RC:FileMsg,RC:LBSMsg
+    private String pushContent;
+    private String pushData;
+
+    public ImMessageModel() {
+    }
+
+    public ImMessageModel(String senderId, String[] targetId, String objectName, ImTxtMessage content, String pushContent, String pushData) {
+        this.senderId = senderId;
+        this.targetId = targetId;
+        this.objectName = objectName;
+        this.content = content;
+        this.pushContent = pushContent;
+        this.pushData = pushData;
+    }
+
+    public String[] getTargetId() {
+        return this.targetId;
+    }
+
+    public ImMessageModel setTargetId(String[] targetId) {
+        this.targetId = targetId;
+        return this;
+    }
+
+    public String getObjectName() {
+        return this.objectName;
+    }
+
+    public ImMessageModel setObjectName(String objectName) {
+        this.objectName = objectName;
+        return this;
+    }
+
+    public ImBaseMessage getContent() {
+        return this.content;
+    }
+
+    public ImMessageModel setContent(ImTxtMessage content) {
+        this.content = content;
+        return this;
+    }
+
+    public String getPushContent() {
+        return this.pushContent;
+    }
+
+    public ImMessageModel setPushContent(String pushContent) {
+        this.pushContent = pushContent;
+        return this;
+    }
+
+    public String getPushData() {
+        return this.pushData;
+    }
+
+    public ImMessageModel setPushData(String pushData) {
+        this.pushData = pushData;
+        return this;
+    }
+
+    public String getSenderId() {
+        return this.senderId;
+    }
+
+    public ImMessageModel setSenderId(String senderId) {
+        this.senderId = senderId;
+        return this;
+    }
+}

+ 114 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/ImPrivateMessage.java

@@ -0,0 +1,114 @@
+package com.ym.mec.common.entity;
+
+public class ImPrivateMessage extends ImMessageModel {
+    public String count;
+    //是否在融云服务器存储, 0: 不存储, 1: 存储, 默认: 1
+    public Integer isPersisted;
+    public Integer isCounted;
+    //是否过滤接收用户黑名单列表, 0: 不过滤 、1: 过滤,默认: 0
+    public Integer verifyBlacklist;
+    //发送者自己是否接收此条消息, 0: 不接收, 1: 接收, 默认: 0
+    public Integer isIncludeSender;
+    public Integer contentAvailable;
+
+    public ImPrivateMessage() {
+    }
+
+    public ImPrivateMessage(String senderId, String[] targetId, String objectName, ImTxtMessage content, String pushContent, String pushData, String count, Integer isPersisted, Integer isCounted, Integer verifyBlacklist, Integer isIncludeSender, Integer contentAvailable) {
+        super(senderId, targetId, objectName, content, pushContent, pushData);
+        this.count = count;
+        this.isPersisted = isPersisted;
+        this.isCounted = isCounted;
+        this.verifyBlacklist = verifyBlacklist;
+        this.isIncludeSender = isIncludeSender;
+        this.contentAvailable = contentAvailable;
+    }
+
+    public ImPrivateMessage setSenderId(String senderId) {
+        super.setSenderId(senderId);
+        return this;
+    }
+
+    public String[] getTargetId() {
+        return super.getTargetId();
+    }
+
+    public ImPrivateMessage setTargetId(String[] targetId) {
+        super.setTargetId(targetId);
+        return this;
+    }
+
+    public ImPrivateMessage setContent(ImTxtMessage content) {
+        super.setContent(content);
+        return this;
+    }
+
+    public ImPrivateMessage setPushContent(String pushContent) {
+        super.setPushContent(pushContent);
+        return this;
+    }
+
+    public ImPrivateMessage setPushData(String pushData) {
+        super.setPushData(pushData);
+        return this;
+    }
+
+    public String getCount() {
+        return this.count;
+    }
+
+    public ImPrivateMessage setCount(String count) {
+        this.count = count;
+        return this;
+    }
+
+    public Integer getVerifyBlacklist() {
+        return this.verifyBlacklist;
+    }
+
+    public ImPrivateMessage setVerifyBlacklist(Integer verifyBlacklist) {
+        this.verifyBlacklist = verifyBlacklist;
+        return this;
+    }
+
+    public Integer getIsPersisted() {
+        return this.isPersisted;
+    }
+
+    public ImPrivateMessage setIsPersisted(Integer isPersisted) {
+        this.isPersisted = isPersisted;
+        return this;
+    }
+
+    public Integer getIsCounted() {
+        return this.isCounted;
+    }
+
+    public ImPrivateMessage setIsCounted(Integer isCounted) {
+        this.isCounted = isCounted;
+        return this;
+    }
+
+    public Integer getIsIncludeSender() {
+        return this.isIncludeSender;
+    }
+
+    public ImPrivateMessage setIsIncludeSender(Integer isIncludeSender) {
+        this.isIncludeSender = isIncludeSender;
+        return this;
+    }
+
+    public ImPrivateMessage setObjectName(String objectName) {
+        super.setObjectName(objectName);
+        return this;
+    }
+
+    public Integer getContentAvailable() {
+        return this.contentAvailable;
+    }
+
+    public ImPrivateMessage setContentAvailable(Integer contentAvailable) {
+        this.contentAvailable = contentAvailable;
+        return this;
+    }
+}

+ 38 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/ImTxtMessage.java

@@ -0,0 +1,38 @@
+package com.ym.mec.common.entity;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class ImTxtMessage extends ImBaseMessage {
+    private String content = "";
+    private String extra = "";
+    private static final transient String TYPE = "RC:TxtMsg";
+
+    public ImTxtMessage(String content, String extra) {
+        this.content = content;
+        this.extra = extra;
+    }
+
+    public String getType() {
+        return "RC:TxtMsg";
+    }
+
+    public String getContent() {
+        return this.content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public String getExtra() {
+        return this.extra;
+    }
+
+    public void setExtra(String extra) {
+        this.extra = extra;
+    }
+
+    public String toString() {
+        return JSONObject.toJSONString(this);
+    }
+}

+ 1 - 1
mec-im/pom.xml

@@ -90,7 +90,7 @@
     <dependency>
       <groupId>cn.rongcloud.im</groupId>
       <artifactId>server-sdk-java</artifactId>
-      <version>3.0.6</version>
+      <version>3.1.4</version>
     </dependency>
     <dependency>
       <groupId>org.springframework.cloud</groupId>

+ 12 - 1
mec-im/src/main/java/com/ym/controller/PrivateController.java

@@ -1,6 +1,10 @@
 package com.ym.controller;
 
+import com.ym.mec.common.entity.ImBaseMessage;
+import com.ym.mec.common.entity.ImPrivateMessage;
+import com.ym.mec.common.entity.ImTxtMessage;
 import com.ym.service.MessageService;
+import io.rong.messages.TxtMessage;
 import io.rong.models.message.PrivateMessage;
 import io.rong.models.message.RecallMessage;
 import io.rong.models.message.TemplateMessage;
@@ -21,7 +25,14 @@ public class PrivateController {
     MessageService messageService;
 
     @RequestMapping(value = "/send", method = RequestMethod.POST)
-    public Object send(@RequestBody PrivateMessage privateMessage) throws Exception {
+    public Object send(@RequestBody ImPrivateMessage imPrivateMessage) throws Exception {
+        PrivateMessage privateMessage = new PrivateMessage();
+        ImTxtMessage content = (ImTxtMessage)imPrivateMessage.getContent();
+        TxtMessage txtMessage = new TxtMessage(content.getContent(),content.getExtra());
+        privateMessage.setContent(txtMessage);
+        privateMessage.setTargetId(imPrivateMessage.getTargetId());
+        privateMessage.setSenderId(imPrivateMessage.getSenderId());
+        privateMessage.setObjectName(imPrivateMessage.getObjectName());
         return messageService.privateSend(privateMessage);
     }
 

+ 5 - 1
mec-im/src/main/java/com/ym/service/Impl/MessageServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ym.service.Impl;
 
 import com.ym.service.MessageService;
+import io.rong.RongCloud;
 import io.rong.methods.message._private.Private;
 import io.rong.methods.message.chatroom.Chatroom;
 import io.rong.methods.message.group.Group;
@@ -25,7 +26,10 @@ public class MessageServiceImpl implements MessageService {
     private String appSecret;
 
     private Private getPrivate(){
-        return new Private(appKey,appSecret);
+        RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
+        Private aPrivate = new Private(appKey, appSecret);
+        aPrivate.setRongCloud(rongCloud);
+        return aPrivate;
     }
     private Group getGroup(){
         return new Group(appKey,appSecret);

+ 5 - 10
mec-web/src/main/java/com/ym/mec/web/controller/APIController.java

@@ -1,21 +1,16 @@
 package com.ym.mec.web.controller;
 
-import com.ym.mec.common.exception.BizException;
-import io.swagger.annotations.Api;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
 import com.ym.mec.biz.dal.dao.TeacherDao;
 import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 import com.ym.mec.biz.dal.entity.Teacher;
 import com.ym.mec.biz.service.PracticeLessonApplyService;
 import com.ym.mec.common.controller.BaseController;
-
-import javax.swing.plaf.basic.BasicIconFactory;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 @RequestMapping("api")
 @Api(tags = "对外接口")