吴志根 4 лет назад
Родитель
Сommit
12fffef2f9

+ 122 - 63
src/dsb/com/cnd3b/restcontroller/enterprise/datacenter/datacenter.java

@@ -2,6 +2,8 @@ package com.cnd3b.restcontroller.enterprise.datacenter;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.aliyun.oss.OSSClient;
+import com.aliyun.oss.common.utils.BinaryUtil;
 import com.aliyun.oss.model.*;
 import com.cnd3b.common.Controller;
 import com.cnd3b.common.data.Rows;
@@ -18,6 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 
 import static com.cnd3b.utility.aliyun.oss.AliyunOSSUtil.*;
@@ -377,11 +380,21 @@ public class datacenter extends Controller {
         int tempBitrate = 1800;
         //获取支持的视频格式列表
         ArrayList<String> listVideo = getSupportVieoList();
-
+        String type = content.getString("type");
         String key = content.getString("key");
+        String outKey = "";
+        if (type.equals("1")) {
+            outKey = key;
+        } else {
+            outKey = "转码视频/" + key;
+        }
+
         if (key.toLowerCase().contains("mov")) {
-            AliyunOSSUtil.transcoding(templateId, key, key);
-            addTranscodingLog(key, key);
+            AliyunOSSUtil.transcoding(templateId, key, outKey);
+            if (type.equals("2")) {
+                addTranscodingLog(key, outKey);
+            }
+
             return getSucReturnObject().setData("MOV转码成功").toString();
         }
         //查询是否是可支持转码的视频
@@ -406,8 +419,10 @@ public class datacenter extends Controller {
             }
             System.err.println(bitrate);
             if (Double.parseDouble(bitrate) > tempBitrate) {
-                AliyunOSSUtil.transcoding(templateId, key, key);
-                addTranscodingLog(key, key);
+                AliyunOSSUtil.transcoding(templateId, key, outKey);
+                if (type.equals("2")) {
+                    addTranscodingLog(key, outKey);
+                }
                 return getSucReturnObject().setData("转码成功").toString();
             } else {
                 return getSucReturnObject().setData("码率低于" + tempBitrate + ",无须转码").toString();
@@ -418,62 +433,62 @@ public class datacenter extends Controller {
 
     }
 
-    public String applyTranscodingOfPath() throws P2Exception {
-        String folderPath = content.getString("folderPath");
-        List<String> list = getOssFileList(folderPath);
-        //阿里云视频转码模板
-        String templateId = "S00000001-200030";
-        //大于这个码率进行视频转码,mov格式的直接转码
-        int tempBitrate = 1800;
-
-        for (String keyPath : list) {
-
-            String key = keyPath;
-            if (key.toLowerCase().contains("mov")) {
-                AliyunOSSUtil.transcoding(templateId, key, key);
-                addTranscodingLog(key, key);
-                System.err.println("MOV转码成功:" + keyPath);
-            } else {
-                ArrayList<String> listVideo = getSupportVieoList();
-                //查询是否是可支持转码的视频
-                boolean isVideo = false;
-                for (String str : listVideo) {
-                    if (key.toLowerCase().contains(str.toLowerCase())) {
-                        isVideo = true;
-                        break;
-                    }
-                }
-                if (isVideo) {
-                    String res = AliyunOSSUtil.submitMediaInfoJob(key);
-                    JSONObject jsonObject = JSONObject.parseObject(res);
-                    //码率
-                    String bitrate = "0";
-                    if (jsonObject.containsKey("mediaInfoJob")) {
-                        JSONObject mediaInfoJob_jsonObject = jsonObject.getJSONObject("mediaInfoJob");
-                        if (mediaInfoJob_jsonObject.containsKey("properties")) {
-                            JSONObject properties_jsonObject = mediaInfoJob_jsonObject.getJSONObject("properties");
-                            bitrate = properties_jsonObject.getString("bitrate");
-                        }
-                    }
-                    System.err.println(bitrate);
-                    if (Double.parseDouble(bitrate) > tempBitrate) {
-                        AliyunOSSUtil.transcoding(templateId, key, key);
-                        addTranscodingLog(key, key);
-                        System.err.println("转码成功:" + keyPath);
-
-                    } else {
-                        System.err.println("码率低于" + tempBitrate + ",无须转码");
-
-                    }
-                } else {
-                    System.err.println("非视频格式,无法转码");
-
-                }
-            }
-
-        }
-        return getSucReturnObject().toString();
-    }
+//    public String applyTranscodingOfPath() throws P2Exception {
+//        String folderPath = content.getString("folderPath");
+//        List<String> list = getOssFileList(folderPath);
+//        //阿里云视频转码模板
+//        String templateId = "S00000001-200030";
+//        //大于这个码率进行视频转码,mov格式的直接转码
+//        int tempBitrate = 1800;
+//
+//        for (String keyPath : list) {
+//
+//            String key = keyPath;
+//            if (key.toLowerCase().contains("mov")) {
+//                AliyunOSSUtil.transcoding(templateId, key, key);
+//                addTranscodingLog(key, key);
+//                System.err.println("MOV转码成功:" + keyPath);
+//            } else {
+//                ArrayList<String> listVideo = getSupportVieoList();
+//                //查询是否是可支持转码的视频
+//                boolean isVideo = false;
+//                for (String str : listVideo) {
+//                    if (key.toLowerCase().contains(str.toLowerCase())) {
+//                        isVideo = true;
+//                        break;
+//                    }
+//                }
+//                if (isVideo) {
+//                    String res = AliyunOSSUtil.submitMediaInfoJob(key);
+//                    JSONObject jsonObject = JSONObject.parseObject(res);
+//                    //码率
+//                    String bitrate = "0";
+//                    if (jsonObject.containsKey("mediaInfoJob")) {
+//                        JSONObject mediaInfoJob_jsonObject = jsonObject.getJSONObject("mediaInfoJob");
+//                        if (mediaInfoJob_jsonObject.containsKey("properties")) {
+//                            JSONObject properties_jsonObject = mediaInfoJob_jsonObject.getJSONObject("properties");
+//                            bitrate = properties_jsonObject.getString("bitrate");
+//                        }
+//                    }
+//                    System.err.println(bitrate);
+//                    if (Double.parseDouble(bitrate) > tempBitrate) {
+//                        AliyunOSSUtil.transcoding(templateId, key, key);
+//                        addTranscodingLog(key, key);
+//                        System.err.println("转码成功:" + keyPath);
+//
+//                    } else {
+//                        System.err.println("码率低于" + tempBitrate + ",无须转码");
+//
+//                    }
+//                } else {
+//                    System.err.println("非视频格式,无法转码");
+//
+//                }
+//            }
+//
+//        }
+//        return getSucReturnObject().toString();
+//    }
 
     //支持转转码的格式
     public ArrayList<String> getSupportVieoList() {
@@ -506,11 +521,11 @@ public class datacenter extends Controller {
         if (paoSetRemote.isEmpty()) {
             PaoRemote paoRemote = paoSetRemote.addAtEnd();
             paoRemote.setValue("tkey", tkey, 11L);
-            paoRemote.setValue("tkey_new", "code/" + tkey_new, 11L);
+            paoRemote.setValue("tkey_new", tkey_new, 11L);
 
         } else {
             PaoRemote paoRemote = paoSetRemote.getPao(0);
-            paoRemote.setValue("tkey_new", "转码视频/" + tkey_new, 11L);
+            paoRemote.setValue("tkey_new", tkey_new, 11L);
 
         }
 
@@ -518,5 +533,49 @@ public class datacenter extends Controller {
 
     }
 
+    /**
+     * 获取OSS上传签名信息
+     *
+     * @return
+     */
+    public String getOssSignature() {
+
+
+        String key = content.getString("key");
+
+        // host的格式为 bucketname.endpoint
+        String host = "https://" + BUCKE_NAME_1 + "." + END_POINT;
+        // callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
+        // String callbackUrl = "http://88.88.88.88:8888";
+        // 每一天产生一个文件夹
+        // 用户上传文件时指定的前缀,如果是 / 则自动检测为文件夹。
+        String dir = key;
+
+        JSONObject jsonObject = new JSONObject();
+        //过期时间 100 秒
+        long expireTime = 600;
+        long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
+        Date expiration = new Date(expireEndTime);
+        // PostObject请求最大可支持的文件大小为5 GB,即CONTENT_LENGTH_RANGE为5*1024*1024*1024。
+        PolicyConditions policyConds = new PolicyConditions();
+        policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);
+        policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
+        String postPolicy = ossClient.generatePostPolicy(expiration, policyConds);
+        byte[] binaryData = postPolicy.getBytes(StandardCharsets.UTF_8);
+        String encodedPolicy = BinaryUtil.toBase64String(binaryData);
+        String postSignature = ossClient.calculatePostSignature(postPolicy);
+
+        jsonObject.put("OSSAccessKeyId", AccessKey_ID);
+        jsonObject.put("policy", encodedPolicy);
+        jsonObject.put("signature", postSignature);
+        jsonObject.put("dir", dir);
+        jsonObject.put("host", host);
+        jsonObject.put("expire", String.valueOf(expireEndTime / 1000));
+
+
+        return getSucReturnObject().setData(jsonObject).toString();
+
+    }
+
 
 }

+ 1 - 1
src/dsb/com/cnd3b/restcontroller/enterprise/tauthtype/tauthtype.java

@@ -132,7 +132,7 @@ public class tauthtype extends Controller {
         SQLFactory sqlFactory = new SQLFactory(this, "ÌåϵÁбí", pageSize, pageNumber, "t1.createdate DESC");
         sqlFactory.addParameter_SQL("where", where);
         Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
-        return getSucReturnObject().setData(rows).toString();
+        return getSucReturnObject().setDataByPaging(rows).toString();
     }
 
 }

+ 1 - 1
src/dsb/com/cnd3b/utility/aliyun/oss/AliyunOSSUtil.java

@@ -374,7 +374,7 @@ public class AliyunOSSUtil {
         // Output
         String outputOSSObject;
         try {
-            outputOSSObject = URLEncoder.encode("תÂëÊÓÆµ/" + ossOutputObject, "utf-8");
+            outputOSSObject = URLEncoder.encode(ossOutputObject, "utf-8");
         } catch (UnsupportedEncodingException e) {
             throw new RuntimeException("output URL encode failed");
         }