Jelajahi Sumber

feat:sop发送图片修复

caoliqin 1 Minggu lalu
induk
melakukan
f68613b22f

+ 23 - 12
fs-service/src/main/java/com/fs/app/sender/image/AppMessageImgSender.java

@@ -15,6 +15,7 @@ import com.fs.im.dto.OpenImMsgDTO;
 import com.fs.im.dto.OpenImResponseDTO;
 import com.fs.im.service.OpenIMService;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
@@ -90,29 +91,23 @@ public class AppMessageImgSender extends AbstractAppMessageSender {
         imRequest.setRecvID(receiver);
         imRequest.setContentType(SenderType.IMG.getImContentTypeCode());
         imRequest.setSessionType(1);//单聊
-        Map<String, Object> content = new HashMap<>();
-        content.put("sourcePath", imgUrl);
-        //原图信息
-        Map<String, Object> sourceMap = new HashMap<>();
         ImageInfo imageInfo = getImageInfo(imgUrl);
         if (ObjectUtil.isEmpty(imageInfo)) {
             return null;
         }
+        Map<String, Object> sourceMap = new HashMap<>();
         sourceMap.put("uuid", UUID.randomUUID().toString());
         sourceMap.put("type", imageInfo.getContentType());
         sourceMap.put("size", /*10240*/imageInfo.getSize());
         sourceMap.put("width", imageInfo.getWidth());
         sourceMap.put("height", imageInfo.getHeight());
         sourceMap.put("url", imgUrl);
-        //大图信息
-
-        //缩略图信息
-        content.put("sourcePicture", sourceMap);
-        content.put("bigPicture", sourceMap);
-        content.put("snapshotPicture", sourceMap);
 
-        OpenImMsgDTO.Content replyContent = new OpenImMsgDTO.Content();
-        replyContent.setData(JSON.toJSONString(content));
+        ImageImContent replyContent = new ImageImContent();
+        replyContent.setSourcePath(imgUrl);
+        replyContent.setSourcePicture(sourceMap);
+        replyContent.setBigPicture(sourceMap);
+        replyContent.setSnapshotPicture(sourceMap);
         imRequest.setContent(replyContent);
         return imRequest;
     }
@@ -157,6 +152,22 @@ public class AppMessageImgSender extends AbstractAppMessageSender {
         return "unknown";
     }
 
+    /**
+     * 图片消息 content,序列化后直接展开为 OpenIM 要求的结构(不包在 data 里)
+     */
+    @Data
+    @EqualsAndHashCode(callSuper = true)
+    public static class ImageImContent extends OpenImMsgDTO.Content {
+
+        private String sourcePath;
+
+        private Map<String, Object> sourcePicture;
+
+        private Map<String, Object> bigPicture;
+
+        private Map<String, Object> snapshotPicture;
+    }
+
     // 图片信息实体
     @Data
     public static class ImageInfo {