Kaynağa Gözat

Merge branch 'dev-xym-add-pyq' of Server/growth-manager into master

xueyiming 2 hafta önce
ebeveyn
işleme
109fff88e2

+ 3 - 2
api-module/src/main/java/com/tzld/piaoquan/api/controller/MessageController.java

@@ -43,9 +43,10 @@ public class MessageController {
                                                  @RequestParam(required = false) String page,
                                                  @RequestParam(required = false) String title,
                                                  @RequestParam(required = false) String desc,
-                                                 @RequestParam(required = false) String appId
+                                                 @RequestParam(required = false) String appId,
+                                                 @RequestParam(required = false) Integer extType
     ) {
-        return messageAttachmentService.createAttachment(type, file, url, picUrl, page, title, desc, appId);
+        return messageAttachmentService.createAttachment(type, file, url, picUrl, page, title, desc, appId, extType);
     }
 
 }

+ 3 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/common/constant/WeComConstant.java

@@ -23,6 +23,9 @@ public interface WeComConstant {
     //上传临时素材
     String POST_WE_COM_MEDIA_UPLOAD = "https://qyapi.weixin.qq.com/cgi-bin/media/upload";
 
+    //上传附件素材
+    String POST_WE_COM_MEDIA_UPLOAD_ATTACHMENT = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_attachment";
+
     //获取客户列表
     String GET_WE_COM_EXTERNAL_CONTACT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list";
 

+ 12 - 6
common-module/src/main/java/com/tzld/piaoquan/growth/common/service/Impl/MessageAttachmentServiceImpl.java

@@ -48,6 +48,7 @@ import static com.tzld.piaoquan.growth.common.common.constant.OtherServerURL.POS
 import static com.tzld.piaoquan.growth.common.common.constant.OtherServerURL.POST_VIDEO_DETAIL_URL;
 import static com.tzld.piaoquan.growth.common.common.constant.TimeConstant.MILLISECOND_DAY;
 import static com.tzld.piaoquan.growth.common.common.constant.WeComConstant.POST_WE_COM_MEDIA_UPLOAD;
+import static com.tzld.piaoquan.growth.common.common.constant.WeComConstant.POST_WE_COM_MEDIA_UPLOAD_ATTACHMENT;
 
 
 @Slf4j
@@ -507,7 +508,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
     }
 
     @Override
-    public CommonResponse<Long> createAttachment(Integer type, MultipartFile file, String url, String picUrl, String page, String title, String desc, String appId) {
+    public CommonResponse<Long> createAttachment(Integer type, MultipartFile file, String url, String picUrl, String page, String title, String desc, String appId, Integer extType) {
         if (type == null) {
             return CommonResponse.create(500, "附件类型不能为空");
         }
@@ -521,7 +522,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             if (file == null || file.isEmpty()) {
                 return CommonResponse.create(500, "封面文件不能为空");
             }
-            String mediaId = uploadFile(file, "image");
+            String mediaId = uploadFile(file, "image", extType);
             if (StringUtils.isEmpty(mediaId)) {
                 return CommonResponse.create(500, "封面上传失败");
             }
@@ -566,7 +567,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             if (file == null || file.isEmpty()) {
                 return CommonResponse.create(500, "图片不能为空");
             }
-            String mediaId = uploadFile(file, "image");
+            String mediaId = uploadFile(file, "image", extType);
             if (StringUtils.isEmpty(mediaId)) {
                 return CommonResponse.create(500, "图片上传失败");
             }
@@ -581,7 +582,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             if (file == null || file.isEmpty()) {
                 return CommonResponse.create(500, "视频不能为空");
             }
-            String mediaId = uploadFile(file, "video");
+            String mediaId = uploadFile(file, "video", extType);
             if (StringUtils.isEmpty(mediaId)) {
                 return CommonResponse.create(500, "视频上传失败");
             }
@@ -594,7 +595,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
         return CommonResponse.create(500, "没有对应类型");
     }
 
-    private String uploadFile(MultipartFile multipartFile, String fileType) {
+    private String uploadFile(MultipartFile multipartFile, String fileType, Integer extType) {
         String mediaId = null;
         try {
             String extension = FileUtils.getExtension(multipartFile);
@@ -612,7 +613,12 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             File file = new File(filePath);
             //暂时不区分主体
             String weComAccessToken = weComAccessTokenService.getWeComAccessToken(1L);
-            String url = String.format(POST_WE_COM_MEDIA_UPLOAD + "?access_token=%s&type=%s", weComAccessToken, fileType);
+            String url;
+            if (extType != null && extType == 1) {
+                url = String.format(POST_WE_COM_MEDIA_UPLOAD_ATTACHMENT + "?access_token=%s&media_type=%s&attachment_type=1", weComAccessToken, fileType);
+            } else {
+                url = String.format(POST_WE_COM_MEDIA_UPLOAD + "?access_token=%s&type=%s", weComAccessToken, fileType);
+            }
             String res = httpPoolClient.post(url, file);
 
             JSONObject jsonObject = JSONObject.parseObject(res);

+ 1 - 1
common-module/src/main/java/com/tzld/piaoquan/growth/common/service/MessageAttachmentService.java

@@ -29,5 +29,5 @@ public interface MessageAttachmentService {
 
     String getPage(String channel, String carrierId, String scene, String putTypeOne, String putTypeTwo, String putTypeThree, Long videoId);
 
-    CommonResponse<Long> createAttachment(Integer type, MultipartFile file, String url, String picUrl, String page, String title, String desc, String appId);
+    CommonResponse<Long> createAttachment(Integer type, MultipartFile file, String url, String picUrl, String page, String title, String desc, String appId, Integer extType);
 }

+ 2 - 3
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComMomentDataJob.java

@@ -55,8 +55,8 @@ public class WeComMomentDataJob {
             JSONObject text = new JSONObject();
             if (StringUtils.isNotEmpty(momentSendMessage.getContent())) {
                 text.put("content", momentSendMessage.getContent());
+                jsonObject.put("text", text);
             }
-            jsonObject.put("text", text);
             String attachmentIds = momentSendMessage.getAttachmentIds();
             JSONArray attachments = new JSONArray();
             if (StringUtils.isNotEmpty(attachmentIds)) {
@@ -70,8 +70,7 @@ public class WeComMomentDataJob {
                                 JSONObject linkAttachment = new JSONObject();
                                 JSONObject link = new JSONObject();
                                 link.put("title", messageAttachment.getTitle());
-                                link.put("picurl", messageAttachment.getPicUrl());
-                                link.put("desc", messageAttachment.getDesc());
+                                link.put("media_id", messageAttachment.getMediaId());
                                 link.put("url", messageAttachment.getUrl());
                                 linkAttachment.put("msgtype", "link");
                                 linkAttachment.put("link", link);