Procházet zdrojové kódy

Merge remote-tracking branch 'origin/test' into test

syh před 5 roky
rodič
revize
bb21ae4c9b

+ 54 - 48
module-common/src/main/java/cn/com/ctop/common/module/utils/CloudVideoProcessUtil.java

@@ -37,12 +37,12 @@ import java.util.UUID;
 @PropertySource("classpath:config.properties")
 public class CloudVideoProcessUtil {
 
-    private static RestTemplate restTemplate=new RestTemplate();
+    private static RestTemplate restTemplate = new RestTemplate();
 
     private static Logger logger = LoggerFactory.getLogger(CloudVideoProcessUtil.class);
 
-    private static final String SECRET_ID="AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets";
-    private static final String SECRET_KEY="tXzuwMfplTTK3c9GFUyETilasvQfePu9";
+    private static final String SECRET_ID = "AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets";
+    private static final String SECRET_KEY = "tXzuwMfplTTK3c9GFUyETilasvQfePu9";
     private static final String ENDPOINT = "mps.tencentcloudapi.com";
     private static final String COS_LOCATION = "ap-chongqing";
     private static final String COS_BUCKET_MEDIA = "media-1301855440";
@@ -85,7 +85,7 @@ public class CloudVideoProcessUtil {
         CosInputInfo cosInputInfo = new CosInputInfo();
         cosInputInfo.setRegion(COS_LOCATION);
         cosInputInfo.setBucket(COS_BUCKET_MEDIA);
-        cosInputInfo.setObject("/"+videoPath);
+        cosInputInfo.setObject("/" + videoPath);
         MediaInputInfo mediaInputInfo = new MediaInputInfo();
         mediaInputInfo.setType("COS");
         mediaInputInfo.setCosInputInfo(cosInputInfo);
@@ -112,12 +112,13 @@ public class CloudVideoProcessUtil {
     }
 
     /**
-     *  查询数据万象任务状态
+     * 查询数据万象任务状态
+     *
      * @return
      */
-    public static Map getMediaJobsResponse(String jobId){
-        String auth =generateAuth(SECRET_ID,SECRET_KEY,"/jobs/"+jobId,HttpMethodName.GET);
-        if(auth.isEmpty()){
+    public static Map getMediaJobsResponse(String jobId) {
+        String auth = generateAuth(SECRET_ID, SECRET_KEY, "/jobs/" + jobId, HttpMethodName.GET);
+        if (auth.isEmpty()) {
             logger.error("腾讯云Authorization获取失败");
         }
         //请求media-1301855440.ci.ap-chongqing.myqcloud.com/jobs/jobId 接口
@@ -126,25 +127,26 @@ public class CloudVideoProcessUtil {
         HttpEntity<String> requestEntity = new HttpEntity<>(headers);
         String response = null;
         try {
-            response = restTemplate.exchange(CosConstant.URL_JOBS+"/"+jobId,HttpMethod.GET,requestEntity,String.class).getBody();
+            response = restTemplate.exchange(CosConstant.URL_JOBS + "/" + jobId, HttpMethod.GET, requestEntity, String.class).getBody();
         } catch (RestClientException e) {
             logger.error(e.getMessage());
         }
-        Map<String,Object> mapResp= XmlToMapUtil.multilayerXmlToMap(response);
-        Map JobsDetail= (Map)((Map)mapResp.get("Response")).get("JobsDetail");
-        if(JobsDetail.get("Code").equals("Success")){
+        Map<String, Object> mapResp = XmlToMapUtil.multilayerXmlToMap(response);
+        Map JobsDetail = (Map) ((Map) mapResp.get("Response")).get("JobsDetail");
+        if (JobsDetail.get("Code").equals("Success")) {
             return JobsDetail;
-        }else {
+        } else {
             return MapUtil.newHashMap();
         }
     }
+
     /**
      * 数据万象发起视频抽帧处理请求
      */
-    public static Map<String,Object> videoCutFrameHandle(String videoPath, String outputPath) {
-        Map<String,Object> result=new HashMap<>();
-        String auth =generateAuth(SECRET_ID,SECRET_KEY,"/jobs",HttpMethodName.POST);
-        if(auth.isEmpty()){
+    public static Map<String, Object> videoCutFrameHandle(String videoPath, String outputPath) {
+        Map<String, Object> result = new HashMap<>();
+        String auth = generateAuth(SECRET_ID, SECRET_KEY, "/jobs", HttpMethodName.POST);
+        if (auth.isEmpty()) {
             logger.error("腾讯云Authorization获取失败");
         }
         //拼接请求数据万象jobs接口的参数
@@ -174,35 +176,36 @@ public class CloudVideoProcessUtil {
         } catch (RestClientException e) {
             logger.error(e.getMessage());
         }
-        Map<String,Object> mapResp= XmlToMapUtil.multilayerXmlToMap(response);
-        Map JobsDetail= (Map)((Map)mapResp.get("Response")).get("JobsDetail");
-        if(JobsDetail.get("Code").equals("Success")){
-            Map jobStatusMap=null;
-            for(int i=0;i<10;i++){
+        Map<String, Object> mapResp = XmlToMapUtil.multilayerXmlToMap(response);
+        Map JobsDetail = (Map) ((Map) mapResp.get("Response")).get("JobsDetail");
+        if (JobsDetail.get("Code").equals("Success")) {
+            Map jobStatusMap = null;
+            for (int i = 0; i < 10; i++) {
                 try {
                     Thread.sleep(1000);
                 } catch (InterruptedException e) {
                     logger.error(e.getMessage());
                 }
-                jobStatusMap=getMediaJobsResponse(JobsDetail.get("JobId").toString());
-                if(jobStatusMap.get("State").equals("Success")){
+                jobStatusMap = getMediaJobsResponse(JobsDetail.get("JobId").toString());
+                if (jobStatusMap.get("State").equals("Success")) {
                     break;
                 }
             }
-            if(jobStatusMap.get("State").equals("Success")){
-                result=getFrameUrl(outputPath);
-            }else {
-                result=getErrorUrl();
+            if (jobStatusMap.get("State").equals("Success")) {
+                result = getFrameUrl(outputPath);
+            } else {
+                result = getErrorUrl();
             }
         }
         return result;
     }
+
     /**
-     *  数据万象获取截图服务
+     * 数据万象获取截图服务
      */
     public static String videoCutPictureHandle(String videoPath, String outputPath) {
-        String auth =generateAuth(SECRET_ID,SECRET_KEY,"/snapshot",HttpMethodName.POST);
-        if(auth.isEmpty()){
+        String auth = generateAuth(SECRET_ID, SECRET_KEY, "/snapshot", HttpMethodName.POST);
+        if (auth.isEmpty()) {
             logger.error("腾讯云Authorization获取失败");
         }
         //拼接请求数据万象jobs接口的参数
@@ -213,9 +216,9 @@ public class CloudVideoProcessUtil {
         output.put("Bucket", COS_BUCKET_MEDIA);
         output.put("Object", outputPath);
         JSONObject request = new JSONObject();
-        request.put("Input",input);
-        request.put("Output",output);
-        request.put("Time",0);
+        request.put("Input", input);
+        request.put("Output", output);
+        request.put("Time", 0);
 
         //请求media-1301855440.ci.ap-chongqing.myqcloud.com/snapshot 接口
         HttpHeaders headers = new HttpHeaders();
@@ -228,12 +231,13 @@ public class CloudVideoProcessUtil {
         } catch (RestClientException e) {
             logger.error(e.getMessage());
         }
-        if(response.isEmpty()){
-            return CosConstant.URL_COS_ADDRESS+"error.jpg";
-        }else{
-            return CosConstant.URL_COS_ADDRESS+outputPath;
+        if (response.isEmpty()) {
+            return CosConstant.URL_COS_ADDRESS + "error.jpg";
+        } else {
+            return CosConstant.URL_COS_ADDRESS + outputPath;
         }
     }
+
     /**
      * 获取视频处理服务 MpsClient
      */
@@ -254,6 +258,7 @@ public class CloudVideoProcessUtil {
 
     /**
      * 获取数据万象认证Auth
+     *
      * @param secretId
      * @param secretKey
      * @param path
@@ -273,23 +278,24 @@ public class CloudVideoProcessUtil {
                 expiredTime
         );
     }
-    private static Map<String,Object> getFrameUrl(String  outputPath){
-        Map<String,Object> result=new HashMap<>();
-        for(int i=1;i<15;i++){
-            result.put(""+i+"",CosConstant.URL_COS_ADDRESS+outputPath.replace("${Number}",""+i+""));
+
+    private static Map<String, Object> getFrameUrl(String outputPath) {
+        Map<String, Object> result = new HashMap<>();
+        for (int i = 0; i < 15; i++) {
+            result.put("" + i + "", CosConstant.URL_COS_ADDRESS + outputPath.replace("${Number}", "" + i + ""));
         }
         return result;
     }
 
-    private static Map<String,Object> getPictureUrl(String  outputPath){
-        Map<String,Object> result=new HashMap<>();
-        result.put("0",CosConstant.URL_COS_ADDRESS+outputPath);
+    private static Map<String, Object> getPictureUrl(String outputPath) {
+        Map<String, Object> result = new HashMap<>();
+        result.put("0", CosConstant.URL_COS_ADDRESS + outputPath);
         return result;
     }
 
-    private static Map<String,Object> getErrorUrl(){
-        Map<String,Object> result=new HashMap<>();
-            result.put("0",CosConstant.URL_COS_ADDRESS+"error.jpg");
+    private static Map<String, Object> getErrorUrl() {
+        Map<String, Object> result = new HashMap<>();
+        result.put("0", CosConstant.URL_COS_ADDRESS + "error.jpg");
         return result;
     }
 }

+ 7 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouMaterialUploadServiceImpl.java

@@ -79,18 +79,13 @@ public class KuaiShouMaterialUploadServiceImpl implements IKuaiShouMaterialUploa
                         returnJson.put("photoId", photoId);
                         returnJson.put("signature", signature);
                         returnJson.put("message", "上传成功");
-                        Thread thread = new Thread() {
-                            @Override
-                            public void run() {
-                                try {
-                                    Thread.sleep(2 * 1000L);
-                                    kuaishouInterfaceService.getVideoInfo(accessToken, accountId, photoId);
-                                } catch (InterruptedException e) {
-                                    e.printStackTrace();
-                                }
-                            }
-                        };
-                        thread.start();
+                        try {
+                            Thread.sleep(1 * 1000L);
+                            kuaishouInterfaceService.getVideoInfo(accessToken, accountId, photoId);
+                        } catch (InterruptedException e) {
+                            e.printStackTrace();
+                        }
+
                     }
                     LoadFileUtil.delFile(localUrl);
                     log.info("快手素材上传完成,accountId:{},code:{},返回信息:{}", accountId, signature, resultJson);