Browse Source

封面添加播放按钮水印实验

wangyunpeng 1 week ago
parent
commit
afc3a7cd7b

+ 23 - 4
api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComSendMsgJob.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.api.job.wecom.thirdpart;
 
 import com.alibaba.fastjson.JSONObject;
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt;
 import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComMsgMapper;
@@ -13,6 +14,7 @@ import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComMsgExample;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoom;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff;
 import com.tzld.piaoquan.api.service.WeComThirdPartyService;
+import com.tzld.piaoquan.api.util.CdnUtil;
 import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
 import com.tzld.piaoquan.growth.common.model.po.Staff;
 import com.tzld.piaoquan.growth.common.service.MessageAttachmentService;
@@ -52,6 +54,8 @@ public class WeComSendMsgJob {
     private Integer duplicateDays;
     @Value("${send.room.msg.video.num:2}")
     private Integer videoNum;
+    @ApolloJsonValue("${send.room.msg.test.roomList:[\"10724205295120197\"]}")
+    private List<String> testRoomList;
 
     private final static ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.SECONDS,
             new LinkedBlockingQueue<>(1000),
@@ -75,7 +79,7 @@ public class WeComSendMsgJob {
                         List<CgiReplyBucketData> cgiReplyBucketDataList = getCgiReplyBucketData(room.getThirdRoomId(), staff);
                         for (CgiReplyBucketData cgiReplyBucketData : cgiReplyBucketDataList) {
                             // build发送体
-                            SendAppMsgRequest request = buildSendAppMsgRequest(cgiReplyBucketData, staff, room.getThirdRoomId());
+                            SendAppMsgRequest request = buildSendAppMsgRequest(cgiReplyBucketData, staff, room);
                             // 发送消息
                             weComThirdPartyService.sendAppMsg(request);
                             // 存储消息
@@ -90,7 +94,8 @@ public class WeComSendMsgJob {
 
     private SendAppMsgRequest buildSendAppMsgRequest(CgiReplyBucketData cgiReplyBucketData,
                                                      ThirdPartWeComStaff staff,
-                                                     String thirdRoomId) {
+                                                     ThirdPartWeComRoom room) {
+        String thirdRoomId = room.getThirdRoomId();
         SendAppMsgRequest request = new SendAppMsgRequest();
         request.setUuid(staff.getThirdUuid());
         request.setSend_userid(Long.valueOf(thirdRoomId));
@@ -101,11 +106,16 @@ public class WeComSendMsgJob {
         request.setTitle("票圈 l 3亿人喜欢的视频平台");
         request.setWeappIconUrl("http://rescdn.yishihui.com/temp/1755515422185_%E7%A5%A8%E5%9C%88Vlog_logo.jpg");
         // 填充视频信息
+        String coverUrl = cgiReplyBucketData.getCoverUrl();
+        // 实验 封面添加播放按钮水印
+        if (testRoomList.contains(thirdRoomId)) {
+            coverUrl = addPlayWatermark(cgiReplyBucketData.getCoverUrl());
+        }
         request.setDesc(cgiReplyBucketData.getTitle());
         request.setPagepath(cgiReplyBucketData.getMiniPagePath());
         CdnUploadImgLinkRequest cdnUploadImgLinkRequest = new CdnUploadImgLinkRequest();
         cdnUploadImgLinkRequest.setUuid(staff.getThirdUuid());
-        cdnUploadImgLinkRequest.setUrl(cgiReplyBucketData.getCoverUrl());
+        cdnUploadImgLinkRequest.setUrl(coverUrl);
         CdnUploadImgLinkResponse uploadResponse = weComThirdPartyService.cdnUploadImgLink(cdnUploadImgLinkRequest);
         request.setCdnkey(uploadResponse.getCdn_key());
         request.setMd5(uploadResponse.getMd5());
@@ -114,6 +124,15 @@ public class WeComSendMsgJob {
         return request;
     }
 
+    private String addPlayWatermark(String coverUrl) {
+        if (!coverUrl.startsWith(CdnUtil.VIDEO_CDN_URL_HOST)) {
+            return coverUrl;
+        }
+        String waterMark = "?x-oss-process=image/resize,m_fill,w_600,h_480,limit_0/format,jpg/watermark,image_eXNoL3BpYy93YXRlcm1hcmtlci9pY29uX3BsYXlfd2hpdGUucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLHdfMTQ0,g_center";
+        coverUrl = coverUrl.substring(0, coverUrl.indexOf("?"));
+        return coverUrl + waterMark;
+    }
+
     private List<CgiReplyBucketData> getCgiReplyBucketData(String roomId, ThirdPartWeComStaff thirdPartWeComStaff) {
         String dt = planMapperExt.getVideoMaxDt();
         String datastatDt = planMapperExt.getVideoDatastatMaxDt();
@@ -134,7 +153,7 @@ public class WeComSendMsgJob {
             Staff staff = new Staff();
             staff.setCarrierId(String.valueOf(thirdPartWeComStaff.getThirdStaffId()));
             staff.setRemark(thirdPartWeComStaff.getName());
-            String page = messageAttachmentService.getPage(staff, video.getVideoId(), "企微", "社群");
+            String page = messageAttachmentService.getPageNoCache(staff, video.getVideoId(), "企微", "社群");
 
             CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
             cgiReplyBucketData.setMiniVideoId(video.getVideoId());