Browse Source

deprecated old fss api...

deason 11 tháng trước cách đây
mục cha
commit
52762176c5
22 tập tin đã thay đổi với 3246 bổ sung3246 xóa
  1. 450 450
      examcloud-support/src/main/java/cn/com/qmth/examcloud/support/filestorage/FileStorageUtil.java
  2. 79 79
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/AliYunAccount.java
  3. 63 63
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/AliyunSite.java
  4. 135 135
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/AliyunSiteManager.java
  5. 220 220
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/OssClient.java
  6. 87 87
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorage.java
  7. 80 80
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorageHelper.java
  8. 159 159
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStoragePathEnvInfo.java
  9. 66 66
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorageSite.java
  10. 45 45
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/YunHttpRequest.java
  11. 46 46
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/YunPathInfo.java
  12. 553 553
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/AliyunFileStorageImpl.java
  13. 55 55
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/AliyunRefreshCdn.java
  14. 126 126
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/UpyunFileStorageImpl.java
  15. 420 420
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpYunClient.java
  16. 44 44
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpYunPathInfo.java
  17. 159 159
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunPathEnvironmentInfo.java
  18. 82 82
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunService.java
  19. 110 110
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunServiceImpl.java
  20. 66 66
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunSite.java
  21. 137 137
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunSiteManager.java
  22. 64 64
      examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunTest.java

+ 450 - 450
examcloud-support/src/main/java/cn/com/qmth/examcloud/support/filestorage/FileStorageUtil.java

@@ -1,450 +1,450 @@
-package cn.com.qmth.examcloud.support.filestorage;
-
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.util.MD5;
-import cn.com.qmth.examcloud.support.cache.CacheHelper;
-import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
-import cn.com.qmth.examcloud.web.aliyun.AliyunSiteManager;
-import cn.com.qmth.examcloud.web.filestorage.*;
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-import cn.com.qmth.examcloud.web.upyun.UpyunSiteManager;
-import org.apache.commons.lang3.StringUtils;
-
-import java.io.*;
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-/**
- * 文件存储服务接口工具类
- */
-public class FileStorageUtil {
-
-    // private static String fileStorageType = PropertyHolder.getString("$filestorage-type");
-
-    // private static String tempDir = PropertyHolder.getString("$filestorage-trans-tempdir");
-
-    private static String beanSuff = "FileStorage";
-
-    /**
-     * 根据当前配置存储类型保存文件到存储服务器
-     *
-     * @param siteId
-     * @param env
-     * @param in     文件流
-     * @param md5    文件MD5 可为空
-     * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
-     */
-    public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5) {
-        FileStorageType fsType = getFileStorageType();
-        return saveFile(siteId, env, in, fsType, md5, false);
-    }
-
-    /**
-     * 根据当前配置存储类型保存文件到存储服务器
-     *
-     * @param siteId
-     * @param env
-     * @param file    文件
-     * @param withMd5 是否校验MD5
-     * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
-     */
-    public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, boolean withMd5) {
-        FileStorageType fsType = getFileStorageType();
-        String md5 = null;
-        if (withMd5) {
-            md5 = MD5.md5Hex(file);
-        }
-        return saveFile(siteId, env, file, fsType, md5, false);
-    }
-
-    /**
-     * 根据当前配置存储类型保存文件到存储服务器
-     *
-     * @param siteId
-     * @param env
-     * @param file   文件
-     * @param md5    文件MD5 可为空
-     * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
-     */
-    public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5) {
-        return saveFile(siteId, env, file, md5, false);
-    }
-
-    public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, Long cacheAge) {
-        FileStorageType fsType = getFileStorageType();
-        return saveFile(siteId, env, file, fsType, md5, false, cacheAge);
-    }
-
-    public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN) {
-        FileStorageType fsType = getFileStorageType();
-        return saveFile(siteId, env, file, fsType, md5, refreshCDN);
-    }
-
-    /**
-     * 保存文件
-     *
-     * @param siteId
-     * @param env
-     * @param bytes
-     * @param refreshCDN 是否刷新CDN缓存
-     * @return
-     */
-    public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN) {
-        if (siteId == null) {
-            throw new StatusException("4001", "siteId不能为空");
-        }
-        if (bytes == null) {
-            throw new StatusException("4002", "文件不能为空");
-        }
-        if (env == null) {
-            throw new StatusException("4003", "文件上传路径不能为空");
-        }
-
-        FileStorageType fsType = getFileStorageType();
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-        FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
-
-        return fs.saveFile(siteId, env, bytes, refreshCDN);
-    }
-
-    /**
-     * 根据存储类型保存文件到存储服务器
-     *
-     * @param siteId
-     * @param env
-     * @param in     文件流
-     * @param fsType 存储类型
-     * @param md5    文件MD5 可为空
-     * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
-     */
-    private static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in,
-                                        FileStorageType fsType, String md5, boolean refreshCDN) {
-
-        if (siteId == null) {
-            throw new StatusException("1000", "siteId是空");
-        }
-        if (in == null) {
-            throw new StatusException("1001", "文件流是空");
-        }
-        if (env == null) {
-            throw new StatusException("1002", "文件上传路径信息是空");
-        }
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-        FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
-        return fs.saveFile(siteId, env, in, md5, refreshCDN);
-    }
-
-    /**
-     * 根据存储类型保存文件到存储服务器
-     *
-     * @param siteId
-     * @param env
-     * @param file       文件
-     * @param fsType     存储类型
-     * @param md5        文件MD5 可为空
-     * @param refreshCDN 是否刷新CDN缓存
-     * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
-     */
-    private static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, FileStorageType fsType,
-                                        String md5, boolean refreshCDN) {
-        if (siteId == null) {
-            throw new StatusException("2000", "siteId是空");
-        }
-        if (file == null) {
-            throw new StatusException("2001", "文件是空");
-        }
-        if (env == null) {
-            throw new StatusException("2002", "文件上传路径信息是空");
-        }
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-        FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
-        return fs.saveFile(siteId, env, file, md5, refreshCDN);
-    }
-
-    private static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, FileStorageType fsType,
-                                        String md5, boolean refreshCDN, Long cacheAge) {
-        if (siteId == null) {
-            throw new StatusException("2000", "siteId是空");
-        }
-        if (file == null) {
-            throw new StatusException("2001", "文件是空");
-        }
-        if (env == null) {
-            throw new StatusException("2002", "文件上传路径信息是空");
-        }
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-        FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
-        return fs.saveFile(siteId, env, file, md5, refreshCDN, cacheAge);
-    }
-
-    /**
-     * 获取文件访问路径
-     *
-     * @param path 数据库保存的路径 如:upyun-1://student_photo/001.jpg,兼容老数据,路径必须是包含根路径的
-     * @return 可直接访问的文件地址
-     */
-    public static String realPath(String path) {
-
-        if (StringUtils.isBlank(path)) {
-            return null;
-        }
-        // 兼容处理老数据文件路径
-        path = diposeOldPath(path);
-        // 如果是全路径直接返回
-        if (path.startsWith("http") || path.startsWith("https")) {
-            return path;
-        }
-        // 根据路径头获取对应的处理类
-        FileStorage fs = SpringContextHolder.getBean(FileStorageHelper.getHead(path).toLowerCase() + beanSuff,
-                FileStorage.class);
-        // 返回处理类处理结果
-        return fs.realPath(path);
-
-    }
-
-    /**
-     * 将文件转换到指定存储服务上
-     *
-     * @param path        数据库保存的路径
-     *                    如:upyun-1://student_photo/001.jpg,兼容老数据,路径必须是包含根路径的
-     * @param transFsType 要转换的类型
-     * @return 转换之后的路径
-     */
-    /*public static String transPath(String path, FileStorageType transFsType) {
-
-        File file = null;
-        if (StringUtils.isBlank(path)) {
-            throw new StatusException("4001", "文件路径是空");
-        }
-        if (transFsType == null) {
-            throw new StatusException("4002", "转换类型是空");
-        }
-        // 兼容处理老数据文件路径
-        path = diposeOldPath(path);
-        // 如果是全路径直接返回
-        if (path.startsWith("http") || path.startsWith("https")) {
-            return path;
-        }
-
-        FileStorageType sourseType = FileStorageType.valueOf(FileStorageHelper.getHead(path));
-        // 相同的类型直接返回
-        if (sourseType.equals(transFsType)) {
-            return path;
-        }
-        // 获取对应的处理类
-        FileStorage fs = SpringContextHolder.getBean(transFsType.name().toLowerCase() + beanSuff, FileStorage.class);
-        try {
-            // 下载文件到本地
-            String httppath = fs.realPath(FileStorageHelper.getPath(path));
-            file = downFile(httppath);
-            // 保存文件到指定存储服务器,并返回路径
-            YunPathInfo ret = fs.saveFile(file, "from" + sourseType.name().toLowerCase() + "/" + FileStorageHelper.getPath(path));
-            return ret.getRelativePath();
-        } catch (IOException e) {
-            throw new StatusException("4003", "下载文件出错 " + e.getMessage());
-        } finally {
-            if (file != null) {
-                file.delete();
-            }
-        }
-
-    }*/
-
-    /*private static File downFile(String url) throws IOException {
-        String name = url.substring(url.lastIndexOf("/") + 1);
-        File file = new File(tempDir + "/" + name);
-        if (file.exists()) {
-            file.delete();
-        }
-        file.createNewFile();
-        saveUrlAs(url, file.getAbsolutePath());
-        return file;
-    }*/
-
-    /**
-     * @param path 数据库存储的路径。路径必须是包含根路径的
-     * @return 处理后的路径。补全路径头。
-     */
-    private static String diposeOldPath(String path) {
-        if (StringUtils.isBlank(path)) {
-            return null;
-        }
-        // 如果是全路径直接返回
-        if (path.startsWith("http") || path.startsWith("https")) {
-            return path;
-        }
-        // 如果是半路径,转换成又拍云类型
-        if (path.indexOf(":") == -1) {
-            if (path.startsWith("/")) {
-                path = path.substring(1);
-            }
-            return FileStorageHelper.getUpyunSiteOne(path);
-        }
-        // 无需处理
-        return path;
-    }
-
-    /**
-     * 将网络文件保存到本地
-     *
-     * @param fileUrl       网络文件URL
-     * @param localFilePath 例如D:/123.txt
-     * @throws IOException
-     */
-    private static void saveUrlAs(String fileUrl, String localFilePath) throws IOException {
-        URL url = new URL(fileUrl);
-
-        HttpURLConnection connection;
-        connection = (HttpURLConnection) url.openConnection();
-
-        try (DataInputStream dataInputStream = new DataInputStream(connection.getInputStream());
-             FileOutputStream fileOutputStream = new FileOutputStream(localFilePath);
-             DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);) {
-
-            byte[] buffer = new byte[4096];
-            int count;
-            while ((count = dataInputStream.read(buffer)) > 0) {
-                dataOutputStream.write(buffer, 0, count);
-            }
-            fileOutputStream.flush();
-            dataOutputStream.flush();
-        } finally {
-            if (connection != null) {
-                connection.disconnect();
-            }
-        }
-    }
-
-    /**
-     * 将网络文件保存到本地
-     *
-     * @param fileUrl   网络文件URL
-     * @param localFile 本地文件对象
-     * @throws IOException
-     */
-    public static void saveUrlAs(String fileUrl, File localFile) {
-        if (StringUtils.isBlank(fileUrl)) {
-            throw new StatusException("500", "文件链接为空");
-        }
-        if (!fileUrl.toLowerCase().startsWith("http") && !fileUrl.toLowerCase().startsWith("https")) {
-            throw new StatusException("500", "文件链接不是URL");
-        }
-        try {
-            saveUrlAs(fileUrl, localFile.getAbsolutePath());
-        } catch (IOException e) {
-            throw new StatusException("5001", "下载文件出错", e);
-        }
-    }
-
-    /**
-     * 获取指定云存储的签名
-     *
-     * @param siteId
-     * @param env
-     * @param md5
-     * @return
-     */
-    public static YunHttpRequest getSignature(FileStorageType fsType, String siteId, FileStoragePathEnvInfo env,
-                                              String md5) {
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-        // 获取对应的处理类
-        FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
-        return fs.getSignature(siteId, env, md5);
-    }
-
-    /**
-     * 获取完整的不带域名的路径
-     *
-     * @param prefixPath 路径前缀
-     * @param sourcePath 数据库存储的路径
-     * @return 处理之后的路径
-     */
-    public static String getIntactPath(String prefixPath, String sourcePath) {
-        if (StringUtils.isBlank(sourcePath)) {
-            return null;
-        }
-        // 如果是全路径直接返回
-        if (sourcePath.startsWith("http") || sourcePath.startsWith("https")) {
-            return sourcePath;
-        }
-        // 如果是半路径则拼接
-        if (sourcePath.indexOf(":") == -1) {
-            if (sourcePath.startsWith("/")) {
-                sourcePath = sourcePath.substring(1);
-            }
-            if (prefixPath.endsWith("/")) {
-                prefixPath = prefixPath.substring(0, prefixPath.length());
-            }
-            return prefixPath + "/" + sourcePath;
-        }
-        // 新协议无需处理
-        return sourcePath;
-    }
-
-    /**
-     * 删除云存储文件
-     *
-     * @param path 全路径,包含根目录,含协议名
-     */
-    public static void deleteFile(String path) {
-        if (StringUtils.isBlank(path)) {
-            return;
-        }
-        path = diposeOldPath(path);
-        // 如果是全路径直接返回
-        if (path.startsWith("http") || path.startsWith("https")) {
-            return;
-        }
-        FileStorage fs = SpringContextHolder.getBean(FileStorageHelper.getHead(path).toLowerCase() + beanSuff,
-                FileStorage.class);
-        fs.deleteFile(path);
-    }
-
-    /**
-     * 获取文件访问路径(备用域名地址)
-     *
-     * @param path 数据库保存的路径 如:upyun-1://student_photo/001.jpg,兼容老数据,路径必须是包含根路径的
-     * @return 可直接访问的文件地址, 如果没有配置备用地址,则返回主域名地址
-     */
-    public static String realPathBackup(String path) {
-        if (StringUtils.isBlank(path)) {
-            return null;
-        }
-        // 兼容处理老数据文件路径
-        path = diposeOldPath(path);
-        // 如果是全路径直接返回
-        if (path.startsWith("http") || path.startsWith("https")) {
-            return path;
-        }
-        // 根据路径头获取对应的处理类
-        FileStorage fs = SpringContextHolder.getBean(FileStorageHelper.getHead(path).toLowerCase() + beanSuff,
-                FileStorage.class);
-        // 返回处理类处理结果
-        return fs.realPathBackup(path);
-
-    }
-
-    public static void initYunClient() {
-        UpyunSiteManager.initClient();
-        AliyunSiteManager.initClient();
-    }
-
-    public static void initYunSite() {
-        UpyunSiteManager.initSite();
-        AliyunSiteManager.initSite();
-    }
-
-    public static FileStorageType getFileStorageType() {
-        SysPropertyCacheBean spc = CacheHelper.getSysProperty("filestorage.type");
-        if (spc == null || spc.getValue() == null) {
-            throw new StatusException("10001", "未配置文件存储服务类型");
-        }
-        String type = (String) spc.getValue();
-        try {
-            return FileStorageType.valueOf(type);
-        } catch (Exception e) {
-            throw new StatusException("10002", "配置文件存储服务类型错误");
-        }
-    }
-
-}
+// package cn.com.qmth.examcloud.support.filestorage;
+//
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.commons.util.MD5;
+// import cn.com.qmth.examcloud.support.cache.CacheHelper;
+// import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
+// import cn.com.qmth.examcloud.web.aliyun.AliyunSiteManager;
+// import cn.com.qmth.examcloud.web.filestorage.*;
+// import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+// import cn.com.qmth.examcloud.web.upyun.UpyunSiteManager;
+// import org.apache.commons.lang3.StringUtils;
+//
+// import java.io.*;
+// import java.net.HttpURLConnection;
+// import java.net.URL;
+//
+// /**
+//  * 文件存储服务接口工具类
+//  */
+// public class FileStorageUtil {
+//
+//     // private static String fileStorageType = PropertyHolder.getString("$filestorage-type");
+//
+//     // private static String tempDir = PropertyHolder.getString("$filestorage-trans-tempdir");
+//
+//     private static String beanSuff = "FileStorage";
+//
+//     /**
+//      * 根据当前配置存储类型保存文件到存储服务器
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param in     文件流
+//      * @param md5    文件MD5 可为空
+//      * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
+//      */
+//     public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5) {
+//         FileStorageType fsType = getFileStorageType();
+//         return saveFile(siteId, env, in, fsType, md5, false);
+//     }
+//
+//     /**
+//      * 根据当前配置存储类型保存文件到存储服务器
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param file    文件
+//      * @param withMd5 是否校验MD5
+//      * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
+//      */
+//     public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, boolean withMd5) {
+//         FileStorageType fsType = getFileStorageType();
+//         String md5 = null;
+//         if (withMd5) {
+//             md5 = MD5.md5Hex(file);
+//         }
+//         return saveFile(siteId, env, file, fsType, md5, false);
+//     }
+//
+//     /**
+//      * 根据当前配置存储类型保存文件到存储服务器
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param file   文件
+//      * @param md5    文件MD5 可为空
+//      * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
+//      */
+//     public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5) {
+//         return saveFile(siteId, env, file, md5, false);
+//     }
+//
+//     public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, Long cacheAge) {
+//         FileStorageType fsType = getFileStorageType();
+//         return saveFile(siteId, env, file, fsType, md5, false, cacheAge);
+//     }
+//
+//     public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN) {
+//         FileStorageType fsType = getFileStorageType();
+//         return saveFile(siteId, env, file, fsType, md5, refreshCDN);
+//     }
+//
+//     /**
+//      * 保存文件
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param bytes
+//      * @param refreshCDN 是否刷新CDN缓存
+//      * @return
+//      */
+//     public static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN) {
+//         if (siteId == null) {
+//             throw new StatusException("4001", "siteId不能为空");
+//         }
+//         if (bytes == null) {
+//             throw new StatusException("4002", "文件不能为空");
+//         }
+//         if (env == null) {
+//             throw new StatusException("4003", "文件上传路径不能为空");
+//         }
+//
+//         FileStorageType fsType = getFileStorageType();
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//         FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
+//
+//         return fs.saveFile(siteId, env, bytes, refreshCDN);
+//     }
+//
+//     /**
+//      * 根据存储类型保存文件到存储服务器
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param in     文件流
+//      * @param fsType 存储类型
+//      * @param md5    文件MD5 可为空
+//      * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
+//      */
+//     private static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in,
+//                                         FileStorageType fsType, String md5, boolean refreshCDN) {
+//
+//         if (siteId == null) {
+//             throw new StatusException("1000", "siteId是空");
+//         }
+//         if (in == null) {
+//             throw new StatusException("1001", "文件流是空");
+//         }
+//         if (env == null) {
+//             throw new StatusException("1002", "文件上传路径信息是空");
+//         }
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//         FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
+//         return fs.saveFile(siteId, env, in, md5, refreshCDN);
+//     }
+//
+//     /**
+//      * 根据存储类型保存文件到存储服务器
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param file       文件
+//      * @param fsType     存储类型
+//      * @param md5        文件MD5 可为空
+//      * @param refreshCDN 是否刷新CDN缓存
+//      * @return 返回包含协议名的地址,数据库直接存储用 如:upyun-1://student_photo/001.jpg
+//      */
+//     private static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, FileStorageType fsType,
+//                                         String md5, boolean refreshCDN) {
+//         if (siteId == null) {
+//             throw new StatusException("2000", "siteId是空");
+//         }
+//         if (file == null) {
+//             throw new StatusException("2001", "文件是空");
+//         }
+//         if (env == null) {
+//             throw new StatusException("2002", "文件上传路径信息是空");
+//         }
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//         FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
+//         return fs.saveFile(siteId, env, file, md5, refreshCDN);
+//     }
+//
+//     private static YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, FileStorageType fsType,
+//                                         String md5, boolean refreshCDN, Long cacheAge) {
+//         if (siteId == null) {
+//             throw new StatusException("2000", "siteId是空");
+//         }
+//         if (file == null) {
+//             throw new StatusException("2001", "文件是空");
+//         }
+//         if (env == null) {
+//             throw new StatusException("2002", "文件上传路径信息是空");
+//         }
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//         FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
+//         return fs.saveFile(siteId, env, file, md5, refreshCDN, cacheAge);
+//     }
+//
+//     /**
+//      * 获取文件访问路径
+//      *
+//      * @param path 数据库保存的路径 如:upyun-1://student_photo/001.jpg,兼容老数据,路径必须是包含根路径的
+//      * @return 可直接访问的文件地址
+//      */
+//     public static String realPath(String path) {
+//
+//         if (StringUtils.isBlank(path)) {
+//             return null;
+//         }
+//         // 兼容处理老数据文件路径
+//         path = diposeOldPath(path);
+//         // 如果是全路径直接返回
+//         if (path.startsWith("http") || path.startsWith("https")) {
+//             return path;
+//         }
+//         // 根据路径头获取对应的处理类
+//         FileStorage fs = SpringContextHolder.getBean(FileStorageHelper.getHead(path).toLowerCase() + beanSuff,
+//                 FileStorage.class);
+//         // 返回处理类处理结果
+//         return fs.realPath(path);
+//
+//     }
+//
+//     /**
+//      * 将文件转换到指定存储服务上
+//      *
+//      * @param path        数据库保存的路径
+//      *                    如:upyun-1://student_photo/001.jpg,兼容老数据,路径必须是包含根路径的
+//      * @param transFsType 要转换的类型
+//      * @return 转换之后的路径
+//      */
+//     /*public static String transPath(String path, FileStorageType transFsType) {
+//
+//         File file = null;
+//         if (StringUtils.isBlank(path)) {
+//             throw new StatusException("4001", "文件路径是空");
+//         }
+//         if (transFsType == null) {
+//             throw new StatusException("4002", "转换类型是空");
+//         }
+//         // 兼容处理老数据文件路径
+//         path = diposeOldPath(path);
+//         // 如果是全路径直接返回
+//         if (path.startsWith("http") || path.startsWith("https")) {
+//             return path;
+//         }
+//
+//         FileStorageType sourseType = FileStorageType.valueOf(FileStorageHelper.getHead(path));
+//         // 相同的类型直接返回
+//         if (sourseType.equals(transFsType)) {
+//             return path;
+//         }
+//         // 获取对应的处理类
+//         FileStorage fs = SpringContextHolder.getBean(transFsType.name().toLowerCase() + beanSuff, FileStorage.class);
+//         try {
+//             // 下载文件到本地
+//             String httppath = fs.realPath(FileStorageHelper.getPath(path));
+//             file = downFile(httppath);
+//             // 保存文件到指定存储服务器,并返回路径
+//             YunPathInfo ret = fs.saveFile(file, "from" + sourseType.name().toLowerCase() + "/" + FileStorageHelper.getPath(path));
+//             return ret.getRelativePath();
+//         } catch (IOException e) {
+//             throw new StatusException("4003", "下载文件出错 " + e.getMessage());
+//         } finally {
+//             if (file != null) {
+//                 file.delete();
+//             }
+//         }
+//
+//     }*/
+//
+//     /*private static File downFile(String url) throws IOException {
+//         String name = url.substring(url.lastIndexOf("/") + 1);
+//         File file = new File(tempDir + "/" + name);
+//         if (file.exists()) {
+//             file.delete();
+//         }
+//         file.createNewFile();
+//         saveUrlAs(url, file.getAbsolutePath());
+//         return file;
+//     }*/
+//
+//     /**
+//      * @param path 数据库存储的路径。路径必须是包含根路径的
+//      * @return 处理后的路径。补全路径头。
+//      */
+//     private static String diposeOldPath(String path) {
+//         if (StringUtils.isBlank(path)) {
+//             return null;
+//         }
+//         // 如果是全路径直接返回
+//         if (path.startsWith("http") || path.startsWith("https")) {
+//             return path;
+//         }
+//         // 如果是半路径,转换成又拍云类型
+//         if (path.indexOf(":") == -1) {
+//             if (path.startsWith("/")) {
+//                 path = path.substring(1);
+//             }
+//             return FileStorageHelper.getUpyunSiteOne(path);
+//         }
+//         // 无需处理
+//         return path;
+//     }
+//
+//     /**
+//      * 将网络文件保存到本地
+//      *
+//      * @param fileUrl       网络文件URL
+//      * @param localFilePath 例如D:/123.txt
+//      * @throws IOException
+//      */
+//     private static void saveUrlAs(String fileUrl, String localFilePath) throws IOException {
+//         URL url = new URL(fileUrl);
+//
+//         HttpURLConnection connection;
+//         connection = (HttpURLConnection) url.openConnection();
+//
+//         try (DataInputStream dataInputStream = new DataInputStream(connection.getInputStream());
+//              FileOutputStream fileOutputStream = new FileOutputStream(localFilePath);
+//              DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);) {
+//
+//             byte[] buffer = new byte[4096];
+//             int count;
+//             while ((count = dataInputStream.read(buffer)) > 0) {
+//                 dataOutputStream.write(buffer, 0, count);
+//             }
+//             fileOutputStream.flush();
+//             dataOutputStream.flush();
+//         } finally {
+//             if (connection != null) {
+//                 connection.disconnect();
+//             }
+//         }
+//     }
+//
+//     /**
+//      * 将网络文件保存到本地
+//      *
+//      * @param fileUrl   网络文件URL
+//      * @param localFile 本地文件对象
+//      * @throws IOException
+//      */
+//     public static void saveUrlAs(String fileUrl, File localFile) {
+//         if (StringUtils.isBlank(fileUrl)) {
+//             throw new StatusException("500", "文件链接为空");
+//         }
+//         if (!fileUrl.toLowerCase().startsWith("http") && !fileUrl.toLowerCase().startsWith("https")) {
+//             throw new StatusException("500", "文件链接不是URL");
+//         }
+//         try {
+//             saveUrlAs(fileUrl, localFile.getAbsolutePath());
+//         } catch (IOException e) {
+//             throw new StatusException("5001", "下载文件出错", e);
+//         }
+//     }
+//
+//     /**
+//      * 获取指定云存储的签名
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param md5
+//      * @return
+//      */
+//     public static YunHttpRequest getSignature(FileStorageType fsType, String siteId, FileStoragePathEnvInfo env,
+//                                               String md5) {
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//         // 获取对应的处理类
+//         FileStorage fs = SpringContextHolder.getBean(fsType.name().toLowerCase() + beanSuff, FileStorage.class);
+//         return fs.getSignature(siteId, env, md5);
+//     }
+//
+//     /**
+//      * 获取完整的不带域名的路径
+//      *
+//      * @param prefixPath 路径前缀
+//      * @param sourcePath 数据库存储的路径
+//      * @return 处理之后的路径
+//      */
+//     public static String getIntactPath(String prefixPath, String sourcePath) {
+//         if (StringUtils.isBlank(sourcePath)) {
+//             return null;
+//         }
+//         // 如果是全路径直接返回
+//         if (sourcePath.startsWith("http") || sourcePath.startsWith("https")) {
+//             return sourcePath;
+//         }
+//         // 如果是半路径则拼接
+//         if (sourcePath.indexOf(":") == -1) {
+//             if (sourcePath.startsWith("/")) {
+//                 sourcePath = sourcePath.substring(1);
+//             }
+//             if (prefixPath.endsWith("/")) {
+//                 prefixPath = prefixPath.substring(0, prefixPath.length());
+//             }
+//             return prefixPath + "/" + sourcePath;
+//         }
+//         // 新协议无需处理
+//         return sourcePath;
+//     }
+//
+//     /**
+//      * 删除云存储文件
+//      *
+//      * @param path 全路径,包含根目录,含协议名
+//      */
+//     public static void deleteFile(String path) {
+//         if (StringUtils.isBlank(path)) {
+//             return;
+//         }
+//         path = diposeOldPath(path);
+//         // 如果是全路径直接返回
+//         if (path.startsWith("http") || path.startsWith("https")) {
+//             return;
+//         }
+//         FileStorage fs = SpringContextHolder.getBean(FileStorageHelper.getHead(path).toLowerCase() + beanSuff,
+//                 FileStorage.class);
+//         fs.deleteFile(path);
+//     }
+//
+//     /**
+//      * 获取文件访问路径(备用域名地址)
+//      *
+//      * @param path 数据库保存的路径 如:upyun-1://student_photo/001.jpg,兼容老数据,路径必须是包含根路径的
+//      * @return 可直接访问的文件地址, 如果没有配置备用地址,则返回主域名地址
+//      */
+//     public static String realPathBackup(String path) {
+//         if (StringUtils.isBlank(path)) {
+//             return null;
+//         }
+//         // 兼容处理老数据文件路径
+//         path = diposeOldPath(path);
+//         // 如果是全路径直接返回
+//         if (path.startsWith("http") || path.startsWith("https")) {
+//             return path;
+//         }
+//         // 根据路径头获取对应的处理类
+//         FileStorage fs = SpringContextHolder.getBean(FileStorageHelper.getHead(path).toLowerCase() + beanSuff,
+//                 FileStorage.class);
+//         // 返回处理类处理结果
+//         return fs.realPathBackup(path);
+//
+//     }
+//
+//     public static void initYunClient() {
+//         UpyunSiteManager.initClient();
+//         AliyunSiteManager.initClient();
+//     }
+//
+//     public static void initYunSite() {
+//         UpyunSiteManager.initSite();
+//         AliyunSiteManager.initSite();
+//     }
+//
+//     public static FileStorageType getFileStorageType() {
+//         SysPropertyCacheBean spc = CacheHelper.getSysProperty("filestorage.type");
+//         if (spc == null || spc.getValue() == null) {
+//             throw new StatusException("10001", "未配置文件存储服务类型");
+//         }
+//         String type = (String) spc.getValue();
+//         try {
+//             return FileStorageType.valueOf(type);
+//         } catch (Exception e) {
+//             throw new StatusException("10002", "配置文件存储服务类型错误");
+//         }
+//     }
+//
+// }

+ 79 - 79
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/AliYunAccount.java

@@ -1,79 +1,79 @@
-package cn.com.qmth.examcloud.web.aliyun;
-
-/**
- * 阿里云存储账号信息
- */
-public class AliYunAccount {
-
-    private String bucket;
-
-    private String ossEndpoint;
-
-    private String accessKeyId;
-
-    private String accessKeySecret;
-
-    private String domain;
-
-    private String domainBackup;
-
-    public String getBucket() {
-        return bucket;
-    }
-
-    public void setBucket(String bucket) {
-        this.bucket = bucket;
-    }
-
-    public String getOssEndpoint() {
-        return ossEndpoint;
-    }
-
-    public void setOssEndpoint(String ossEndpoint) {
-        this.ossEndpoint = ossEndpoint;
-    }
-
-    public String getAccessKeyId() {
-        return accessKeyId;
-    }
-
-    public void setAccessKeyId(String accessKeyId) {
-        this.accessKeyId = accessKeyId;
-    }
-
-    public String getAccessKeySecret() {
-        return accessKeySecret;
-    }
-
-    public void setAccessKeySecret(String accessKeySecret) {
-        this.accessKeySecret = accessKeySecret;
-    }
-
-    public String getDomain() {
-        return domain;
-    }
-
-    public void setDomain(String domain) {
-        this.domain = domain;
-    }
-
-    public String getDomainBackup() {
-        return domainBackup;
-    }
-
-    public void setDomainBackup(String domainBackup) {
-        this.domainBackup = domainBackup;
-    }
-
-    public AliYunAccount(String bucket, String ossEndpoint, String accessKeyId, String accessKeySecret, String domain,
-                         String domainBackup) {
-        super();
-        this.bucket = bucket;
-        this.ossEndpoint = ossEndpoint;
-        this.accessKeyId = accessKeyId;
-        this.accessKeySecret = accessKeySecret;
-        this.domain = domain;
-        this.domainBackup = domainBackup;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.aliyun;
+//
+// /**
+//  * 阿里云存储账号信息
+//  */
+// public class AliYunAccount {
+//
+//     private String bucket;
+//
+//     private String ossEndpoint;
+//
+//     private String accessKeyId;
+//
+//     private String accessKeySecret;
+//
+//     private String domain;
+//
+//     private String domainBackup;
+//
+//     public String getBucket() {
+//         return bucket;
+//     }
+//
+//     public void setBucket(String bucket) {
+//         this.bucket = bucket;
+//     }
+//
+//     public String getOssEndpoint() {
+//         return ossEndpoint;
+//     }
+//
+//     public void setOssEndpoint(String ossEndpoint) {
+//         this.ossEndpoint = ossEndpoint;
+//     }
+//
+//     public String getAccessKeyId() {
+//         return accessKeyId;
+//     }
+//
+//     public void setAccessKeyId(String accessKeyId) {
+//         this.accessKeyId = accessKeyId;
+//     }
+//
+//     public String getAccessKeySecret() {
+//         return accessKeySecret;
+//     }
+//
+//     public void setAccessKeySecret(String accessKeySecret) {
+//         this.accessKeySecret = accessKeySecret;
+//     }
+//
+//     public String getDomain() {
+//         return domain;
+//     }
+//
+//     public void setDomain(String domain) {
+//         this.domain = domain;
+//     }
+//
+//     public String getDomainBackup() {
+//         return domainBackup;
+//     }
+//
+//     public void setDomainBackup(String domainBackup) {
+//         this.domainBackup = domainBackup;
+//     }
+//
+//     public AliYunAccount(String bucket, String ossEndpoint, String accessKeyId, String accessKeySecret, String domain,
+//                          String domainBackup) {
+//         super();
+//         this.bucket = bucket;
+//         this.ossEndpoint = ossEndpoint;
+//         this.accessKeyId = accessKeyId;
+//         this.accessKeySecret = accessKeySecret;
+//         this.domain = domain;
+//         this.domainBackup = domainBackup;
+//     }
+//
+// }

+ 63 - 63
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/AliyunSite.java

@@ -1,63 +1,63 @@
-package cn.com.qmth.examcloud.web.aliyun;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-/**
- * 类注释
- */
-public class AliyunSite implements JsonSerializable {
-
-    private static final long serialVersionUID = -1754474062438702321L;
-
-    private String id;
-
-    private String name;
-
-    private String aliyunId;
-
-    private String maxSize;
-
-    private String path;
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getMaxSize() {
-        return maxSize;
-    }
-
-    public void setMaxSize(String maxSize) {
-        this.maxSize = maxSize;
-    }
-
-    public String getPath() {
-        return path;
-    }
-
-    public void setPath(String path) {
-        this.path = path;
-    }
-
-    public String getAliyunId() {
-        return aliyunId;
-    }
-
-    public void setAliyunId(String aliyunId) {
-        this.aliyunId = aliyunId;
-    }
-
-
-}
+// package cn.com.qmth.examcloud.web.aliyun;
+//
+// import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+//
+// /**
+//  * 类注释
+//  */
+// public class AliyunSite implements JsonSerializable {
+//
+//     private static final long serialVersionUID = -1754474062438702321L;
+//
+//     private String id;
+//
+//     private String name;
+//
+//     private String aliyunId;
+//
+//     private String maxSize;
+//
+//     private String path;
+//
+//     public String getId() {
+//         return id;
+//     }
+//
+//     public void setId(String id) {
+//         this.id = id;
+//     }
+//
+//     public String getName() {
+//         return name;
+//     }
+//
+//     public void setName(String name) {
+//         this.name = name;
+//     }
+//
+//     public String getMaxSize() {
+//         return maxSize;
+//     }
+//
+//     public void setMaxSize(String maxSize) {
+//         this.maxSize = maxSize;
+//     }
+//
+//     public String getPath() {
+//         return path;
+//     }
+//
+//     public void setPath(String path) {
+//         this.path = path;
+//     }
+//
+//     public String getAliyunId() {
+//         return aliyunId;
+//     }
+//
+//     public void setAliyunId(String aliyunId) {
+//         this.aliyunId = aliyunId;
+//     }
+//
+//
+// }

+ 135 - 135
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/AliyunSiteManager.java

@@ -1,135 +1,135 @@
-package cn.com.qmth.examcloud.web.aliyun;
-
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.helpers.XStreamBuilder;
-import cn.com.qmth.examcloud.commons.util.PathUtil;
-import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.OSSClientBuilder;
-import com.thoughtworks.xstream.XStream;
-import org.apache.commons.lang3.StringUtils;
-
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * aliyun site manager
- */
-public class AliyunSiteManager {
-
-    private static final Map<String, AliyunSite> SITE_HOLDERS = new ConcurrentHashMap<>();
-
-    private static final Map<String, OSS> CLIENT_HOLDERS = new ConcurrentHashMap<>();
-
-    private static final Map<String, AliYunAccount> ACCOUNT_HOLDERS = new ConcurrentHashMap<>();
-
-    public static void initSite() {
-        String resoucePath = PathUtil.getResoucePath("aliyun.xml");
-        File file = new File(resoucePath);
-
-        XStream xStream = XStreamBuilder.newInstance().build();
-        xStream.allowTypes(new Class[]{AliyunSite.class, List.class});
-        xStream.alias("sites", List.class);
-        xStream.alias("site", AliyunSite.class);
-
-        List<AliyunSite> list = null;
-        try {
-            @SuppressWarnings("unchecked")
-            List<AliyunSite> obj = (List<AliyunSite>) xStream.fromXML(file);
-            list = obj;
-        } catch (Exception e) {
-            throw new StatusException("20001", "aliyun.xml is wrong", e);
-        }
-
-        for (AliyunSite aliyunSite : list) {
-
-            SITE_HOLDERS.put(aliyunSite.getId(), aliyunSite);
-        }
-
-    }
-
-    public static void initClient() {
-        String aliyunNum = PropertyHolder.getString("$aliyun.site.num");
-        if (StringUtils.isBlank(aliyunNum)) {
-            throw new StatusException("20021", "aliyunNum is not configured.");
-        }
-        int num = Integer.parseInt(aliyunNum);
-        for (int i = 1; i <= num; i++) {
-            String aliyunId = i + "";
-            String bucket = PropertyHolder.getString("$aliyun.site." + aliyunId + ".bucket");
-            String ossEndpoint = PropertyHolder.getString("$aliyun.site." + aliyunId + ".ossEndpoint");
-
-            String accessKeyId = PropertyHolder.getString("$aliyun.site." + aliyunId + ".accessKeyId");
-            String accessKeySecret = PropertyHolder.getString("$aliyun.site." + aliyunId + ".accessKeySecret");
-            String domain = PropertyHolder.getString("$aliyun.site." + aliyunId + ".domain");
-            String domainBackup = PropertyHolder.getString("$aliyun.site." + aliyunId + ".domain.backup");
-
-            if (StringUtils.isBlank(bucket)) {
-                throw new StatusException("20001", "bucket is not configured. aliyunId=" + aliyunId);
-            }
-            if (StringUtils.isBlank(ossEndpoint)) {
-                throw new StatusException("20002", "ossEndpoint is not configured. aliyunId=" + aliyunId);
-            }
-            if (StringUtils.isBlank(accessKeyId)) {
-                throw new StatusException("20003", "accessKeyId is not configured. aliyunId=" + aliyunId);
-            }
-            if (StringUtils.isBlank(accessKeySecret)) {
-                throw new StatusException("20004", "accessKeySecret is not configured. aliyunId=" + aliyunId);
-            }
-            if (StringUtils.isBlank(domain)) {
-                throw new StatusException("20005", "domain is not configured. aliyunId=" + aliyunId);
-            }
-            if (null == ACCOUNT_HOLDERS.get(aliyunId)) {
-                AliYunAccount ac = new AliYunAccount(bucket, ossEndpoint, accessKeyId, accessKeySecret, domain,
-                        domainBackup);
-                ACCOUNT_HOLDERS.put(aliyunId, ac);
-            }
-            if (null == CLIENT_HOLDERS.get(aliyunId)) {
-                OSS ossClient = new OSSClientBuilder().build(ossEndpoint, accessKeyId, accessKeySecret);
-                CLIENT_HOLDERS.put(aliyunId, ossClient);
-            }
-        }
-    }
-
-    /**
-     * 方法注释
-     *
-     * @param siteId
-     * @return
-     * @author
-     */
-    public static AliyunSite getAliyunSite(String siteId) {
-        AliyunSite aliyunSite = SITE_HOLDERS.get(siteId);
-
-        if (null == aliyunSite) {
-            throw new StatusException("20006", "aliyun.xml siteId not exist.");
-        }
-        return aliyunSite;
-    }
-
-    public static AliYunAccount getAliYunAccountByAliyunId(String aliyunId) {
-        AliYunAccount ac = ACCOUNT_HOLDERS.get(aliyunId);
-
-        if (null == ac) {
-            throw new StatusException("20007", "AliYunAccount is null");
-        }
-        return ac;
-    }
-
-    public static OSS getAliYunClientByAliyunId(String aliyunId) {
-        OSS oss = CLIENT_HOLDERS.get(aliyunId);
-
-        if (null == oss) {
-            throw new StatusException("20008", "aliYunClient is null");
-        }
-        return oss;
-    }
-
-    public static OSS getAliYunClientBySiteId(String siteId) {
-        AliyunSite site = getAliyunSite(siteId);
-        return getAliYunClientByAliyunId(site.getAliyunId());
-    }
-
-}
+// package cn.com.qmth.examcloud.web.aliyun;
+//
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.commons.helpers.XStreamBuilder;
+// import cn.com.qmth.examcloud.commons.util.PathUtil;
+// import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
+// import com.aliyun.oss.OSS;
+// import com.aliyun.oss.OSSClientBuilder;
+// import com.thoughtworks.xstream.XStream;
+// import org.apache.commons.lang3.StringUtils;
+//
+// import java.io.File;
+// import java.util.List;
+// import java.util.Map;
+// import java.util.concurrent.ConcurrentHashMap;
+//
+// /**
+//  * aliyun site manager
+//  */
+// public class AliyunSiteManager {
+//
+//     private static final Map<String, AliyunSite> SITE_HOLDERS = new ConcurrentHashMap<>();
+//
+//     private static final Map<String, OSS> CLIENT_HOLDERS = new ConcurrentHashMap<>();
+//
+//     private static final Map<String, AliYunAccount> ACCOUNT_HOLDERS = new ConcurrentHashMap<>();
+//
+//     public static void initSite() {
+//         String resoucePath = PathUtil.getResoucePath("aliyun.xml");
+//         File file = new File(resoucePath);
+//
+//         XStream xStream = XStreamBuilder.newInstance().build();
+//         xStream.allowTypes(new Class[]{AliyunSite.class, List.class});
+//         xStream.alias("sites", List.class);
+//         xStream.alias("site", AliyunSite.class);
+//
+//         List<AliyunSite> list = null;
+//         try {
+//             @SuppressWarnings("unchecked")
+//             List<AliyunSite> obj = (List<AliyunSite>) xStream.fromXML(file);
+//             list = obj;
+//         } catch (Exception e) {
+//             throw new StatusException("20001", "aliyun.xml is wrong", e);
+//         }
+//
+//         for (AliyunSite aliyunSite : list) {
+//
+//             SITE_HOLDERS.put(aliyunSite.getId(), aliyunSite);
+//         }
+//
+//     }
+//
+//     public static void initClient() {
+//         String aliyunNum = PropertyHolder.getString("$aliyun.site.num");
+//         if (StringUtils.isBlank(aliyunNum)) {
+//             throw new StatusException("20021", "aliyunNum is not configured.");
+//         }
+//         int num = Integer.parseInt(aliyunNum);
+//         for (int i = 1; i <= num; i++) {
+//             String aliyunId = i + "";
+//             String bucket = PropertyHolder.getString("$aliyun.site." + aliyunId + ".bucket");
+//             String ossEndpoint = PropertyHolder.getString("$aliyun.site." + aliyunId + ".ossEndpoint");
+//
+//             String accessKeyId = PropertyHolder.getString("$aliyun.site." + aliyunId + ".accessKeyId");
+//             String accessKeySecret = PropertyHolder.getString("$aliyun.site." + aliyunId + ".accessKeySecret");
+//             String domain = PropertyHolder.getString("$aliyun.site." + aliyunId + ".domain");
+//             String domainBackup = PropertyHolder.getString("$aliyun.site." + aliyunId + ".domain.backup");
+//
+//             if (StringUtils.isBlank(bucket)) {
+//                 throw new StatusException("20001", "bucket is not configured. aliyunId=" + aliyunId);
+//             }
+//             if (StringUtils.isBlank(ossEndpoint)) {
+//                 throw new StatusException("20002", "ossEndpoint is not configured. aliyunId=" + aliyunId);
+//             }
+//             if (StringUtils.isBlank(accessKeyId)) {
+//                 throw new StatusException("20003", "accessKeyId is not configured. aliyunId=" + aliyunId);
+//             }
+//             if (StringUtils.isBlank(accessKeySecret)) {
+//                 throw new StatusException("20004", "accessKeySecret is not configured. aliyunId=" + aliyunId);
+//             }
+//             if (StringUtils.isBlank(domain)) {
+//                 throw new StatusException("20005", "domain is not configured. aliyunId=" + aliyunId);
+//             }
+//             if (null == ACCOUNT_HOLDERS.get(aliyunId)) {
+//                 AliYunAccount ac = new AliYunAccount(bucket, ossEndpoint, accessKeyId, accessKeySecret, domain,
+//                         domainBackup);
+//                 ACCOUNT_HOLDERS.put(aliyunId, ac);
+//             }
+//             if (null == CLIENT_HOLDERS.get(aliyunId)) {
+//                 OSS ossClient = new OSSClientBuilder().build(ossEndpoint, accessKeyId, accessKeySecret);
+//                 CLIENT_HOLDERS.put(aliyunId, ossClient);
+//             }
+//         }
+//     }
+//
+//     /**
+//      * 方法注释
+//      *
+//      * @param siteId
+//      * @return
+//      * @author
+//      */
+//     public static AliyunSite getAliyunSite(String siteId) {
+//         AliyunSite aliyunSite = SITE_HOLDERS.get(siteId);
+//
+//         if (null == aliyunSite) {
+//             throw new StatusException("20006", "aliyun.xml siteId not exist.");
+//         }
+//         return aliyunSite;
+//     }
+//
+//     public static AliYunAccount getAliYunAccountByAliyunId(String aliyunId) {
+//         AliYunAccount ac = ACCOUNT_HOLDERS.get(aliyunId);
+//
+//         if (null == ac) {
+//             throw new StatusException("20007", "AliYunAccount is null");
+//         }
+//         return ac;
+//     }
+//
+//     public static OSS getAliYunClientByAliyunId(String aliyunId) {
+//         OSS oss = CLIENT_HOLDERS.get(aliyunId);
+//
+//         if (null == oss) {
+//             throw new StatusException("20008", "aliYunClient is null");
+//         }
+//         return oss;
+//     }
+//
+//     public static OSS getAliYunClientBySiteId(String siteId) {
+//         AliyunSite site = getAliyunSite(siteId);
+//         return getAliYunClientByAliyunId(site.getAliyunId());
+//     }
+//
+// }

+ 220 - 220
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/aliyun/OssClient.java

@@ -1,220 +1,220 @@
-package cn.com.qmth.examcloud.web.aliyun;
-
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.web.config.SystemProperties;
-import com.aliyun.oss.ClientBuilderConfiguration;
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.OSSClientBuilder;
-import com.aliyun.oss.model.GetObjectRequest;
-import com.aliyun.oss.model.OSSObject;
-import com.aliyuncs.DefaultAcsClient;
-import com.aliyuncs.IAcsClient;
-import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesRequest;
-import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesResponse;
-import com.aliyuncs.profile.DefaultProfile;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStream;
-
-@Component
-public class OssClient {
-
-    private static final Logger log = LoggerFactory.getLogger(OssClient.class);
-
-    @Autowired
-    private SystemProperties properties;
-
-    public String upload(File file, String ossFilePath) {
-        return this.upload(file, ossFilePath, false);
-    }
-
-    public String upload(File file, String ossFilePath, boolean refreshCDNCache) {
-        OSS ossClient = this.getClient();
-        ossFilePath = this.fixOssFilePath(ossFilePath);
-
-        try {
-            // ObjectMetadata meta = new ObjectMetadata();
-            // meta.setContentMD5(md5);
-            ossClient.putObject(properties.getAliyunBucketName(), ossFilePath, file);
-
-            String ossFileUrl = properties.getAliyunDomain() + "/" + ossFilePath;
-            if (refreshCDNCache) {
-                this.refreshCDNCache(ossFileUrl);
-            }
-
-            return ossFileUrl;
-        } catch (Exception e) {
-            log.error("文件上传异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
-            throw new StatusException("文件上传异常!");
-        } finally {
-            try {
-                ossClient.shutdown();
-            } catch (Exception e) {
-                // ignore
-            }
-        }
-    }
-
-    public String upload(byte[] fileBytes, String ossFilePath) {
-        return this.upload(fileBytes, ossFilePath, false);
-    }
-
-    public String upload(byte[] fileBytes, String ossFilePath, boolean refreshCDNCache) {
-        OSS ossClient = this.getClient();
-        ossFilePath = this.fixOssFilePath(ossFilePath);
-
-        try (ByteArrayInputStream input = new ByteArrayInputStream(fileBytes);) {
-            ossClient.putObject(properties.getAliyunBucketName(), ossFilePath, input);
-
-            String ossFileUrl = properties.getAliyunDomain() + "/" + ossFilePath;
-            if (refreshCDNCache) {
-                this.refreshCDNCache(ossFileUrl);
-            }
-
-            return ossFileUrl;
-        } catch (Exception e) {
-            log.error("文件上传异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
-            throw new StatusException("文件上传异常!");
-        } finally {
-            try {
-                ossClient.shutdown();
-            } catch (Exception e) {
-                // ignore
-            }
-        }
-    }
-
-    public void download(String ossFilePath, File toFile) {
-        OSS ossClient = this.getClient();
-        ossFilePath = this.fixOssFilePath(ossFilePath);
-
-        try {
-            GetObjectRequest request = new GetObjectRequest(properties.getAliyunBucketName(), ossFilePath);
-            ossClient.getObject(request, toFile);
-        } catch (Exception e) {
-            log.error("文件下载异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
-            throw new StatusException("文件下载异常!");
-        } finally {
-            try {
-                ossClient.shutdown();
-            } catch (Exception e) {
-                // ignore
-            }
-        }
-    }
-
-    public byte[] download(String ossFilePath) {
-        OSS ossClient = this.getClient();
-        ossFilePath = this.fixOssFilePath(ossFilePath);
-
-        InputStream is = null;
-        ByteArrayOutputStream bos = null;
-        try {
-            GetObjectRequest request = new GetObjectRequest(properties.getAliyunBucketName(), ossFilePath);
-            OSSObject ossObject = ossClient.getObject(request);
-
-            is = ossObject.getObjectContent();
-            bos = new ByteArrayOutputStream();
-
-            int len;
-            byte[] bytes = new byte[1024];
-            while ((len = is.read(bytes)) != -1) {
-                bos.write(bytes, 0, len);
-            }
-            bos.flush();
-            ossObject.close();
-
-            return bos.toByteArray();
-        } catch (Exception e) {
-            log.error("文件下载异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
-            throw new StatusException("文件下载异常!");
-        } finally {
-            try {
-                ossClient.shutdown();
-                if (is != null) {
-                    is.close();
-                }
-                if (bos != null) {
-                    bos.close();
-                }
-            } catch (Exception e) {
-                // ignore
-            }
-        }
-    }
-
-    /**
-     * 刷新文件的CDN缓存:
-     * 1、同一个账号 每天最多可提交2000条URL刷新和100个目录刷新
-     * 2、每次请求最多只能提交1000条URL刷新,多个URL之间需要用换行符 \n 分割
-     * 3、每秒最多50次请求
-     */
-    public void refreshCDNCache(String ossFileUrls) {
-        // 默认OSS区域ID,注意要和“外网Endpoint”保持一致(后续改为可配置!)
-        final String regionId = "oss-cn-shenzhen";
-
-        DefaultProfile profile = DefaultProfile.getProfile(regionId,
-                properties.getAccessKeyId(), properties.getAccessKeySecret());
-        IAcsClient client = new DefaultAcsClient(profile);
-
-        RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
-        request.setObjectPath(ossFileUrls);
-        request.setObjectType("file");
-
-        try {
-            RefreshObjectCachesResponse resp = client.getAcsResponse(request);
-
-            log.info("refreshCDNCache:{} RequestId:{}", ossFileUrls, resp != null ? resp.getRequestId() : "none");
-        } catch (Exception e) {
-            log.error("refreshCDNCache:{} err:{}", ossFileUrls, e.getMessage());
-        }
-    }
-
-    /**
-     * 将“OSS文件访问地址”去掉“域名”部分
-     */
-    public String valueOfOssFilePath(String fileUrl) {
-        if (fileUrl == null) {
-            return null;
-        }
-
-        String ossFilePath = fileUrl.replace(properties.getAliyunDomain(), "");
-        return this.fixOssFilePath(ossFilePath);
-    }
-
-    private String fixOssFilePath(String ossFilePath) {
-        // OSS file path must be not start with '/'
-        if (ossFilePath.startsWith("/")) {
-            return ossFilePath.substring(1);
-        }
-
-        return ossFilePath;
-    }
-
-    public OSS getClient() {
-        ClientBuilderConfiguration configuration = new ClientBuilderConfiguration();
-
-        OSS client = new OSSClientBuilder().build(
-                properties.getAliyunOssEndpoint(),
-                properties.getAccessKeyId(),
-                properties.getAccessKeySecret(),
-                configuration
-        );
-        return client;
-    }
-
-    public SystemProperties getProperties() {
-        return properties;
-    }
-
-    public void setProperties(SystemProperties properties) {
-        this.properties = properties;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.aliyun;
+//
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.web.config.SystemProperties;
+// import com.aliyun.oss.ClientBuilderConfiguration;
+// import com.aliyun.oss.OSS;
+// import com.aliyun.oss.OSSClientBuilder;
+// import com.aliyun.oss.model.GetObjectRequest;
+// import com.aliyun.oss.model.OSSObject;
+// import com.aliyuncs.DefaultAcsClient;
+// import com.aliyuncs.IAcsClient;
+// import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesRequest;
+// import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesResponse;
+// import com.aliyuncs.profile.DefaultProfile;
+// import org.slf4j.Logger;
+// import org.slf4j.LoggerFactory;
+// import org.springframework.beans.factory.annotation.Autowired;
+// import org.springframework.stereotype.Component;
+//
+// import java.io.ByteArrayInputStream;
+// import java.io.ByteArrayOutputStream;
+// import java.io.File;
+// import java.io.InputStream;
+//
+// @Component
+// public class OssClient {
+//
+//     private static final Logger log = LoggerFactory.getLogger(OssClient.class);
+//
+//     @Autowired
+//     private SystemProperties properties;
+//
+//     public String upload(File file, String ossFilePath) {
+//         return this.upload(file, ossFilePath, false);
+//     }
+//
+//     public String upload(File file, String ossFilePath, boolean refreshCDNCache) {
+//         OSS ossClient = this.getClient();
+//         ossFilePath = this.fixOssFilePath(ossFilePath);
+//
+//         try {
+//             // ObjectMetadata meta = new ObjectMetadata();
+//             // meta.setContentMD5(md5);
+//             ossClient.putObject(properties.getAliyunBucketName(), ossFilePath, file);
+//
+//             String ossFileUrl = properties.getAliyunDomain() + "/" + ossFilePath;
+//             if (refreshCDNCache) {
+//                 this.refreshCDNCache(ossFileUrl);
+//             }
+//
+//             return ossFileUrl;
+//         } catch (Exception e) {
+//             log.error("文件上传异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+//             throw new StatusException("文件上传异常!");
+//         } finally {
+//             try {
+//                 ossClient.shutdown();
+//             } catch (Exception e) {
+//                 // ignore
+//             }
+//         }
+//     }
+//
+//     public String upload(byte[] fileBytes, String ossFilePath) {
+//         return this.upload(fileBytes, ossFilePath, false);
+//     }
+//
+//     public String upload(byte[] fileBytes, String ossFilePath, boolean refreshCDNCache) {
+//         OSS ossClient = this.getClient();
+//         ossFilePath = this.fixOssFilePath(ossFilePath);
+//
+//         try (ByteArrayInputStream input = new ByteArrayInputStream(fileBytes);) {
+//             ossClient.putObject(properties.getAliyunBucketName(), ossFilePath, input);
+//
+//             String ossFileUrl = properties.getAliyunDomain() + "/" + ossFilePath;
+//             if (refreshCDNCache) {
+//                 this.refreshCDNCache(ossFileUrl);
+//             }
+//
+//             return ossFileUrl;
+//         } catch (Exception e) {
+//             log.error("文件上传异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+//             throw new StatusException("文件上传异常!");
+//         } finally {
+//             try {
+//                 ossClient.shutdown();
+//             } catch (Exception e) {
+//                 // ignore
+//             }
+//         }
+//     }
+//
+//     public void download(String ossFilePath, File toFile) {
+//         OSS ossClient = this.getClient();
+//         ossFilePath = this.fixOssFilePath(ossFilePath);
+//
+//         try {
+//             GetObjectRequest request = new GetObjectRequest(properties.getAliyunBucketName(), ossFilePath);
+//             ossClient.getObject(request, toFile);
+//         } catch (Exception e) {
+//             log.error("文件下载异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+//             throw new StatusException("文件下载异常!");
+//         } finally {
+//             try {
+//                 ossClient.shutdown();
+//             } catch (Exception e) {
+//                 // ignore
+//             }
+//         }
+//     }
+//
+//     public byte[] download(String ossFilePath) {
+//         OSS ossClient = this.getClient();
+//         ossFilePath = this.fixOssFilePath(ossFilePath);
+//
+//         InputStream is = null;
+//         ByteArrayOutputStream bos = null;
+//         try {
+//             GetObjectRequest request = new GetObjectRequest(properties.getAliyunBucketName(), ossFilePath);
+//             OSSObject ossObject = ossClient.getObject(request);
+//
+//             is = ossObject.getObjectContent();
+//             bos = new ByteArrayOutputStream();
+//
+//             int len;
+//             byte[] bytes = new byte[1024];
+//             while ((len = is.read(bytes)) != -1) {
+//                 bos.write(bytes, 0, len);
+//             }
+//             bos.flush();
+//             ossObject.close();
+//
+//             return bos.toByteArray();
+//         } catch (Exception e) {
+//             log.error("文件下载异常! ossFilePath:{} err:{}", ossFilePath, e.getMessage());
+//             throw new StatusException("文件下载异常!");
+//         } finally {
+//             try {
+//                 ossClient.shutdown();
+//                 if (is != null) {
+//                     is.close();
+//                 }
+//                 if (bos != null) {
+//                     bos.close();
+//                 }
+//             } catch (Exception e) {
+//                 // ignore
+//             }
+//         }
+//     }
+//
+//     /**
+//      * 刷新文件的CDN缓存:
+//      * 1、同一个账号 每天最多可提交2000条URL刷新和100个目录刷新
+//      * 2、每次请求最多只能提交1000条URL刷新,多个URL之间需要用换行符 \n 分割
+//      * 3、每秒最多50次请求
+//      */
+//     public void refreshCDNCache(String ossFileUrls) {
+//         // 默认OSS区域ID,注意要和“外网Endpoint”保持一致(后续改为可配置!)
+//         final String regionId = "oss-cn-shenzhen";
+//
+//         DefaultProfile profile = DefaultProfile.getProfile(regionId,
+//                 properties.getAccessKeyId(), properties.getAccessKeySecret());
+//         IAcsClient client = new DefaultAcsClient(profile);
+//
+//         RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
+//         request.setObjectPath(ossFileUrls);
+//         request.setObjectType("file");
+//
+//         try {
+//             RefreshObjectCachesResponse resp = client.getAcsResponse(request);
+//
+//             log.info("refreshCDNCache:{} RequestId:{}", ossFileUrls, resp != null ? resp.getRequestId() : "none");
+//         } catch (Exception e) {
+//             log.error("refreshCDNCache:{} err:{}", ossFileUrls, e.getMessage());
+//         }
+//     }
+//
+//     /**
+//      * 将“OSS文件访问地址”去掉“域名”部分
+//      */
+//     public String valueOfOssFilePath(String fileUrl) {
+//         if (fileUrl == null) {
+//             return null;
+//         }
+//
+//         String ossFilePath = fileUrl.replace(properties.getAliyunDomain(), "");
+//         return this.fixOssFilePath(ossFilePath);
+//     }
+//
+//     private String fixOssFilePath(String ossFilePath) {
+//         // OSS file path must be not start with '/'
+//         if (ossFilePath.startsWith("/")) {
+//             return ossFilePath.substring(1);
+//         }
+//
+//         return ossFilePath;
+//     }
+//
+//     public OSS getClient() {
+//         ClientBuilderConfiguration configuration = new ClientBuilderConfiguration();
+//
+//         OSS client = new OSSClientBuilder().build(
+//                 properties.getAliyunOssEndpoint(),
+//                 properties.getAccessKeyId(),
+//                 properties.getAccessKeySecret(),
+//                 configuration
+//         );
+//         return client;
+//     }
+//
+//     public SystemProperties getProperties() {
+//         return properties;
+//     }
+//
+//     public void setProperties(SystemProperties properties) {
+//         this.properties = properties;
+//     }
+//
+// }

+ 87 - 87
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorage.java

@@ -1,87 +1,87 @@
-package cn.com.qmth.examcloud.web.filestorage;
-
-import java.io.File;
-import java.io.InputStream;
-
-public interface FileStorage {
-
-    /**
-     * 保存文件到存储服务
-     *
-     * @param siteId
-     * @param env
-     * @param in         文件流
-     * @param md5        文件MD5 可为空
-     * @param refreshCDN 是否刷新CDN缓存
-     * @return 返回路径
-     */
-    YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN);
-
-    /**
-     * 保存文件到存储服务
-     *
-     * @param siteId
-     * @param env
-     * @param file       文件
-     * @param md5        文件MD5 可为空
-     * @param refreshCDN 是否刷新CDN缓存
-     * @return 返回路径
-     */
-    YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN);
-
-    YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN, Long cacheAge);
-
-    /**
-     * 保存文件到存储服务
-     *
-     * @param siteId
-     * @param env
-     * @param bytes
-     * @param refreshCDN 是否刷新CDN缓存
-     * @return
-     */
-    YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN);
-
-    /**
-     * 获取可直接访问的文件地址
-     *
-     * @param path 全路径,包含根目录,含协议名
-     * @return 返回可直接访问的地址
-     */
-    String realPath(String path);
-
-    /**
-     * 获取可直接访问的文件地址(备用域名地址)
-     *
-     * @param path 全路径,包含根目录,含协议名
-     * @return 返回可直接访问的地址, 如果没有配置备用地址,则返回主域名地址
-     */
-    String realPathBackup(String path);
-
-    /**
-     * 保存文件到存储服务,siteId为1,转换接口用
-     *
-     * @param file 文件
-     * @param path 全路径,含协议名
-     * @return 返回路径
-     */
-    YunPathInfo saveFile(File file, String path);
-
-    /**
-     * 获取云存储签名
-     *
-     * @param siteId
-     * @param env
-     * @param md5
-     * @return
-     */
-    YunHttpRequest getSignature(String siteId, FileStoragePathEnvInfo env, String md5);
-
-    /**
-     * 删除文件
-     *
-     * @param path 全路径,含协议名
-     */
-    void deleteFile(String path);
-
-}
+// package cn.com.qmth.examcloud.web.filestorage;
+//
+// import java.io.File;
+// import java.io.InputStream;
+//
+// public interface FileStorage {
+//
+//     /**
+//      * 保存文件到存储服务
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param in         文件流
+//      * @param md5        文件MD5 可为空
+//      * @param refreshCDN 是否刷新CDN缓存
+//      * @return 返回路径
+//      */
+//     YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN);
+//
+//     /**
+//      * 保存文件到存储服务
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param file       文件
+//      * @param md5        文件MD5 可为空
+//      * @param refreshCDN 是否刷新CDN缓存
+//      * @return 返回路径
+//      */
+//     YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN);
+//
+//     YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN, Long cacheAge);
+//
+//     /**
+//      * 保存文件到存储服务
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param bytes
+//      * @param refreshCDN 是否刷新CDN缓存
+//      * @return
+//      */
+//     YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN);
+//
+//     /**
+//      * 获取可直接访问的文件地址
+//      *
+//      * @param path 全路径,包含根目录,含协议名
+//      * @return 返回可直接访问的地址
+//      */
+//     String realPath(String path);
+//
+//     /**
+//      * 获取可直接访问的文件地址(备用域名地址)
+//      *
+//      * @param path 全路径,包含根目录,含协议名
+//      * @return 返回可直接访问的地址, 如果没有配置备用地址,则返回主域名地址
+//      */
+//     String realPathBackup(String path);
+//
+//     /**
+//      * 保存文件到存储服务,siteId为1,转换接口用
+//      *
+//      * @param file 文件
+//      * @param path 全路径,含协议名
+//      * @return 返回路径
+//      */
+//     YunPathInfo saveFile(File file, String path);
+//
+//     /**
+//      * 获取云存储签名
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param md5
+//      * @return
+//      */
+//     YunHttpRequest getSignature(String siteId, FileStoragePathEnvInfo env, String md5);
+//
+//     /**
+//      * 删除文件
+//      *
+//      * @param path 全路径,含协议名
+//      */
+//     void deleteFile(String path);
+//
+// }

+ 80 - 80
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorageHelper.java

@@ -1,80 +1,80 @@
-package cn.com.qmth.examcloud.web.filestorage;
-
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import org.apache.commons.lang3.StringUtils;
-
-public class FileStorageHelper {
-
-    private static String connector = "://";
-
-    public static String getUpyunSiteOne(String path) {
-        return FileStorageType.UPYUN.name().toLowerCase() + "-1" + connector + path;
-    }
-
-    public static String getUrl(String domain, String path) {
-        if (StringUtils.isBlank(domain)) {
-            return null;
-        }
-        if (StringUtils.isBlank(path)) {
-            return null;
-        }
-        if (path.startsWith("/")) {
-            path = path.substring(1);
-        }
-        if (domain.endsWith("/")) {
-            domain = domain.substring(0, domain.length());
-        }
-        return domain + "/" + path;
-    }
-
-    public static String getYunId(String path) {
-        if (StringUtils.isBlank(path)) {
-            return null;
-        }
-        if (path.indexOf(connector) == -1) {
-            throw new StatusException("7001", "文件路径格式错误:" + path);
-        }
-        String hpath = path.substring(0, path.indexOf(connector));
-        if (hpath.indexOf("-") == -1) {
-            throw new StatusException("7002", "文件路径格式错误:" + path);
-        }
-        String yunId = hpath.substring(hpath.indexOf("-") + 1);
-        if (StringUtils.isBlank(yunId)) {
-            throw new StatusException("7003", "文件路径格式错误:" + path);
-        }
-        return yunId;
-    }
-
-    public static String getHead(String path) {
-        if (StringUtils.isBlank(path)) {
-            return null;
-        }
-        if (path.indexOf(connector) == -1) {
-            throw new StatusException("8001", "文件路径格式错误:" + path);
-        }
-        String hpath = path.substring(0, path.indexOf(connector));
-        if (hpath.indexOf("-") == -1) {
-            throw new StatusException("8002", "文件路径格式错误:" + path);
-        }
-        String head = hpath.substring(0, hpath.indexOf("-"));
-        if (StringUtils.isBlank(head)) {
-            throw new StatusException("8003", "文件路径格式错误:" + path);
-        }
-        return head;
-    }
-
-    public static String getPath(String path) {
-        if (StringUtils.isBlank(path)) {
-            return null;
-        }
-        if (path.indexOf(connector) == -1) {
-            throw new StatusException("9001", "文件路径格式错误:" + path);
-        }
-        String rpath = path.substring(path.indexOf(connector) + 3);
-        if (StringUtils.isBlank(rpath)) {
-            throw new StatusException("9002", "文件路径格式错误:" + path);
-        }
-        return rpath;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.filestorage;
+//
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import org.apache.commons.lang3.StringUtils;
+//
+// public class FileStorageHelper {
+//
+//     private static String connector = "://";
+//
+//     public static String getUpyunSiteOne(String path) {
+//         return FileStorageType.UPYUN.name().toLowerCase() + "-1" + connector + path;
+//     }
+//
+//     public static String getUrl(String domain, String path) {
+//         if (StringUtils.isBlank(domain)) {
+//             return null;
+//         }
+//         if (StringUtils.isBlank(path)) {
+//             return null;
+//         }
+//         if (path.startsWith("/")) {
+//             path = path.substring(1);
+//         }
+//         if (domain.endsWith("/")) {
+//             domain = domain.substring(0, domain.length());
+//         }
+//         return domain + "/" + path;
+//     }
+//
+//     public static String getYunId(String path) {
+//         if (StringUtils.isBlank(path)) {
+//             return null;
+//         }
+//         if (path.indexOf(connector) == -1) {
+//             throw new StatusException("7001", "文件路径格式错误:" + path);
+//         }
+//         String hpath = path.substring(0, path.indexOf(connector));
+//         if (hpath.indexOf("-") == -1) {
+//             throw new StatusException("7002", "文件路径格式错误:" + path);
+//         }
+//         String yunId = hpath.substring(hpath.indexOf("-") + 1);
+//         if (StringUtils.isBlank(yunId)) {
+//             throw new StatusException("7003", "文件路径格式错误:" + path);
+//         }
+//         return yunId;
+//     }
+//
+//     public static String getHead(String path) {
+//         if (StringUtils.isBlank(path)) {
+//             return null;
+//         }
+//         if (path.indexOf(connector) == -1) {
+//             throw new StatusException("8001", "文件路径格式错误:" + path);
+//         }
+//         String hpath = path.substring(0, path.indexOf(connector));
+//         if (hpath.indexOf("-") == -1) {
+//             throw new StatusException("8002", "文件路径格式错误:" + path);
+//         }
+//         String head = hpath.substring(0, hpath.indexOf("-"));
+//         if (StringUtils.isBlank(head)) {
+//             throw new StatusException("8003", "文件路径格式错误:" + path);
+//         }
+//         return head;
+//     }
+//
+//     public static String getPath(String path) {
+//         if (StringUtils.isBlank(path)) {
+//             return null;
+//         }
+//         if (path.indexOf(connector) == -1) {
+//             throw new StatusException("9001", "文件路径格式错误:" + path);
+//         }
+//         String rpath = path.substring(path.indexOf(connector) + 3);
+//         if (StringUtils.isBlank(rpath)) {
+//             throw new StatusException("9002", "文件路径格式错误:" + path);
+//         }
+//         return rpath;
+//     }
+//
+// }

+ 159 - 159
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStoragePathEnvInfo.java

@@ -1,159 +1,159 @@
-package cn.com.qmth.examcloud.web.filestorage;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-/**
- * 云存储路径变量
- */
-public class FileStoragePathEnvInfo implements JsonSerializable {
-
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = -5101258662105160433L;
-
-    /**
-     * 顶级机构ID
-     */
-    private String rootOrgId;
-
-    /**
-     * 顶级机构域名
-     */
-    private String rootOrgDomain;
-
-    /**
-     * 用户ID(包含普普通用户ID和studentId)
-     */
-    private String userId;
-
-    /**
-     * 时间戳
-     */
-    private String timeMillis;
-
-    /**
-     * 文件后缀(以"."开头,如 ".jpg",".zip")
-     */
-    private String fileSuffix;
-
-    /**
-     * 相对路径
-     */
-    private String relativePath;
-
-    /**
-     * 扩展属性
-     */
-    private String ext1;
-
-    /**
-     * 扩展属性
-     */
-    private String ext2;
-
-    /**
-     * 扩展属性
-     */
-    private String ext3;
-
-    /**
-     * 扩展属性
-     */
-    private String ext4;
-
-    /**
-     * 扩展属性
-     */
-    private String ext5;
-
-    public String getRootOrgId() {
-        return rootOrgId;
-    }
-
-    public void setRootOrgId(String rootOrgId) {
-        this.rootOrgId = rootOrgId;
-    }
-
-    public String getRootOrgDomain() {
-        return rootOrgDomain;
-    }
-
-    public void setRootOrgDomain(String rootOrgDomain) {
-        this.rootOrgDomain = rootOrgDomain;
-    }
-
-    public String getUserId() {
-        return userId;
-    }
-
-    public void setUserId(String userId) {
-        this.userId = userId;
-    }
-
-    public String getTimeMillis() {
-        return timeMillis;
-    }
-
-    public void setTimeMillis(String timeMillis) {
-        this.timeMillis = timeMillis;
-    }
-
-    public String getFileSuffix() {
-        return fileSuffix;
-    }
-
-    public void setFileSuffix(String fileSuffix) {
-        this.fileSuffix = fileSuffix;
-    }
-
-    public String getRelativePath() {
-        return relativePath;
-    }
-
-    public void setRelativePath(String relativePath) {
-        this.relativePath = relativePath;
-    }
-
-    public String getExt1() {
-        return ext1;
-    }
-
-    public void setExt1(String ext1) {
-        this.ext1 = ext1;
-    }
-
-    public String getExt2() {
-        return ext2;
-    }
-
-    public void setExt2(String ext2) {
-        this.ext2 = ext2;
-    }
-
-    public String getExt3() {
-        return ext3;
-    }
-
-    public void setExt3(String ext3) {
-        this.ext3 = ext3;
-    }
-
-    public String getExt4() {
-        return ext4;
-    }
-
-    public void setExt4(String ext4) {
-        this.ext4 = ext4;
-    }
-
-    public String getExt5() {
-        return ext5;
-    }
-
-    public void setExt5(String ext5) {
-        this.ext5 = ext5;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.filestorage;
+//
+// import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+//
+// /**
+//  * 云存储路径变量
+//  */
+// public class FileStoragePathEnvInfo implements JsonSerializable {
+//
+//
+//     /**
+//      *
+//      */
+//     private static final long serialVersionUID = -5101258662105160433L;
+//
+//     /**
+//      * 顶级机构ID
+//      */
+//     private String rootOrgId;
+//
+//     /**
+//      * 顶级机构域名
+//      */
+//     private String rootOrgDomain;
+//
+//     /**
+//      * 用户ID(包含普普通用户ID和studentId)
+//      */
+//     private String userId;
+//
+//     /**
+//      * 时间戳
+//      */
+//     private String timeMillis;
+//
+//     /**
+//      * 文件后缀(以"."开头,如 ".jpg",".zip")
+//      */
+//     private String fileSuffix;
+//
+//     /**
+//      * 相对路径
+//      */
+//     private String relativePath;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext1;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext2;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext3;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext4;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext5;
+//
+//     public String getRootOrgId() {
+//         return rootOrgId;
+//     }
+//
+//     public void setRootOrgId(String rootOrgId) {
+//         this.rootOrgId = rootOrgId;
+//     }
+//
+//     public String getRootOrgDomain() {
+//         return rootOrgDomain;
+//     }
+//
+//     public void setRootOrgDomain(String rootOrgDomain) {
+//         this.rootOrgDomain = rootOrgDomain;
+//     }
+//
+//     public String getUserId() {
+//         return userId;
+//     }
+//
+//     public void setUserId(String userId) {
+//         this.userId = userId;
+//     }
+//
+//     public String getTimeMillis() {
+//         return timeMillis;
+//     }
+//
+//     public void setTimeMillis(String timeMillis) {
+//         this.timeMillis = timeMillis;
+//     }
+//
+//     public String getFileSuffix() {
+//         return fileSuffix;
+//     }
+//
+//     public void setFileSuffix(String fileSuffix) {
+//         this.fileSuffix = fileSuffix;
+//     }
+//
+//     public String getRelativePath() {
+//         return relativePath;
+//     }
+//
+//     public void setRelativePath(String relativePath) {
+//         this.relativePath = relativePath;
+//     }
+//
+//     public String getExt1() {
+//         return ext1;
+//     }
+//
+//     public void setExt1(String ext1) {
+//         this.ext1 = ext1;
+//     }
+//
+//     public String getExt2() {
+//         return ext2;
+//     }
+//
+//     public void setExt2(String ext2) {
+//         this.ext2 = ext2;
+//     }
+//
+//     public String getExt3() {
+//         return ext3;
+//     }
+//
+//     public void setExt3(String ext3) {
+//         this.ext3 = ext3;
+//     }
+//
+//     public String getExt4() {
+//         return ext4;
+//     }
+//
+//     public void setExt4(String ext4) {
+//         this.ext4 = ext4;
+//     }
+//
+//     public String getExt5() {
+//         return ext5;
+//     }
+//
+//     public void setExt5(String ext5) {
+//         this.ext5 = ext5;
+//     }
+//
+// }

+ 66 - 66
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/FileStorageSite.java

@@ -1,66 +1,66 @@
-package cn.com.qmth.examcloud.web.filestorage;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-/**
- *
- */
-public class FileStorageSite implements JsonSerializable {
-
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 4367301242875120606L;
-
-    private String id;
-
-    private String name;
-
-    private String upyunId;
-
-    private String maxSize;
-
-    private String path;
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getUpyunId() {
-        return upyunId;
-    }
-
-    public void setUpyunId(String upyunId) {
-        this.upyunId = upyunId;
-    }
-
-    public String getMaxSize() {
-        return maxSize;
-    }
-
-    public void setMaxSize(String maxSize) {
-        this.maxSize = maxSize;
-    }
-
-    public String getPath() {
-        return path;
-    }
-
-    public void setPath(String path) {
-        this.path = path;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.filestorage;
+//
+// import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+//
+// /**
+//  *
+//  */
+// public class FileStorageSite implements JsonSerializable {
+//
+//
+//     /**
+//      *
+//      */
+//     private static final long serialVersionUID = 4367301242875120606L;
+//
+//     private String id;
+//
+//     private String name;
+//
+//     private String upyunId;
+//
+//     private String maxSize;
+//
+//     private String path;
+//
+//     public String getId() {
+//         return id;
+//     }
+//
+//     public void setId(String id) {
+//         this.id = id;
+//     }
+//
+//     public String getName() {
+//         return name;
+//     }
+//
+//     public void setName(String name) {
+//         this.name = name;
+//     }
+//
+//     public String getUpyunId() {
+//         return upyunId;
+//     }
+//
+//     public void setUpyunId(String upyunId) {
+//         this.upyunId = upyunId;
+//     }
+//
+//     public String getMaxSize() {
+//         return maxSize;
+//     }
+//
+//     public void setMaxSize(String maxSize) {
+//         this.maxSize = maxSize;
+//     }
+//
+//     public String getPath() {
+//         return path;
+//     }
+//
+//     public void setPath(String path) {
+//         this.path = path;
+//     }
+//
+// }

+ 45 - 45
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/YunHttpRequest.java

@@ -1,45 +1,45 @@
-package cn.com.qmth.examcloud.web.filestorage;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-import java.util.Map;
-
-public class YunHttpRequest implements JsonSerializable {
-
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = -6298376638986327265L;
-
-    private String accessUrl;
-
-    private String formUrl;
-
-    private Map<String, String> formParams;
-
-    public String getAccessUrl() {
-        return accessUrl;
-    }
-
-    public void setAccessUrl(String accessUrl) {
-        this.accessUrl = accessUrl;
-    }
-
-    public String getFormUrl() {
-        return formUrl;
-    }
-
-    public void setFormUrl(String formUrl) {
-        this.formUrl = formUrl;
-    }
-
-    public Map<String, String> getFormParams() {
-        return formParams;
-    }
-
-    public void setFormParams(Map<String, String> formParams) {
-        this.formParams = formParams;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.filestorage;
+//
+// import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+//
+// import java.util.Map;
+//
+// public class YunHttpRequest implements JsonSerializable {
+//
+//
+//     /**
+//      *
+//      */
+//     private static final long serialVersionUID = -6298376638986327265L;
+//
+//     private String accessUrl;
+//
+//     private String formUrl;
+//
+//     private Map<String, String> formParams;
+//
+//     public String getAccessUrl() {
+//         return accessUrl;
+//     }
+//
+//     public void setAccessUrl(String accessUrl) {
+//         this.accessUrl = accessUrl;
+//     }
+//
+//     public String getFormUrl() {
+//         return formUrl;
+//     }
+//
+//     public void setFormUrl(String formUrl) {
+//         this.formUrl = formUrl;
+//     }
+//
+//     public Map<String, String> getFormParams() {
+//         return formParams;
+//     }
+//
+//     public void setFormParams(Map<String, String> formParams) {
+//         this.formParams = formParams;
+//     }
+//
+// }

+ 46 - 46
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/YunPathInfo.java

@@ -1,46 +1,46 @@
-package cn.com.qmth.examcloud.web.filestorage;
-
-/**
- * 路径
- */
-public class YunPathInfo {
-
-    /**
-     * 文件访问地址,http
-     */
-    private String url;
-
-    /**
-     * 返回包含协议名的地址,数据库直接存储用
-     */
-    private String relativePath;
-
-    /**
-     * 构造函数
-     *
-     * @param url
-     * @param relativePath
-     */
-    public YunPathInfo(String url, String relativePath) {
-        super();
-        this.url = url;
-        this.relativePath = relativePath;
-    }
-
-    public String getUrl() {
-        return url;
-    }
-
-    public void setUrl(String url) {
-        this.url = url;
-    }
-
-    public String getRelativePath() {
-        return relativePath;
-    }
-
-    public void setRelativePath(String relativePath) {
-        this.relativePath = relativePath;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.filestorage;
+//
+// /**
+//  * 路径
+//  */
+// public class YunPathInfo {
+//
+//     /**
+//      * 文件访问地址,http
+//      */
+//     private String url;
+//
+//     /**
+//      * 返回包含协议名的地址,数据库直接存储用
+//      */
+//     private String relativePath;
+//
+//     /**
+//      * 构造函数
+//      *
+//      * @param url
+//      * @param relativePath
+//      */
+//     public YunPathInfo(String url, String relativePath) {
+//         super();
+//         this.url = url;
+//         this.relativePath = relativePath;
+//     }
+//
+//     public String getUrl() {
+//         return url;
+//     }
+//
+//     public void setUrl(String url) {
+//         this.url = url;
+//     }
+//
+//     public String getRelativePath() {
+//         return relativePath;
+//     }
+//
+//     public void setRelativePath(String relativePath) {
+//         this.relativePath = relativePath;
+//     }
+//
+// }

+ 553 - 553
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/AliyunFileStorageImpl.java

@@ -1,553 +1,553 @@
-package cn.com.qmth.examcloud.web.filestorage.impl;
-
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.util.DateUtil;
-import cn.com.qmth.examcloud.commons.util.FreeMarkerUtil;
-import cn.com.qmth.examcloud.web.aliyun.AliYunAccount;
-import cn.com.qmth.examcloud.web.aliyun.AliyunSite;
-import cn.com.qmth.examcloud.web.aliyun.AliyunSiteManager;
-import cn.com.qmth.examcloud.web.filestorage.*;
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.model.ObjectMetadata;
-import com.google.common.collect.Maps;
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.time.DateUtils;
-import org.springframework.stereotype.Service;
-
-import java.io.*;
-import java.util.Base64;
-import java.util.Date;
-import java.util.Map;
-
-@Service(value = "aliyunFileStorage")
-public class AliyunFileStorageImpl implements FileStorage {
-
-    // 文件最大大小(byte)
-    private static int maxFileSize = 100 * 1024 * 1024;
-
-    @Override
-    public YunPathInfo saveFile(File file, String path) {
-        String siteId = "transPath";
-        FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
-        env.setRelativePath(path);
-        return saveFile(siteId, env, file, null, false);
-    }
-
-    @Override
-    public String realPath(String path) {
-        String yunId = FileStorageHelper.getYunId(path);
-        String urlpath = FileStorageHelper.getPath(path);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(yunId);
-        return FileStorageHelper.getUrl(ac.getDomain(), urlpath);
-    }
-
-    /**
-     * 表单上传
-     *
-     * @param siteId
-     * @param env
-     * @param file
-     * @param md5
-     * @return 不带域名的完整路径
-     * @throws IOException
-     */
-    /*private String postObject(String siteId, FileStoragePathEnvInfo env, File file, String md5) throws IOException {
-        AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
-        String ossEndpoint = ac.getOssEndpoint();
-        String bucket = ac.getBucket();
-        String accessKeyId = ac.getAccessKeyId();
-        String accessKeySecret = ac.getAccessKeySecret();
-        // 阿里云文件路径
-        String path = FreeMarkerUtil.process(as.getPath(), env);
-        if (path.startsWith("/")) {
-            path = path.substring(1);
-        }
-
-        String filepath = file.getAbsolutePath();
-        String filename = path.substring(path.lastIndexOf("/") + 1);
-        String urlStr = null; // 提交表单的URL为bucket域名
-        if (ossEndpoint.startsWith("https://")) {
-            urlStr = ossEndpoint.replace("https://", "https://" + bucket + ".");
-        } else if (ossEndpoint.startsWith("http://")) {
-            urlStr = ossEndpoint.replace("http://", "http://" + bucket + ".");
-        }
-
-        LinkedHashMap<String, String> textMap = new LinkedHashMap<String, String>();
-        // key
-        textMap.put("key", path);
-        // Content-Disposition
-        textMap.put("Content-Disposition", "attachment;filename=" + filename);
-        // OSSAccessKeyId
-        textMap.put("OSSAccessKeyId", accessKeyId);
-        // policy
-        String policy = "{\"expiration\": \"2120-01-01T12:00:00.000Z\",\"conditions\": [[\"content-length-range\", 0, "
-                + maxFileSize + "]]}";
-        String encodePolicy = java.util.Base64.getEncoder().encodeToString(policy.getBytes());
-        textMap.put("policy", encodePolicy);
-        // Signature
-        String signaturecom = com.aliyun.oss.common.auth.ServiceSignature.create().computeSignature(accessKeySecret,
-                encodePolicy);
-        textMap.put("Signature", signaturecom);
-
-        Map<String, String> fileMap = new HashMap<String, String>();
-        fileMap.put("file", filepath);
-
-        String ret = formUpload(urlStr, textMap, fileMap);
-        log.info("oss上传:" + ret);
-        return path;
-    }*/
-
-    /*@SuppressWarnings("rawtypes")
-    private static String formUpload(String urlStr, Map<String, String> textMap, Map<String, String> fileMap)
-            throws IOException {
-        String res = "";
-        HttpURLConnection conn = null;
-        String BOUNDARY = "9431149156168";
-        try {
-            URL url = new URL(urlStr);
-            conn = (HttpURLConnection) url.openConnection();
-            conn.setConnectTimeout(5000);
-            conn.setReadTimeout(30000);
-            conn.setDoOutput(true);
-            conn.setDoInput(true);
-            conn.setRequestMethod("POST");
-            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
-            conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
-
-            OutputStream out = new DataOutputStream(conn.getOutputStream());
-            // text
-            if (textMap != null) {
-                StringBuffer strBuf = new StringBuffer();
-                Iterator iter = textMap.entrySet().iterator();
-                int i = 0;
-                while (iter.hasNext()) {
-                    Map.Entry entry = (Map.Entry) iter.next();
-                    String inputName = (String) entry.getKey();
-                    String inputValue = (String) entry.getValue();
-                    if (inputValue == null) {
-                        continue;
-                    }
-                    if (i == 0) {
-                        strBuf.append("--").append(BOUNDARY).append("\r\n");
-                        strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
-                        strBuf.append(inputValue);
-                    } else {
-                        strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
-                        strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
-
-                        strBuf.append(inputValue);
-                    }
-
-                    i++;
-                }
-                out.write(strBuf.toString().getBytes());
-            }
-
-            // file
-            if (fileMap != null) {
-                Iterator iter = fileMap.entrySet().iterator();
-                while (iter.hasNext()) {
-                    Map.Entry entry = (Map.Entry) iter.next();
-                    String inputName = (String) entry.getKey();
-                    String inputValue = (String) entry.getValue();
-                    if (inputValue == null) {
-                        continue;
-                    }
-                    File file = new File(inputValue);
-                    String filename = file.getName();
-                    String contentType = new MimetypesFileTypeMap().getContentType(file);
-                    if (contentType == null || contentType.equals("")) {
-                        contentType = "application/octet-stream";
-                    }
-
-                    StringBuffer strBuf = new StringBuffer();
-                    strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
-                    strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"; filename=\"" + filename
-                            + "\"\r\n");
-                    strBuf.append("Content-Type: " + contentType + "\r\n\r\n");
-
-                    out.write(strBuf.toString().getBytes());
-
-                    DataInputStream in = new DataInputStream(new FileInputStream(file));
-                    int bytes = 0;
-                    byte[] bufferOut = new byte[1024];
-                    while ((bytes = in.read(bufferOut)) != -1) {
-                        out.write(bufferOut, 0, bytes);
-                    }
-                    in.close();
-                }
-                StringBuffer strBuf = new StringBuffer();
-                out.write(strBuf.toString().getBytes());
-            }
-
-            byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
-            out.write(endData);
-            out.flush();
-            out.close();
-
-            // 读取返回数据
-            StringBuffer strBuf = new StringBuffer();
-            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
-            String line = null;
-            while ((line = reader.readLine()) != null) {
-                strBuf.append(line).append("\n");
-            }
-            res = strBuf.toString();
-            reader.close();
-            reader = null;
-        } finally {
-            if (conn != null) {
-                conn.disconnect();
-                conn = null;
-            }
-        }
-        return res;
-    }*/
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN) {
-        try (InputStream in = new FileInputStream(file);) {
-            return saveFile(siteId, env, in, md5, refreshCDN);
-        } catch (Exception e) {
-            throw new StatusException("5001", "上传出错", e);
-        }
-    }
-
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN) {
-        try (ByteArrayInputStream in = new ByteArrayInputStream(bytes);) {
-            return saveFile(siteId, env, in, null, refreshCDN);
-        } catch (Exception e) {
-            throw new StatusException("5002", "上传出错", e);
-        }
-    }
-
-    @Override
-    public YunHttpRequest getSignature(String siteId, FileStoragePathEnvInfo env, String md5) {
-        AliyunSite site = AliyunSiteManager.getAliyunSite(siteId);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(site.getAliyunId());
-        String ossEndpoint = ac.getOssEndpoint();
-        String bucket = ac.getBucket();
-        String accessKeyId = ac.getAccessKeyId();
-        String accessKeySecret = ac.getAccessKeySecret();
-        String urlStr = null; // 提交表单的URL为bucket域名
-        if (ossEndpoint.startsWith("https://")) {
-            urlStr = ossEndpoint.replace("https://", "https://" + bucket + ".");
-        } else if (ossEndpoint.startsWith("http://")) {
-            urlStr = ossEndpoint.replace("http://", "http://" + bucket + ".");
-        }
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-
-        String path = FreeMarkerUtil.process(site.getPath(), env);
-        if (path.startsWith("/")) {
-            path = path.substring(1);
-        }
-
-        String accessUrl = FileStorageHelper.getUrl(ac.getDomain(), path);
-
-        Map<String, String> params = Maps.newHashMap();
-        // key
-        params.put("key", path);
-        // OSSAccessKeyId
-        params.put("OSSAccessKeyId", accessKeyId);
-        // policy
-        Date expiration = DateUtils.addSeconds(new Date(), 600);
-        String expirationStr = DateUtil.format(expiration, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
-        String policy = "{\"expiration\": \"" + expirationStr + "\",\"conditions\": [[\"content-length-range\", 0, "
-                + maxFileSize + "]]}";
-        String encodePolicy = java.util.Base64.getEncoder().encodeToString(policy.getBytes());
-        params.put("policy", encodePolicy);
-        // Signature
-        String signaturecom = com.aliyun.oss.common.auth.ServiceSignature.create().computeSignature(accessKeySecret,
-                encodePolicy);
-        params.put("Signature", signaturecom);
-
-        YunHttpRequest request = new YunHttpRequest();
-        request.setAccessUrl(accessUrl);
-        request.setFormParams(params);
-        request.setFormUrl(urlStr);
-        return request;
-    }
-
-    /*@SuppressWarnings("unused")
-    private String postObjectByInputStream(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5) throws IOException {
-        AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
-        String ossEndpoint = ac.getOssEndpoint();
-        String bucket = ac.getBucket();
-        String accessKeyId = ac.getAccessKeyId();
-        String accessKeySecret = ac.getAccessKeySecret();
-        // 阿里云文件路径
-        String path = FreeMarkerUtil.process(as.getPath(), env);
-        if (path.startsWith("/")) {
-            path = path.substring(1);
-        }
-
-        String filename = path.substring(path.lastIndexOf("/") + 1);
-        String urlStr = null; // 提交表单的URL为bucket域名
-        if (ossEndpoint.startsWith("https://")) {
-            urlStr = ossEndpoint.replace("https://", "https://" + bucket + ".");
-        } else if (ossEndpoint.startsWith("http://")) {
-            urlStr = ossEndpoint.replace("http://", "http://" + bucket + ".");
-        }
-
-        LinkedHashMap<String, String> textMap = new LinkedHashMap<String, String>();
-        // key
-        textMap.put("key", path);
-        // Content-Disposition
-        textMap.put("Content-Disposition", "attachment;filename=" + filename);
-        // OSSAccessKeyId
-        textMap.put("OSSAccessKeyId", accessKeyId);
-        // policy
-        String policy = "{\"expiration\": \"2120-01-01T12:00:00.000Z\",\"conditions\": [[\"content-length-range\", 0, "
-                + maxFileSize + "]]}";
-        String encodePolicy = java.util.Base64.getEncoder().encodeToString(policy.getBytes());
-        textMap.put("policy", encodePolicy);
-        // Signature
-        String signaturecom = com.aliyun.oss.common.auth.ServiceSignature.create().computeSignature(accessKeySecret,
-                encodePolicy);
-        textMap.put("Signature", signaturecom);
-
-
-        String ret = formUploadByInputStream(urlStr, textMap, in, filename);
-        log.info("oss上传:" + ret);
-        return path;
-    }*/
-
-    /*@SuppressWarnings("rawtypes")
-    private static String formUploadByInputStream(String urlStr, Map<String, String> textMap, InputStream filein, String fileName)
-            throws IOException {
-        String res = "";
-        HttpURLConnection conn = null;
-        String BOUNDARY = "9431149156168";
-        try {
-            URL url = new URL(urlStr);
-            conn = (HttpURLConnection) url.openConnection();
-            conn.setConnectTimeout(5000);
-            conn.setReadTimeout(30000);
-            conn.setDoOutput(true);
-            conn.setDoInput(true);
-            conn.setRequestMethod("POST");
-            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
-            conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
-
-            OutputStream out = new DataOutputStream(conn.getOutputStream());
-            // text
-            if (textMap != null) {
-                StringBuffer strBuf = new StringBuffer();
-                Iterator iter = textMap.entrySet().iterator();
-                int i = 0;
-                while (iter.hasNext()) {
-                    Map.Entry entry = (Map.Entry) iter.next();
-                    String inputName = (String) entry.getKey();
-                    String inputValue = (String) entry.getValue();
-                    if (inputValue == null) {
-                        continue;
-                    }
-                    if (i == 0) {
-                        strBuf.append("--").append(BOUNDARY).append("\r\n");
-                        strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
-                        strBuf.append(inputValue);
-                    } else {
-                        strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
-                        strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
-
-                        strBuf.append(inputValue);
-                    }
-
-                    i++;
-                }
-                out.write(strBuf.toString().getBytes());
-            }
-
-            // file
-
-            StringBuffer strBufFile = new StringBuffer();
-            strBufFile.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
-            strBufFile.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName
-                    + "\"\r\n");
-            strBufFile.append("Content-Type: application/octet-stream\r\n\r\n");
-
-            out.write(strBufFile.toString().getBytes());
-
-            DataInputStream in = new DataInputStream(filein);
-            int bytes = 0;
-            byte[] bufferOut = new byte[1024];
-            while ((bytes = in.read(bufferOut)) != -1) {
-                out.write(bufferOut, 0, bytes);
-            }
-            in.close();
-            StringBuffer strBufTag = new StringBuffer();
-            out.write(strBufTag.toString().getBytes());
-
-            byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
-            out.write(endData);
-            out.flush();
-            out.close();
-
-            // 读取返回数据
-            StringBuffer strBuf = new StringBuffer();
-            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
-            String line = null;
-            while ((line = reader.readLine()) != null) {
-                strBuf.append(line).append("\n");
-            }
-            res = strBuf.toString();
-            reader.close();
-            reader = null;
-        } finally {
-            if (conn != null) {
-                conn.disconnect();
-                conn = null;
-            }
-        }
-        return res;
-    }*/
-
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN) {
-        try {
-            String relativePath = uploadObject(siteId, env, in, md5);
-            AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
-            AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
-            String url = FileStorageHelper.getUrl(ac.getDomain(), relativePath);
-            YunPathInfo result = new YunPathInfo(url, getTreatyPath(as.getAliyunId(), relativePath));
-
-            if (refreshCDN) {
-                AliyunRefreshCdn.refreshCDN(ac.getAccessKeyId(), ac.getAccessKeySecret(), result.getUrl());
-            }
-
-            return result;
-        } catch (Exception e) {
-            throw new StatusException("6001", "上传出错", e);
-        }
-    }
-
-    @Override
-    public String realPathBackup(String path) {
-        String yunId = FileStorageHelper.getYunId(path);
-        String urlpath = FileStorageHelper.getPath(path);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(yunId);
-        String bk = ac.getDomainBackup();
-        if (StringUtils.isNotBlank(bk)) {
-            return FileStorageHelper.getUrl(bk, urlpath);
-        }
-        return FileStorageHelper.getUrl(ac.getDomain(), urlpath);
-    }
-
-    @Override
-    public void deleteFile(String path) {
-        // 无删除权限
-        /*String yunId = FileStorageHelper.getYunId(path);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(yunId);
-        String bucket = ac.getBucket();
-        OSS oss = AliyunSiteManager.getAliYunClientByAliyunId(yunId);
-        // 阿里云文件路径
-        String urlpath = FileStorageHelper.getPath(path);
-        if (urlpath.startsWith("/")) {
-            urlpath = urlpath.substring(1);
-        }
-        oss.deleteObject(bucket, urlpath);*/
-    }
-
-    private String uploadObject(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5) throws IOException, DecoderException {
-        AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
-        String bucket = ac.getBucket();
-        OSS oss = AliyunSiteManager.getAliYunClientBySiteId(siteId);
-        // 阿里云文件路径
-        String path = FreeMarkerUtil.process(as.getPath(), env);
-        path = disposePath(path);
-        if (StringUtils.isNotBlank(md5)) {
-            md5 = Base64.getEncoder().encodeToString(Hex.decodeHex(md5));
-            ObjectMetadata meta = new ObjectMetadata();
-            meta.setContentMD5(md5);
-            oss.putObject(bucket, path, in, meta);
-        } else {
-            oss.putObject(bucket, path, in);
-        }
-
-        return path;
-    }
-
-    private String getTreatyPath(String yunId, String relativePath) {
-        if (relativePath.startsWith("/")) {
-            relativePath = relativePath.substring(1);
-        }
-        String path = FileStorageType.ALIYUN.name().toLowerCase() + "-" + yunId + "://" + relativePath;
-        return path;
-    }
-
-    private String disposePath(String path) {
-        for (; ; ) {
-            if (path.startsWith("/")) {
-                path = path.substring(1);
-            } else {
-                return path;
-            }
-        }
-    }
-
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN,
-                                Long cacheAge) {
-        try (InputStream in = new FileInputStream(file);) {
-            return saveFile(siteId, env, in, md5, refreshCDN, cacheAge);
-        } catch (Exception e) {
-            throw new StatusException("5001", "上传出错", e);
-        }
-    }
-
-    private YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN, Long cacheAge) {
-        try {
-            String relativePath = uploadObject(siteId, env, in, md5, cacheAge);
-            AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
-            AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
-            String url = FileStorageHelper.getUrl(ac.getDomain(), relativePath);
-            YunPathInfo result = new YunPathInfo(url, getTreatyPath(as.getAliyunId(), relativePath));
-
-            if (refreshCDN) {
-                AliyunRefreshCdn.refreshCDN(ac.getAccessKeyId(), ac.getAccessKeySecret(), result.getUrl());
-            }
-
-            return result;
-        } catch (Exception e) {
-            throw new StatusException("6001", "上传出错", e);
-        }
-    }
-
-    private String uploadObject(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, Long cacheAge) throws IOException, DecoderException {
-        AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
-        AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
-        String bucket = ac.getBucket();
-        OSS oss = AliyunSiteManager.getAliYunClientBySiteId(siteId);
-        // 阿里云文件路径
-        String path = FreeMarkerUtil.process(as.getPath(), env);
-        path = disposePath(path);
-        //        if (StringUtils.isNotBlank(md5)) {
-        //            md5 = Base64.getEncoder().encodeToString(Hex.decodeHex(md5));
-        //            ObjectMetadata meta = new ObjectMetadata();
-        //            meta.setContentMD5(md5);
-        //            if(cacheAge!=null) {
-        //            	meta.setCacheControl("max-age="+cacheAge);
-        //            }
-        //            oss.putObject(bucket, path, in, meta);
-        //        } else {
-        //            oss.putObject(bucket, path, in);
-        //        }
-        ObjectMetadata meta = new ObjectMetadata();
-        if (StringUtils.isNotBlank(md5)) {
-            md5 = Base64.getEncoder().encodeToString(Hex.decodeHex(md5));
-            meta.setContentMD5(md5);
-        }
-        if (cacheAge != null) {
-            meta.setCacheControl("max-age=" + cacheAge);
-        }
-        oss.putObject(bucket, path, in, meta);
-
-        return path;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.filestorage.impl;
+//
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.commons.util.DateUtil;
+// import cn.com.qmth.examcloud.commons.util.FreeMarkerUtil;
+// import cn.com.qmth.examcloud.web.aliyun.AliYunAccount;
+// import cn.com.qmth.examcloud.web.aliyun.AliyunSite;
+// import cn.com.qmth.examcloud.web.aliyun.AliyunSiteManager;
+// import cn.com.qmth.examcloud.web.filestorage.*;
+// import com.aliyun.oss.OSS;
+// import com.aliyun.oss.model.ObjectMetadata;
+// import com.google.common.collect.Maps;
+// import org.apache.commons.codec.DecoderException;
+// import org.apache.commons.codec.binary.Hex;
+// import org.apache.commons.lang3.StringUtils;
+// import org.apache.commons.lang3.time.DateUtils;
+// import org.springframework.stereotype.Service;
+//
+// import java.io.*;
+// import java.util.Base64;
+// import java.util.Date;
+// import java.util.Map;
+//
+// @Service(value = "aliyunFileStorage")
+// public class AliyunFileStorageImpl implements FileStorage {
+//
+//     // 文件最大大小(byte)
+//     private static int maxFileSize = 100 * 1024 * 1024;
+//
+//     @Override
+//     public YunPathInfo saveFile(File file, String path) {
+//         String siteId = "transPath";
+//         FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
+//         env.setRelativePath(path);
+//         return saveFile(siteId, env, file, null, false);
+//     }
+//
+//     @Override
+//     public String realPath(String path) {
+//         String yunId = FileStorageHelper.getYunId(path);
+//         String urlpath = FileStorageHelper.getPath(path);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(yunId);
+//         return FileStorageHelper.getUrl(ac.getDomain(), urlpath);
+//     }
+//
+//     /**
+//      * 表单上传
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param file
+//      * @param md5
+//      * @return 不带域名的完整路径
+//      * @throws IOException
+//      */
+//     /*private String postObject(String siteId, FileStoragePathEnvInfo env, File file, String md5) throws IOException {
+//         AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
+//         String ossEndpoint = ac.getOssEndpoint();
+//         String bucket = ac.getBucket();
+//         String accessKeyId = ac.getAccessKeyId();
+//         String accessKeySecret = ac.getAccessKeySecret();
+//         // 阿里云文件路径
+//         String path = FreeMarkerUtil.process(as.getPath(), env);
+//         if (path.startsWith("/")) {
+//             path = path.substring(1);
+//         }
+//
+//         String filepath = file.getAbsolutePath();
+//         String filename = path.substring(path.lastIndexOf("/") + 1);
+//         String urlStr = null; // 提交表单的URL为bucket域名
+//         if (ossEndpoint.startsWith("https://")) {
+//             urlStr = ossEndpoint.replace("https://", "https://" + bucket + ".");
+//         } else if (ossEndpoint.startsWith("http://")) {
+//             urlStr = ossEndpoint.replace("http://", "http://" + bucket + ".");
+//         }
+//
+//         LinkedHashMap<String, String> textMap = new LinkedHashMap<String, String>();
+//         // key
+//         textMap.put("key", path);
+//         // Content-Disposition
+//         textMap.put("Content-Disposition", "attachment;filename=" + filename);
+//         // OSSAccessKeyId
+//         textMap.put("OSSAccessKeyId", accessKeyId);
+//         // policy
+//         String policy = "{\"expiration\": \"2120-01-01T12:00:00.000Z\",\"conditions\": [[\"content-length-range\", 0, "
+//                 + maxFileSize + "]]}";
+//         String encodePolicy = java.util.Base64.getEncoder().encodeToString(policy.getBytes());
+//         textMap.put("policy", encodePolicy);
+//         // Signature
+//         String signaturecom = com.aliyun.oss.common.auth.ServiceSignature.create().computeSignature(accessKeySecret,
+//                 encodePolicy);
+//         textMap.put("Signature", signaturecom);
+//
+//         Map<String, String> fileMap = new HashMap<String, String>();
+//         fileMap.put("file", filepath);
+//
+//         String ret = formUpload(urlStr, textMap, fileMap);
+//         log.info("oss上传:" + ret);
+//         return path;
+//     }*/
+//
+//     /*@SuppressWarnings("rawtypes")
+//     private static String formUpload(String urlStr, Map<String, String> textMap, Map<String, String> fileMap)
+//             throws IOException {
+//         String res = "";
+//         HttpURLConnection conn = null;
+//         String BOUNDARY = "9431149156168";
+//         try {
+//             URL url = new URL(urlStr);
+//             conn = (HttpURLConnection) url.openConnection();
+//             conn.setConnectTimeout(5000);
+//             conn.setReadTimeout(30000);
+//             conn.setDoOutput(true);
+//             conn.setDoInput(true);
+//             conn.setRequestMethod("POST");
+//             conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
+//             conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
+//
+//             OutputStream out = new DataOutputStream(conn.getOutputStream());
+//             // text
+//             if (textMap != null) {
+//                 StringBuffer strBuf = new StringBuffer();
+//                 Iterator iter = textMap.entrySet().iterator();
+//                 int i = 0;
+//                 while (iter.hasNext()) {
+//                     Map.Entry entry = (Map.Entry) iter.next();
+//                     String inputName = (String) entry.getKey();
+//                     String inputValue = (String) entry.getValue();
+//                     if (inputValue == null) {
+//                         continue;
+//                     }
+//                     if (i == 0) {
+//                         strBuf.append("--").append(BOUNDARY).append("\r\n");
+//                         strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
+//                         strBuf.append(inputValue);
+//                     } else {
+//                         strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
+//                         strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
+//
+//                         strBuf.append(inputValue);
+//                     }
+//
+//                     i++;
+//                 }
+//                 out.write(strBuf.toString().getBytes());
+//             }
+//
+//             // file
+//             if (fileMap != null) {
+//                 Iterator iter = fileMap.entrySet().iterator();
+//                 while (iter.hasNext()) {
+//                     Map.Entry entry = (Map.Entry) iter.next();
+//                     String inputName = (String) entry.getKey();
+//                     String inputValue = (String) entry.getValue();
+//                     if (inputValue == null) {
+//                         continue;
+//                     }
+//                     File file = new File(inputValue);
+//                     String filename = file.getName();
+//                     String contentType = new MimetypesFileTypeMap().getContentType(file);
+//                     if (contentType == null || contentType.equals("")) {
+//                         contentType = "application/octet-stream";
+//                     }
+//
+//                     StringBuffer strBuf = new StringBuffer();
+//                     strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
+//                     strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"; filename=\"" + filename
+//                             + "\"\r\n");
+//                     strBuf.append("Content-Type: " + contentType + "\r\n\r\n");
+//
+//                     out.write(strBuf.toString().getBytes());
+//
+//                     DataInputStream in = new DataInputStream(new FileInputStream(file));
+//                     int bytes = 0;
+//                     byte[] bufferOut = new byte[1024];
+//                     while ((bytes = in.read(bufferOut)) != -1) {
+//                         out.write(bufferOut, 0, bytes);
+//                     }
+//                     in.close();
+//                 }
+//                 StringBuffer strBuf = new StringBuffer();
+//                 out.write(strBuf.toString().getBytes());
+//             }
+//
+//             byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
+//             out.write(endData);
+//             out.flush();
+//             out.close();
+//
+//             // 读取返回数据
+//             StringBuffer strBuf = new StringBuffer();
+//             BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+//             String line = null;
+//             while ((line = reader.readLine()) != null) {
+//                 strBuf.append(line).append("\n");
+//             }
+//             res = strBuf.toString();
+//             reader.close();
+//             reader = null;
+//         } finally {
+//             if (conn != null) {
+//                 conn.disconnect();
+//                 conn = null;
+//             }
+//         }
+//         return res;
+//     }*/
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN) {
+//         try (InputStream in = new FileInputStream(file);) {
+//             return saveFile(siteId, env, in, md5, refreshCDN);
+//         } catch (Exception e) {
+//             throw new StatusException("5001", "上传出错", e);
+//         }
+//     }
+//
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN) {
+//         try (ByteArrayInputStream in = new ByteArrayInputStream(bytes);) {
+//             return saveFile(siteId, env, in, null, refreshCDN);
+//         } catch (Exception e) {
+//             throw new StatusException("5002", "上传出错", e);
+//         }
+//     }
+//
+//     @Override
+//     public YunHttpRequest getSignature(String siteId, FileStoragePathEnvInfo env, String md5) {
+//         AliyunSite site = AliyunSiteManager.getAliyunSite(siteId);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(site.getAliyunId());
+//         String ossEndpoint = ac.getOssEndpoint();
+//         String bucket = ac.getBucket();
+//         String accessKeyId = ac.getAccessKeyId();
+//         String accessKeySecret = ac.getAccessKeySecret();
+//         String urlStr = null; // 提交表单的URL为bucket域名
+//         if (ossEndpoint.startsWith("https://")) {
+//             urlStr = ossEndpoint.replace("https://", "https://" + bucket + ".");
+//         } else if (ossEndpoint.startsWith("http://")) {
+//             urlStr = ossEndpoint.replace("http://", "http://" + bucket + ".");
+//         }
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//
+//         String path = FreeMarkerUtil.process(site.getPath(), env);
+//         if (path.startsWith("/")) {
+//             path = path.substring(1);
+//         }
+//
+//         String accessUrl = FileStorageHelper.getUrl(ac.getDomain(), path);
+//
+//         Map<String, String> params = Maps.newHashMap();
+//         // key
+//         params.put("key", path);
+//         // OSSAccessKeyId
+//         params.put("OSSAccessKeyId", accessKeyId);
+//         // policy
+//         Date expiration = DateUtils.addSeconds(new Date(), 600);
+//         String expirationStr = DateUtil.format(expiration, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+//         String policy = "{\"expiration\": \"" + expirationStr + "\",\"conditions\": [[\"content-length-range\", 0, "
+//                 + maxFileSize + "]]}";
+//         String encodePolicy = java.util.Base64.getEncoder().encodeToString(policy.getBytes());
+//         params.put("policy", encodePolicy);
+//         // Signature
+//         String signaturecom = com.aliyun.oss.common.auth.ServiceSignature.create().computeSignature(accessKeySecret,
+//                 encodePolicy);
+//         params.put("Signature", signaturecom);
+//
+//         YunHttpRequest request = new YunHttpRequest();
+//         request.setAccessUrl(accessUrl);
+//         request.setFormParams(params);
+//         request.setFormUrl(urlStr);
+//         return request;
+//     }
+//
+//     /*@SuppressWarnings("unused")
+//     private String postObjectByInputStream(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5) throws IOException {
+//         AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
+//         String ossEndpoint = ac.getOssEndpoint();
+//         String bucket = ac.getBucket();
+//         String accessKeyId = ac.getAccessKeyId();
+//         String accessKeySecret = ac.getAccessKeySecret();
+//         // 阿里云文件路径
+//         String path = FreeMarkerUtil.process(as.getPath(), env);
+//         if (path.startsWith("/")) {
+//             path = path.substring(1);
+//         }
+//
+//         String filename = path.substring(path.lastIndexOf("/") + 1);
+//         String urlStr = null; // 提交表单的URL为bucket域名
+//         if (ossEndpoint.startsWith("https://")) {
+//             urlStr = ossEndpoint.replace("https://", "https://" + bucket + ".");
+//         } else if (ossEndpoint.startsWith("http://")) {
+//             urlStr = ossEndpoint.replace("http://", "http://" + bucket + ".");
+//         }
+//
+//         LinkedHashMap<String, String> textMap = new LinkedHashMap<String, String>();
+//         // key
+//         textMap.put("key", path);
+//         // Content-Disposition
+//         textMap.put("Content-Disposition", "attachment;filename=" + filename);
+//         // OSSAccessKeyId
+//         textMap.put("OSSAccessKeyId", accessKeyId);
+//         // policy
+//         String policy = "{\"expiration\": \"2120-01-01T12:00:00.000Z\",\"conditions\": [[\"content-length-range\", 0, "
+//                 + maxFileSize + "]]}";
+//         String encodePolicy = java.util.Base64.getEncoder().encodeToString(policy.getBytes());
+//         textMap.put("policy", encodePolicy);
+//         // Signature
+//         String signaturecom = com.aliyun.oss.common.auth.ServiceSignature.create().computeSignature(accessKeySecret,
+//                 encodePolicy);
+//         textMap.put("Signature", signaturecom);
+//
+//
+//         String ret = formUploadByInputStream(urlStr, textMap, in, filename);
+//         log.info("oss上传:" + ret);
+//         return path;
+//     }*/
+//
+//     /*@SuppressWarnings("rawtypes")
+//     private static String formUploadByInputStream(String urlStr, Map<String, String> textMap, InputStream filein, String fileName)
+//             throws IOException {
+//         String res = "";
+//         HttpURLConnection conn = null;
+//         String BOUNDARY = "9431149156168";
+//         try {
+//             URL url = new URL(urlStr);
+//             conn = (HttpURLConnection) url.openConnection();
+//             conn.setConnectTimeout(5000);
+//             conn.setReadTimeout(30000);
+//             conn.setDoOutput(true);
+//             conn.setDoInput(true);
+//             conn.setRequestMethod("POST");
+//             conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
+//             conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
+//
+//             OutputStream out = new DataOutputStream(conn.getOutputStream());
+//             // text
+//             if (textMap != null) {
+//                 StringBuffer strBuf = new StringBuffer();
+//                 Iterator iter = textMap.entrySet().iterator();
+//                 int i = 0;
+//                 while (iter.hasNext()) {
+//                     Map.Entry entry = (Map.Entry) iter.next();
+//                     String inputName = (String) entry.getKey();
+//                     String inputValue = (String) entry.getValue();
+//                     if (inputValue == null) {
+//                         continue;
+//                     }
+//                     if (i == 0) {
+//                         strBuf.append("--").append(BOUNDARY).append("\r\n");
+//                         strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
+//                         strBuf.append(inputValue);
+//                     } else {
+//                         strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
+//                         strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
+//
+//                         strBuf.append(inputValue);
+//                     }
+//
+//                     i++;
+//                 }
+//                 out.write(strBuf.toString().getBytes());
+//             }
+//
+//             // file
+//
+//             StringBuffer strBufFile = new StringBuffer();
+//             strBufFile.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
+//             strBufFile.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName
+//                     + "\"\r\n");
+//             strBufFile.append("Content-Type: application/octet-stream\r\n\r\n");
+//
+//             out.write(strBufFile.toString().getBytes());
+//
+//             DataInputStream in = new DataInputStream(filein);
+//             int bytes = 0;
+//             byte[] bufferOut = new byte[1024];
+//             while ((bytes = in.read(bufferOut)) != -1) {
+//                 out.write(bufferOut, 0, bytes);
+//             }
+//             in.close();
+//             StringBuffer strBufTag = new StringBuffer();
+//             out.write(strBufTag.toString().getBytes());
+//
+//             byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
+//             out.write(endData);
+//             out.flush();
+//             out.close();
+//
+//             // 读取返回数据
+//             StringBuffer strBuf = new StringBuffer();
+//             BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+//             String line = null;
+//             while ((line = reader.readLine()) != null) {
+//                 strBuf.append(line).append("\n");
+//             }
+//             res = strBuf.toString();
+//             reader.close();
+//             reader = null;
+//         } finally {
+//             if (conn != null) {
+//                 conn.disconnect();
+//                 conn = null;
+//             }
+//         }
+//         return res;
+//     }*/
+//
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN) {
+//         try {
+//             String relativePath = uploadObject(siteId, env, in, md5);
+//             AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
+//             AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
+//             String url = FileStorageHelper.getUrl(ac.getDomain(), relativePath);
+//             YunPathInfo result = new YunPathInfo(url, getTreatyPath(as.getAliyunId(), relativePath));
+//
+//             if (refreshCDN) {
+//                 AliyunRefreshCdn.refreshCDN(ac.getAccessKeyId(), ac.getAccessKeySecret(), result.getUrl());
+//             }
+//
+//             return result;
+//         } catch (Exception e) {
+//             throw new StatusException("6001", "上传出错", e);
+//         }
+//     }
+//
+//     @Override
+//     public String realPathBackup(String path) {
+//         String yunId = FileStorageHelper.getYunId(path);
+//         String urlpath = FileStorageHelper.getPath(path);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(yunId);
+//         String bk = ac.getDomainBackup();
+//         if (StringUtils.isNotBlank(bk)) {
+//             return FileStorageHelper.getUrl(bk, urlpath);
+//         }
+//         return FileStorageHelper.getUrl(ac.getDomain(), urlpath);
+//     }
+//
+//     @Override
+//     public void deleteFile(String path) {
+//         // 无删除权限
+//         /*String yunId = FileStorageHelper.getYunId(path);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(yunId);
+//         String bucket = ac.getBucket();
+//         OSS oss = AliyunSiteManager.getAliYunClientByAliyunId(yunId);
+//         // 阿里云文件路径
+//         String urlpath = FileStorageHelper.getPath(path);
+//         if (urlpath.startsWith("/")) {
+//             urlpath = urlpath.substring(1);
+//         }
+//         oss.deleteObject(bucket, urlpath);*/
+//     }
+//
+//     private String uploadObject(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5) throws IOException, DecoderException {
+//         AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
+//         String bucket = ac.getBucket();
+//         OSS oss = AliyunSiteManager.getAliYunClientBySiteId(siteId);
+//         // 阿里云文件路径
+//         String path = FreeMarkerUtil.process(as.getPath(), env);
+//         path = disposePath(path);
+//         if (StringUtils.isNotBlank(md5)) {
+//             md5 = Base64.getEncoder().encodeToString(Hex.decodeHex(md5));
+//             ObjectMetadata meta = new ObjectMetadata();
+//             meta.setContentMD5(md5);
+//             oss.putObject(bucket, path, in, meta);
+//         } else {
+//             oss.putObject(bucket, path, in);
+//         }
+//
+//         return path;
+//     }
+//
+//     private String getTreatyPath(String yunId, String relativePath) {
+//         if (relativePath.startsWith("/")) {
+//             relativePath = relativePath.substring(1);
+//         }
+//         String path = FileStorageType.ALIYUN.name().toLowerCase() + "-" + yunId + "://" + relativePath;
+//         return path;
+//     }
+//
+//     private String disposePath(String path) {
+//         for (; ; ) {
+//             if (path.startsWith("/")) {
+//                 path = path.substring(1);
+//             } else {
+//                 return path;
+//             }
+//         }
+//     }
+//
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN,
+//                                 Long cacheAge) {
+//         try (InputStream in = new FileInputStream(file);) {
+//             return saveFile(siteId, env, in, md5, refreshCDN, cacheAge);
+//         } catch (Exception e) {
+//             throw new StatusException("5001", "上传出错", e);
+//         }
+//     }
+//
+//     private YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN, Long cacheAge) {
+//         try {
+//             String relativePath = uploadObject(siteId, env, in, md5, cacheAge);
+//             AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
+//             AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
+//             String url = FileStorageHelper.getUrl(ac.getDomain(), relativePath);
+//             YunPathInfo result = new YunPathInfo(url, getTreatyPath(as.getAliyunId(), relativePath));
+//
+//             if (refreshCDN) {
+//                 AliyunRefreshCdn.refreshCDN(ac.getAccessKeyId(), ac.getAccessKeySecret(), result.getUrl());
+//             }
+//
+//             return result;
+//         } catch (Exception e) {
+//             throw new StatusException("6001", "上传出错", e);
+//         }
+//     }
+//
+//     private String uploadObject(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, Long cacheAge) throws IOException, DecoderException {
+//         AliyunSite as = AliyunSiteManager.getAliyunSite(siteId);
+//         AliYunAccount ac = AliyunSiteManager.getAliYunAccountByAliyunId(as.getAliyunId());
+//         String bucket = ac.getBucket();
+//         OSS oss = AliyunSiteManager.getAliYunClientBySiteId(siteId);
+//         // 阿里云文件路径
+//         String path = FreeMarkerUtil.process(as.getPath(), env);
+//         path = disposePath(path);
+//         //        if (StringUtils.isNotBlank(md5)) {
+//         //            md5 = Base64.getEncoder().encodeToString(Hex.decodeHex(md5));
+//         //            ObjectMetadata meta = new ObjectMetadata();
+//         //            meta.setContentMD5(md5);
+//         //            if(cacheAge!=null) {
+//         //            	meta.setCacheControl("max-age="+cacheAge);
+//         //            }
+//         //            oss.putObject(bucket, path, in, meta);
+//         //        } else {
+//         //            oss.putObject(bucket, path, in);
+//         //        }
+//         ObjectMetadata meta = new ObjectMetadata();
+//         if (StringUtils.isNotBlank(md5)) {
+//             md5 = Base64.getEncoder().encodeToString(Hex.decodeHex(md5));
+//             meta.setContentMD5(md5);
+//         }
+//         if (cacheAge != null) {
+//             meta.setCacheControl("max-age=" + cacheAge);
+//         }
+//         oss.putObject(bucket, path, in, meta);
+//
+//         return path;
+//     }
+//
+// }

+ 55 - 55
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/AliyunRefreshCdn.java

@@ -1,55 +1,55 @@
-/*
- * Copyright (c) 2020 QMTH All Rights Reserved.
- * Created by Deason on 2020-08-31 10:24:15
- */
-
-package cn.com.qmth.examcloud.web.filestorage.impl;
-
-import cn.com.qmth.examcloud.commons.util.JsonUtil;
-import com.aliyuncs.DefaultAcsClient;
-import com.aliyuncs.IAcsClient;
-import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesRequest;
-import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesResponse;
-import com.aliyuncs.profile.DefaultProfile;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * 阿里云 - 刷新文件的CDN缓存
- */
-public class AliyunRefreshCdn {
-
-    private static final Logger LOG = LoggerFactory.getLogger(AliyunRefreshCdn.class);
-
-    /**
-     * 刷新文件的CDN缓存:
-     * 1、同一个账号 每天最多可提交2000条URL刷新和100个目录刷新
-     * 2、每次请求最多只能提交1000条URL刷新,多个URL之间需要用换行符 \n 分割
-     * 3、每秒最多50次请求
-     */
-    public static void refreshCDN(String accessKeyId, String accessKeySecret, String fileUrls) {
-        DefaultProfile profile = DefaultProfile.getProfile("oss-cn-shenzhen", accessKeyId, accessKeySecret);
-        IAcsClient client = new DefaultAcsClient(profile);
-
-        RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
-        request.setObjectPath(fileUrls);
-        request.setObjectType("file");
-
-        try {
-            RefreshObjectCachesResponse response = client.getAcsResponse(request);
-
-            LOG.info("refreshCDN fileUrl = " + fileUrls);
-            if (LOG.isDebugEnabled()) {
-                LOG.debug(JsonUtil.toJson(response));
-            }
-        } catch (Exception e) {
-            LOG.error(e.getMessage(), e);
-        }
-    }
-
-    /*public static void main(String[] args) {
-        String fileUrl = "http://xxx.com/xxx/xxx.xxx";
-        refreshCDN("xxx", "xxx", fileUrl);
-    }*/
-
-}
+// /*
+//  * Copyright (c) 2020 QMTH All Rights Reserved.
+//  * Created by Deason on 2020-08-31 10:24:15
+//  */
+//
+// package cn.com.qmth.examcloud.web.filestorage.impl;
+//
+// import cn.com.qmth.examcloud.commons.util.JsonUtil;
+// import com.aliyuncs.DefaultAcsClient;
+// import com.aliyuncs.IAcsClient;
+// import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesRequest;
+// import com.aliyuncs.cdn.model.v20180510.RefreshObjectCachesResponse;
+// import com.aliyuncs.profile.DefaultProfile;
+// import org.slf4j.Logger;
+// import org.slf4j.LoggerFactory;
+//
+// /**
+//  * 阿里云 - 刷新文件的CDN缓存
+//  */
+// public class AliyunRefreshCdn {
+//
+//     private static final Logger LOG = LoggerFactory.getLogger(AliyunRefreshCdn.class);
+//
+//     /**
+//      * 刷新文件的CDN缓存:
+//      * 1、同一个账号 每天最多可提交2000条URL刷新和100个目录刷新
+//      * 2、每次请求最多只能提交1000条URL刷新,多个URL之间需要用换行符 \n 分割
+//      * 3、每秒最多50次请求
+//      */
+//     public static void refreshCDN(String accessKeyId, String accessKeySecret, String fileUrls) {
+//         DefaultProfile profile = DefaultProfile.getProfile("oss-cn-shenzhen", accessKeyId, accessKeySecret);
+//         IAcsClient client = new DefaultAcsClient(profile);
+//
+//         RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
+//         request.setObjectPath(fileUrls);
+//         request.setObjectType("file");
+//
+//         try {
+//             RefreshObjectCachesResponse response = client.getAcsResponse(request);
+//
+//             LOG.info("refreshCDN fileUrl = " + fileUrls);
+//             if (LOG.isDebugEnabled()) {
+//                 LOG.debug(JsonUtil.toJson(response));
+//             }
+//         } catch (Exception e) {
+//             LOG.error(e.getMessage(), e);
+//         }
+//     }
+//
+//     /*public static void main(String[] args) {
+//         String fileUrl = "http://xxx.com/xxx/xxx.xxx";
+//         refreshCDN("xxx", "xxx", fileUrl);
+//     }*/
+//
+// }

+ 126 - 126
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/filestorage/impl/UpyunFileStorageImpl.java

@@ -1,126 +1,126 @@
-package cn.com.qmth.examcloud.web.filestorage.impl;
-
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.web.filestorage.*;
-import cn.com.qmth.examcloud.web.upyun.*;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
-@Service(value = "upyunFileStorage")
-public class UpyunFileStorageImpl implements FileStorage {
-
-    @Autowired
-    private UpyunService upyunService;
-
-    @Override
-    public YunPathInfo saveFile(File file, String path) {
-        String siteId = "transPath";
-        FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
-        env.setRelativePath(path);
-        return saveFile(siteId, env, file, null, false);
-    }
-
-    @Override
-    public String realPath(String path) {
-        String upyunId = FileStorageHelper.getYunId(path);
-        String urlpath = FileStorageHelper.getPath(path);
-        UpYunClient c = UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
-        return FileStorageHelper.getUrl(c.getDomain(), urlpath);
-    }
-
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN) {
-        try (InputStream in = new FileInputStream(file);) {
-            return saveFile(siteId, env, in, md5, refreshCDN);
-        } catch (Exception e) {
-            throw new StatusException("1001", "上传出错", e);
-        }
-    }
-
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN) {
-        try (ByteArrayInputStream in = new ByteArrayInputStream(bytes);) {
-            return saveFile(siteId, env, in, null, refreshCDN);
-        } catch (Exception e) {
-            throw new StatusException("1001", "上传出错", e);
-        }
-    }
-
-    private UpyunPathEnvironmentInfo of(FileStoragePathEnvInfo env) {
-        UpyunPathEnvironmentInfo ret = new UpyunPathEnvironmentInfo();
-        ret.setExt1(env.getExt1());
-        ret.setExt2(env.getExt2());
-        ret.setExt3(env.getExt3());
-        ret.setExt4(env.getExt4());
-        ret.setExt5(env.getExt5());
-        ret.setFileSuffix(env.getFileSuffix());
-        ret.setRelativePath(env.getRelativePath());
-        ret.setRootOrgDomain(env.getRootOrgDomain());
-        ret.setRootOrgId(env.getRootOrgId());
-        ret.setTimeMillis(env.getTimeMillis());
-        ret.setUserId(env.getUserId());
-        return ret;
-    }
-
-    @Override
-    public YunHttpRequest getSignature(String siteId, FileStoragePathEnvInfo env, String md5) {
-        YunHttpRequest req = upyunService.buildUpYunHttpRequest(siteId, of(env), md5);
-        return req;
-    }
-
-    @Override
-    public void deleteFile(String path) {
-        // 无删除权限
-        // String upyunId = FileStorageHelper.getYunId(path);
-        // String urlpath = FileStorageHelper.getPath(path);
-        // upyunService.deleteByUpyunId(upyunId, urlpath);
-    }
-
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN) {
-        UpYunPathInfo pathInfo = upyunService.writeFile(siteId, of(env), in, md5);
-        UpyunSite site = UpyunSiteManager.getUpyunSite(siteId);
-        String relativePath = getTreatyPath(site.getUpyunId(), pathInfo.getRelativePath());
-        UpYunClient c = UpyunSiteManager.getUpYunClientByUpyunId(site.getUpyunId());
-        String url = FileStorageHelper.getUrl(c.getDomain(), pathInfo.getRelativePath());
-        YunPathInfo pi = new YunPathInfo(url, relativePath);
-        return pi;
-    }
-
-    @Override
-    public String realPathBackup(String path) {
-        String upyunId = FileStorageHelper.getYunId(path);
-        String urlpath = FileStorageHelper.getPath(path);
-        UpYunClient c = UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
-        String bk = c.getDomainBackup();
-        if (StringUtils.isNotBlank(bk)) {
-            return FileStorageHelper.getUrl(bk, urlpath);
-        }
-        return FileStorageHelper.getUrl(c.getDomain(), urlpath);
-    }
-
-    private String getTreatyPath(String yunId, String relativePath) {
-        if (relativePath.startsWith("/")) {
-            relativePath = relativePath.substring(1);
-        }
-        String path = FileStorageType.UPYUN.name().toLowerCase() + "-" + yunId + "://" + relativePath;
-        return path;
-    }
-
-    @Override
-    public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN,
-                                Long cacheAge) {
-        try (InputStream in = new FileInputStream(file);) {
-            return saveFile(siteId, env, in, md5, refreshCDN);
-        } catch (Exception e) {
-            throw new StatusException("1001", "上传出错", e);
-        }
-    }
-
-}
+// package cn.com.qmth.examcloud.web.filestorage.impl;
+//
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.web.filestorage.*;
+// import cn.com.qmth.examcloud.web.upyun.*;
+// import org.apache.commons.lang3.StringUtils;
+// import org.springframework.beans.factory.annotation.Autowired;
+// import org.springframework.stereotype.Service;
+//
+// import java.io.ByteArrayInputStream;
+// import java.io.File;
+// import java.io.FileInputStream;
+// import java.io.InputStream;
+//
+// @Service(value = "upyunFileStorage")
+// public class UpyunFileStorageImpl implements FileStorage {
+//
+//     @Autowired
+//     private UpyunService upyunService;
+//
+//     @Override
+//     public YunPathInfo saveFile(File file, String path) {
+//         String siteId = "transPath";
+//         FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
+//         env.setRelativePath(path);
+//         return saveFile(siteId, env, file, null, false);
+//     }
+//
+//     @Override
+//     public String realPath(String path) {
+//         String upyunId = FileStorageHelper.getYunId(path);
+//         String urlpath = FileStorageHelper.getPath(path);
+//         UpYunClient c = UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
+//         return FileStorageHelper.getUrl(c.getDomain(), urlpath);
+//     }
+//
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN) {
+//         try (InputStream in = new FileInputStream(file);) {
+//             return saveFile(siteId, env, in, md5, refreshCDN);
+//         } catch (Exception e) {
+//             throw new StatusException("1001", "上传出错", e);
+//         }
+//     }
+//
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, byte[] bytes, boolean refreshCDN) {
+//         try (ByteArrayInputStream in = new ByteArrayInputStream(bytes);) {
+//             return saveFile(siteId, env, in, null, refreshCDN);
+//         } catch (Exception e) {
+//             throw new StatusException("1001", "上传出错", e);
+//         }
+//     }
+//
+//     private UpyunPathEnvironmentInfo of(FileStoragePathEnvInfo env) {
+//         UpyunPathEnvironmentInfo ret = new UpyunPathEnvironmentInfo();
+//         ret.setExt1(env.getExt1());
+//         ret.setExt2(env.getExt2());
+//         ret.setExt3(env.getExt3());
+//         ret.setExt4(env.getExt4());
+//         ret.setExt5(env.getExt5());
+//         ret.setFileSuffix(env.getFileSuffix());
+//         ret.setRelativePath(env.getRelativePath());
+//         ret.setRootOrgDomain(env.getRootOrgDomain());
+//         ret.setRootOrgId(env.getRootOrgId());
+//         ret.setTimeMillis(env.getTimeMillis());
+//         ret.setUserId(env.getUserId());
+//         return ret;
+//     }
+//
+//     @Override
+//     public YunHttpRequest getSignature(String siteId, FileStoragePathEnvInfo env, String md5) {
+//         YunHttpRequest req = upyunService.buildUpYunHttpRequest(siteId, of(env), md5);
+//         return req;
+//     }
+//
+//     @Override
+//     public void deleteFile(String path) {
+//         // 无删除权限
+//         // String upyunId = FileStorageHelper.getYunId(path);
+//         // String urlpath = FileStorageHelper.getPath(path);
+//         // upyunService.deleteByUpyunId(upyunId, urlpath);
+//     }
+//
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, InputStream in, String md5, boolean refreshCDN) {
+//         UpYunPathInfo pathInfo = upyunService.writeFile(siteId, of(env), in, md5);
+//         UpyunSite site = UpyunSiteManager.getUpyunSite(siteId);
+//         String relativePath = getTreatyPath(site.getUpyunId(), pathInfo.getRelativePath());
+//         UpYunClient c = UpyunSiteManager.getUpYunClientByUpyunId(site.getUpyunId());
+//         String url = FileStorageHelper.getUrl(c.getDomain(), pathInfo.getRelativePath());
+//         YunPathInfo pi = new YunPathInfo(url, relativePath);
+//         return pi;
+//     }
+//
+//     @Override
+//     public String realPathBackup(String path) {
+//         String upyunId = FileStorageHelper.getYunId(path);
+//         String urlpath = FileStorageHelper.getPath(path);
+//         UpYunClient c = UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
+//         String bk = c.getDomainBackup();
+//         if (StringUtils.isNotBlank(bk)) {
+//             return FileStorageHelper.getUrl(bk, urlpath);
+//         }
+//         return FileStorageHelper.getUrl(c.getDomain(), urlpath);
+//     }
+//
+//     private String getTreatyPath(String yunId, String relativePath) {
+//         if (relativePath.startsWith("/")) {
+//             relativePath = relativePath.substring(1);
+//         }
+//         String path = FileStorageType.UPYUN.name().toLowerCase() + "-" + yunId + "://" + relativePath;
+//         return path;
+//     }
+//
+//     @Override
+//     public YunPathInfo saveFile(String siteId, FileStoragePathEnvInfo env, File file, String md5, boolean refreshCDN,
+//                                 Long cacheAge) {
+//         try (InputStream in = new FileInputStream(file);) {
+//             return saveFile(siteId, env, in, md5, refreshCDN);
+//         } catch (Exception e) {
+//             throw new StatusException("1001", "上传出错", e);
+//         }
+//     }
+//
+// }

+ 420 - 420
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpYunClient.java

@@ -1,420 +1,420 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.util.JsonUtil;
-import cn.com.qmth.examcloud.commons.util.MD5;
-import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
-import com.google.common.collect.Maps;
-import org.apache.commons.compress.utils.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.time.DateUtils;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.config.CookieSpecs;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.entity.InputStreamEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.util.EntityUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import java.io.*;
-import java.net.URLEncoder;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SignatureException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-
-/**
- * upyun client
- *
- * @author WANGWEI
- * @date 2018年11月21日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class UpYunClient {
-
-    private static final Logger LOG = LoggerFactory.getLogger(UpYunClient.class);
-
-    /**
-     * 空间名
-     */
-    protected String bucketName = null;
-
-    /**
-     * 操作员名
-     */
-    protected String userName = null;
-
-    /**
-     * 操作员密码
-     */
-    protected String password = null;
-
-    protected String md5Password = null;
-
-    public static final String API_DOMAIN = "v0.api.upyun.com";
-
-    private static final String MKDIR = "mkdir";
-
-    private final String METHOD_POST = "POST";
-
-    private final String METHOD_PUT = "PUT";
-
-    private final String METHOD_DELETE = "DELETE";
-
-    private final String DATE = "Date";
-
-    private final String AUTHORIZATION = "Authorization";
-
-    private final String SEPARATOR = "/";
-
-    private static CloseableHttpClient httpclient;
-
-    private static RequestConfig requestConfig;
-
-    private String domain;
-
-    private String domainBackup;
-
-    static {
-        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(60,
-                TimeUnit.SECONDS);
-        cm.setValidateAfterInactivity(1000);
-        cm.setMaxTotal(8000);
-        cm.setDefaultMaxPerRoute(800);
-
-        requestConfig = RequestConfig.custom().setConnectionRequestTimeout(500)
-                .setSocketTimeout(10000).setConnectTimeout(10000)
-                .setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
-
-        httpclient = HttpClients.custom().setConnectionManager(cm).disableAutomaticRetries()
-                .setDefaultRequestConfig(requestConfig).build();
-    }
-
-    /**
-     * 构造函数
-     *
-     * @param bucketName
-     * @param userName
-     * @param password
-     */
-    public UpYunClient(String bucketName, String userName, String password, String domain, String domainBackup) {
-
-        this.bucketName = bucketName;
-        this.userName = userName;
-        this.password = password;
-        this.domain = domain;
-        this.domainBackup = domainBackup;
-        this.md5Password = MD5.encrypt32(password);
-    }
-
-    /**
-     * 创建又拍云请求
-     *
-     * @param filePath
-     * @return
-     * @author WANGWEI
-     */
-    public YunHttpRequest buildUpYunHttpRequest(String filePath) {
-        return buildUpYunHttpRequest(filePath, "");
-    }
-
-    /**
-     * 创建又拍云请求
-     *
-     * @param filePath
-     * @param md5
-     * @return
-     * @author WANGWEI
-     */
-    public YunHttpRequest buildUpYunHttpRequest(String filePath, String md5) {
-        String path = filePath.trim();
-        if (!path.startsWith(SEPARATOR)) {
-            path = SEPARATOR + path;
-        }
-        String formUrl = "https://" + API_DOMAIN + "/" + this.bucketName;
-        String date = getDate();
-
-        Map<String, Object> policyArgs = Maps.newHashMap();
-        policyArgs.put("bucket", bucketName);
-        policyArgs.put("save-key", path);
-        Date expiration = DateUtils.addSeconds(new Date(), 600);
-        policyArgs.put("expiration", expiration.getTime() / 1000);
-        policyArgs.put("date", date);
-        policyArgs.put("content-md5", md5);
-
-        String json = JsonUtil.toJson(policyArgs);
-        String policy = Base64.getEncoder().encodeToString(json.getBytes());
-
-        Map<String, String> params = Maps.newHashMap();
-
-        String authorization = null;
-        try {
-            md5 = null == md5 ? "" : md5;
-            authorization = sign(userName, md5Password, METHOD_POST, SEPARATOR + this.bucketName,
-                    date, policy, md5);
-        } catch (Exception e) {
-            throw new StatusException("100005", "[upyun]. fail to build sign", e);
-        }
-
-        params.put("authorization", authorization);
-        params.put("policy", policy);
-
-        String accessUrl = this.domain + filePath;
-
-        YunHttpRequest request = new YunHttpRequest();
-        request.setAccessUrl(accessUrl);
-        request.setFormParams(params);
-        request.setFormUrl(formUrl);
-
-        return request;
-    }
-
-    public UpYunPathInfo writeFile(String filePath, File file) {
-        return writeFile(filePath, file, false);
-    }
-
-    /**
-     * 上传文件
-     *
-     * @param filePath
-     * @param file
-     * @param withMd5
-     * @return
-     * @author WANGWEI
-     */
-    public UpYunPathInfo writeFile(String filePath, File file, boolean withMd5) {
-        String md5 = null;
-        if (withMd5) {
-            md5 = MD5.md5Hex(file);
-        }
-
-        return writeFile(filePath, file, md5);
-    }
-
-    /**
-     * 上传文件
-     *
-     * @param filePath
-     * @param file
-     * @param md5
-     * @return
-     * @author WANGWEI
-     */
-    public UpYunPathInfo writeFile(String filePath, File file, String md5) {
-        InputStream in = null;
-        try {
-            in = new FileInputStream(file);
-            return writeFile(filePath, in, md5);
-        } catch (FileNotFoundException e) {
-            throw new ExamCloudRuntimeException(e);
-        } finally {
-            IOUtils.closeQuietly(in);
-        }
-    }
-
-    /**
-     * 上传文件
-     *
-     * @param filePath
-     * @param in
-     * @return
-     * @author WANGWEI
-     */
-    public UpYunPathInfo writeFile(String filePath, InputStream in) {
-        return writeFile(filePath, in, "");
-    }
-
-    private String encodeFileName(String filePath) {
-        int inx = filePath.lastIndexOf("/");
-        String filename = filePath.substring(inx + 1);
-        String head = filePath.substring(0, inx + 1);
-        try {
-            return head + URLEncoder.encode(filename, "utf-8");
-        } catch (UnsupportedEncodingException e) {
-            LOG.error("编码失败", e);
-        }
-        return filePath;
-    }
-
-    /**
-     * 上传文件
-     *
-     * @param filePath
-     * @param in
-     * @param md5
-     * @return
-     * @author WANGWEI
-     */
-    public UpYunPathInfo writeFile(String filePath, InputStream in, String md5) {
-        String path = formatPath(filePath);
-        path = encodeFileName(path);
-        String url = "https://" + API_DOMAIN + path;
-
-        HttpPut httpPut = new HttpPut(url);
-        httpPut.setConfig(UpYunClient.requestConfig);
-        CloseableHttpResponse response = null;
-
-        long s = System.currentTimeMillis();
-        try {
-            md5 = null == md5 ? "" : md5;
-
-            if (md5.equals(MD5.encrypt32(""))) {
-                throw new StatusException("100009", "empty IO stream");
-            }
-
-            String date = getDate();
-            String authorization = sign(userName, md5Password, METHOD_PUT, path, date, "", md5);
-            httpPut.addHeader(AUTHORIZATION, authorization);
-            httpPut.addHeader(DATE, date);
-            httpPut.addHeader(MKDIR, "true");
-            if (StringUtils.isNotBlank(md5)) {
-                httpPut.addHeader("Content-MD5", md5);
-            }
-
-            httpPut.setEntity(new InputStreamEntity(in));
-            response = httpclient.execute(httpPut);
-            int statusCode = response.getStatusLine().getStatusCode();
-
-            if (HttpStatus.SC_OK != statusCode) {
-                LOG.error("[upyun error] " + EntityUtils.toString(response.getEntity(), "UTF-8"));
-                throw new StatusException("100001", "[upyun]. fail to write file");
-            }
-        } catch (StatusException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new ExamCloudRuntimeException(e);
-        } finally {
-            IOUtils.closeQuietly(in);
-            IOUtils.closeQuietly(response);
-            // httpPut.releaseConnection();
-        }
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("[upyun]. write file. path=" + path + "; cost "
-                    + (System.currentTimeMillis() - s) + " ms.");
-        }
-
-        String fileUrl = this.domain + filePath;
-        return new UpYunPathInfo(fileUrl, filePath);
-    }
-
-    /**
-     * 删除文件
-     *
-     * @param filePath
-     * @return
-     * @author WANGWEI
-     */
-    public void deleteFile(String filePath) {
-        String path = formatPath(filePath);
-        String url = "https://" + API_DOMAIN + path;
-
-        HttpDelete httpDelete = new HttpDelete(url);
-        httpDelete.setConfig(UpYunClient.requestConfig);
-        CloseableHttpResponse response = null;
-
-        long s = System.currentTimeMillis();
-        try {
-            String date = getDate();
-            String authorization = sign(userName, md5Password, METHOD_DELETE, path, date, "", "");
-            httpDelete.addHeader(AUTHORIZATION, authorization);
-            httpDelete.addHeader(DATE, date);
-
-            response = httpclient.execute(httpDelete);
-            int statusCode = response.getStatusLine().getStatusCode();
-
-            if (HttpStatus.SC_OK != statusCode) {
-                LOG.error("[upyun error] " + EntityUtils.toString(response.getEntity(), "UTF-8"));
-                throw new StatusException("100002", "[upyun]. fail to delete file");
-            }
-        } catch (StatusException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new ExamCloudRuntimeException(e);
-        } finally {
-            IOUtils.closeQuietly(response);
-            // httpDelete.releaseConnection();
-        }
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("[upyun]. delete file. path=" + path + "; cost "
-                    + (System.currentTimeMillis() - s) + " ms.");
-        }
-
-    }
-
-    /**
-     * 格式化路径参数
-     * <p>
-     * 最终构成的格式:"/空间名/文件路径"
-     *
-     * @param path 目录路径或文件路径
-     * @return 格式化后的路径
-     */
-    private String formatPath(String path) {
-
-        if (StringUtils.isNotBlank(path)) {
-
-            // 去除前后的空格
-            path = path.trim();
-
-            // 确保路径以"/"开头
-            if (!path.startsWith(SEPARATOR)) {
-                return SEPARATOR + bucketName + SEPARATOR + path;
-            }
-        }
-
-        return SEPARATOR + bucketName + path;
-    }
-
-    private String getDate() {
-        Calendar calendar = Calendar.getInstance();
-        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
-                Locale.US);
-        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
-        return dateFormat.format(calendar.getTime());
-    }
-
-    private byte[] hashHmac(String data, String key)
-            throws SignatureException, NoSuchAlgorithmException, InvalidKeyException {
-        SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");
-        Mac mac = Mac.getInstance("HmacSHA1");
-        mac.init(signingKey);
-        return mac.doFinal(data.getBytes());
-    }
-
-    private String sign(String key, String secret, String method, String uri, String date,
-                        String policy, String md5) throws Exception {
-        String value = method + "&" + uri + "&" + date;
-        if (policy != null && policy.length() > 0) {
-            value = value + "&" + policy;
-        }
-
-        if (md5 != null && md5.length() > 0) {
-            value = value + "&" + md5;
-        }
-        byte[] hmac = hashHmac(value, secret);
-        String sign = Base64.getEncoder().encodeToString(hmac);
-        return "UPYUN " + key + ":" + sign;
-    }
-
-    public String getDomain() {
-        return domain;
-    }
-
-    public String getDomainBackup() {
-        return domainBackup;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.commons.util.JsonUtil;
+// import cn.com.qmth.examcloud.commons.util.MD5;
+// import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
+// import com.google.common.collect.Maps;
+// import org.apache.commons.compress.utils.IOUtils;
+// import org.apache.commons.lang3.StringUtils;
+// import org.apache.commons.lang3.time.DateUtils;
+// import org.apache.http.HttpStatus;
+// import org.apache.http.client.config.CookieSpecs;
+// import org.apache.http.client.config.RequestConfig;
+// import org.apache.http.client.methods.CloseableHttpResponse;
+// import org.apache.http.client.methods.HttpDelete;
+// import org.apache.http.client.methods.HttpPut;
+// import org.apache.http.entity.InputStreamEntity;
+// import org.apache.http.impl.client.CloseableHttpClient;
+// import org.apache.http.impl.client.HttpClients;
+// import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+// import org.apache.http.util.EntityUtils;
+// import org.slf4j.Logger;
+// import org.slf4j.LoggerFactory;
+//
+// import javax.crypto.Mac;
+// import javax.crypto.spec.SecretKeySpec;
+// import java.io.*;
+// import java.net.URLEncoder;
+// import java.security.InvalidKeyException;
+// import java.security.NoSuchAlgorithmException;
+// import java.security.SignatureException;
+// import java.text.SimpleDateFormat;
+// import java.util.*;
+// import java.util.concurrent.TimeUnit;
+//
+// /**
+//  * upyun client
+//  *
+//  * @author WANGWEI
+//  * @date 2018年11月21日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// public class UpYunClient {
+//
+//     private static final Logger LOG = LoggerFactory.getLogger(UpYunClient.class);
+//
+//     /**
+//      * 空间名
+//      */
+//     protected String bucketName = null;
+//
+//     /**
+//      * 操作员名
+//      */
+//     protected String userName = null;
+//
+//     /**
+//      * 操作员密码
+//      */
+//     protected String password = null;
+//
+//     protected String md5Password = null;
+//
+//     public static final String API_DOMAIN = "v0.api.upyun.com";
+//
+//     private static final String MKDIR = "mkdir";
+//
+//     private final String METHOD_POST = "POST";
+//
+//     private final String METHOD_PUT = "PUT";
+//
+//     private final String METHOD_DELETE = "DELETE";
+//
+//     private final String DATE = "Date";
+//
+//     private final String AUTHORIZATION = "Authorization";
+//
+//     private final String SEPARATOR = "/";
+//
+//     private static CloseableHttpClient httpclient;
+//
+//     private static RequestConfig requestConfig;
+//
+//     private String domain;
+//
+//     private String domainBackup;
+//
+//     static {
+//         PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(60,
+//                 TimeUnit.SECONDS);
+//         cm.setValidateAfterInactivity(1000);
+//         cm.setMaxTotal(8000);
+//         cm.setDefaultMaxPerRoute(800);
+//
+//         requestConfig = RequestConfig.custom().setConnectionRequestTimeout(500)
+//                 .setSocketTimeout(10000).setConnectTimeout(10000)
+//                 .setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
+//
+//         httpclient = HttpClients.custom().setConnectionManager(cm).disableAutomaticRetries()
+//                 .setDefaultRequestConfig(requestConfig).build();
+//     }
+//
+//     /**
+//      * 构造函数
+//      *
+//      * @param bucketName
+//      * @param userName
+//      * @param password
+//      */
+//     public UpYunClient(String bucketName, String userName, String password, String domain, String domainBackup) {
+//
+//         this.bucketName = bucketName;
+//         this.userName = userName;
+//         this.password = password;
+//         this.domain = domain;
+//         this.domainBackup = domainBackup;
+//         this.md5Password = MD5.encrypt32(password);
+//     }
+//
+//     /**
+//      * 创建又拍云请求
+//      *
+//      * @param filePath
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public YunHttpRequest buildUpYunHttpRequest(String filePath) {
+//         return buildUpYunHttpRequest(filePath, "");
+//     }
+//
+//     /**
+//      * 创建又拍云请求
+//      *
+//      * @param filePath
+//      * @param md5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public YunHttpRequest buildUpYunHttpRequest(String filePath, String md5) {
+//         String path = filePath.trim();
+//         if (!path.startsWith(SEPARATOR)) {
+//             path = SEPARATOR + path;
+//         }
+//         String formUrl = "https://" + API_DOMAIN + "/" + this.bucketName;
+//         String date = getDate();
+//
+//         Map<String, Object> policyArgs = Maps.newHashMap();
+//         policyArgs.put("bucket", bucketName);
+//         policyArgs.put("save-key", path);
+//         Date expiration = DateUtils.addSeconds(new Date(), 600);
+//         policyArgs.put("expiration", expiration.getTime() / 1000);
+//         policyArgs.put("date", date);
+//         policyArgs.put("content-md5", md5);
+//
+//         String json = JsonUtil.toJson(policyArgs);
+//         String policy = Base64.getEncoder().encodeToString(json.getBytes());
+//
+//         Map<String, String> params = Maps.newHashMap();
+//
+//         String authorization = null;
+//         try {
+//             md5 = null == md5 ? "" : md5;
+//             authorization = sign(userName, md5Password, METHOD_POST, SEPARATOR + this.bucketName,
+//                     date, policy, md5);
+//         } catch (Exception e) {
+//             throw new StatusException("100005", "[upyun]. fail to build sign", e);
+//         }
+//
+//         params.put("authorization", authorization);
+//         params.put("policy", policy);
+//
+//         String accessUrl = this.domain + filePath;
+//
+//         YunHttpRequest request = new YunHttpRequest();
+//         request.setAccessUrl(accessUrl);
+//         request.setFormParams(params);
+//         request.setFormUrl(formUrl);
+//
+//         return request;
+//     }
+//
+//     public UpYunPathInfo writeFile(String filePath, File file) {
+//         return writeFile(filePath, file, false);
+//     }
+//
+//     /**
+//      * 上传文件
+//      *
+//      * @param filePath
+//      * @param file
+//      * @param withMd5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public UpYunPathInfo writeFile(String filePath, File file, boolean withMd5) {
+//         String md5 = null;
+//         if (withMd5) {
+//             md5 = MD5.md5Hex(file);
+//         }
+//
+//         return writeFile(filePath, file, md5);
+//     }
+//
+//     /**
+//      * 上传文件
+//      *
+//      * @param filePath
+//      * @param file
+//      * @param md5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public UpYunPathInfo writeFile(String filePath, File file, String md5) {
+//         InputStream in = null;
+//         try {
+//             in = new FileInputStream(file);
+//             return writeFile(filePath, in, md5);
+//         } catch (FileNotFoundException e) {
+//             throw new ExamCloudRuntimeException(e);
+//         } finally {
+//             IOUtils.closeQuietly(in);
+//         }
+//     }
+//
+//     /**
+//      * 上传文件
+//      *
+//      * @param filePath
+//      * @param in
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public UpYunPathInfo writeFile(String filePath, InputStream in) {
+//         return writeFile(filePath, in, "");
+//     }
+//
+//     private String encodeFileName(String filePath) {
+//         int inx = filePath.lastIndexOf("/");
+//         String filename = filePath.substring(inx + 1);
+//         String head = filePath.substring(0, inx + 1);
+//         try {
+//             return head + URLEncoder.encode(filename, "utf-8");
+//         } catch (UnsupportedEncodingException e) {
+//             LOG.error("编码失败", e);
+//         }
+//         return filePath;
+//     }
+//
+//     /**
+//      * 上传文件
+//      *
+//      * @param filePath
+//      * @param in
+//      * @param md5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public UpYunPathInfo writeFile(String filePath, InputStream in, String md5) {
+//         String path = formatPath(filePath);
+//         path = encodeFileName(path);
+//         String url = "https://" + API_DOMAIN + path;
+//
+//         HttpPut httpPut = new HttpPut(url);
+//         httpPut.setConfig(UpYunClient.requestConfig);
+//         CloseableHttpResponse response = null;
+//
+//         long s = System.currentTimeMillis();
+//         try {
+//             md5 = null == md5 ? "" : md5;
+//
+//             if (md5.equals(MD5.encrypt32(""))) {
+//                 throw new StatusException("100009", "empty IO stream");
+//             }
+//
+//             String date = getDate();
+//             String authorization = sign(userName, md5Password, METHOD_PUT, path, date, "", md5);
+//             httpPut.addHeader(AUTHORIZATION, authorization);
+//             httpPut.addHeader(DATE, date);
+//             httpPut.addHeader(MKDIR, "true");
+//             if (StringUtils.isNotBlank(md5)) {
+//                 httpPut.addHeader("Content-MD5", md5);
+//             }
+//
+//             httpPut.setEntity(new InputStreamEntity(in));
+//             response = httpclient.execute(httpPut);
+//             int statusCode = response.getStatusLine().getStatusCode();
+//
+//             if (HttpStatus.SC_OK != statusCode) {
+//                 LOG.error("[upyun error] " + EntityUtils.toString(response.getEntity(), "UTF-8"));
+//                 throw new StatusException("100001", "[upyun]. fail to write file");
+//             }
+//         } catch (StatusException e) {
+//             throw e;
+//         } catch (Exception e) {
+//             throw new ExamCloudRuntimeException(e);
+//         } finally {
+//             IOUtils.closeQuietly(in);
+//             IOUtils.closeQuietly(response);
+//             // httpPut.releaseConnection();
+//         }
+//
+//         if (LOG.isDebugEnabled()) {
+//             LOG.debug("[upyun]. write file. path=" + path + "; cost "
+//                     + (System.currentTimeMillis() - s) + " ms.");
+//         }
+//
+//         String fileUrl = this.domain + filePath;
+//         return new UpYunPathInfo(fileUrl, filePath);
+//     }
+//
+//     /**
+//      * 删除文件
+//      *
+//      * @param filePath
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public void deleteFile(String filePath) {
+//         String path = formatPath(filePath);
+//         String url = "https://" + API_DOMAIN + path;
+//
+//         HttpDelete httpDelete = new HttpDelete(url);
+//         httpDelete.setConfig(UpYunClient.requestConfig);
+//         CloseableHttpResponse response = null;
+//
+//         long s = System.currentTimeMillis();
+//         try {
+//             String date = getDate();
+//             String authorization = sign(userName, md5Password, METHOD_DELETE, path, date, "", "");
+//             httpDelete.addHeader(AUTHORIZATION, authorization);
+//             httpDelete.addHeader(DATE, date);
+//
+//             response = httpclient.execute(httpDelete);
+//             int statusCode = response.getStatusLine().getStatusCode();
+//
+//             if (HttpStatus.SC_OK != statusCode) {
+//                 LOG.error("[upyun error] " + EntityUtils.toString(response.getEntity(), "UTF-8"));
+//                 throw new StatusException("100002", "[upyun]. fail to delete file");
+//             }
+//         } catch (StatusException e) {
+//             throw e;
+//         } catch (Exception e) {
+//             throw new ExamCloudRuntimeException(e);
+//         } finally {
+//             IOUtils.closeQuietly(response);
+//             // httpDelete.releaseConnection();
+//         }
+//
+//         if (LOG.isDebugEnabled()) {
+//             LOG.debug("[upyun]. delete file. path=" + path + "; cost "
+//                     + (System.currentTimeMillis() - s) + " ms.");
+//         }
+//
+//     }
+//
+//     /**
+//      * 格式化路径参数
+//      * <p>
+//      * 最终构成的格式:"/空间名/文件路径"
+//      *
+//      * @param path 目录路径或文件路径
+//      * @return 格式化后的路径
+//      */
+//     private String formatPath(String path) {
+//
+//         if (StringUtils.isNotBlank(path)) {
+//
+//             // 去除前后的空格
+//             path = path.trim();
+//
+//             // 确保路径以"/"开头
+//             if (!path.startsWith(SEPARATOR)) {
+//                 return SEPARATOR + bucketName + SEPARATOR + path;
+//             }
+//         }
+//
+//         return SEPARATOR + bucketName + path;
+//     }
+//
+//     private String getDate() {
+//         Calendar calendar = Calendar.getInstance();
+//         SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
+//                 Locale.US);
+//         dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+//         return dateFormat.format(calendar.getTime());
+//     }
+//
+//     private byte[] hashHmac(String data, String key)
+//             throws SignatureException, NoSuchAlgorithmException, InvalidKeyException {
+//         SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");
+//         Mac mac = Mac.getInstance("HmacSHA1");
+//         mac.init(signingKey);
+//         return mac.doFinal(data.getBytes());
+//     }
+//
+//     private String sign(String key, String secret, String method, String uri, String date,
+//                         String policy, String md5) throws Exception {
+//         String value = method + "&" + uri + "&" + date;
+//         if (policy != null && policy.length() > 0) {
+//             value = value + "&" + policy;
+//         }
+//
+//         if (md5 != null && md5.length() > 0) {
+//             value = value + "&" + md5;
+//         }
+//         byte[] hmac = hashHmac(value, secret);
+//         String sign = Base64.getEncoder().encodeToString(hmac);
+//         return "UPYUN " + key + ":" + sign;
+//     }
+//
+//     public String getDomain() {
+//         return domain;
+//     }
+//
+//     public String getDomainBackup() {
+//         return domainBackup;
+//     }
+//
+// }

+ 44 - 44
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpYunPathInfo.java

@@ -1,44 +1,44 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-/**
- * 路径
- *
- * @author WANGWEI
- * @date 2019年5月9日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class UpYunPathInfo {
-
-    private String url;
-
-    private String relativePath;
-
-    /**
-     * 构造函数
-     *
-     * @param url
-     * @param relativePath
-     */
-    public UpYunPathInfo(String url, String relativePath) {
-        super();
-        this.url = url;
-        this.relativePath = relativePath;
-    }
-
-    public String getUrl() {
-        return url;
-    }
-
-    public void setUrl(String url) {
-        this.url = url;
-    }
-
-    public String getRelativePath() {
-        return relativePath;
-    }
-
-    public void setRelativePath(String relativePath) {
-        this.relativePath = relativePath;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// /**
+//  * 路径
+//  *
+//  * @author WANGWEI
+//  * @date 2019年5月9日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// public class UpYunPathInfo {
+//
+//     private String url;
+//
+//     private String relativePath;
+//
+//     /**
+//      * 构造函数
+//      *
+//      * @param url
+//      * @param relativePath
+//      */
+//     public UpYunPathInfo(String url, String relativePath) {
+//         super();
+//         this.url = url;
+//         this.relativePath = relativePath;
+//     }
+//
+//     public String getUrl() {
+//         return url;
+//     }
+//
+//     public void setUrl(String url) {
+//         this.url = url;
+//     }
+//
+//     public String getRelativePath() {
+//         return relativePath;
+//     }
+//
+//     public void setRelativePath(String relativePath) {
+//         this.relativePath = relativePath;
+//     }
+//
+// }

+ 159 - 159
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunPathEnvironmentInfo.java

@@ -1,159 +1,159 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-/**
- * 又拍云路径变量
- *
- * @author WANGWEI
- * @date 2018年11月21日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class UpyunPathEnvironmentInfo implements JsonSerializable {
-
-    private static final long serialVersionUID = -3579995914084929142L;
-
-    /**
-     * 顶级机构ID
-     */
-    private String rootOrgId;
-
-    /**
-     * 顶级机构域名
-     */
-    private String rootOrgDomain;
-
-    /**
-     * 用户ID(包含普普通用户ID和studentId)
-     */
-    private String userId;
-
-    /**
-     * 时间戳
-     */
-    private String timeMillis;
-
-    /**
-     * 文件后缀(以"."开头,如 ".jpg",".zip")
-     */
-    private String fileSuffix;
-
-    /**
-     * 相对路径
-     */
-    private String relativePath;
-
-    /**
-     * 扩展属性
-     */
-    private String ext1;
-
-    /**
-     * 扩展属性
-     */
-    private String ext2;
-
-    /**
-     * 扩展属性
-     */
-    private String ext3;
-
-    /**
-     * 扩展属性
-     */
-    private String ext4;
-
-    /**
-     * 扩展属性
-     */
-    private String ext5;
-
-    public String getRootOrgId() {
-        return rootOrgId;
-    }
-
-    public void setRootOrgId(String rootOrgId) {
-        this.rootOrgId = rootOrgId;
-    }
-
-    public String getRootOrgDomain() {
-        return rootOrgDomain;
-    }
-
-    public void setRootOrgDomain(String rootOrgDomain) {
-        this.rootOrgDomain = rootOrgDomain;
-    }
-
-    public String getUserId() {
-        return userId;
-    }
-
-    public void setUserId(String userId) {
-        this.userId = userId;
-    }
-
-    public String getTimeMillis() {
-        return timeMillis;
-    }
-
-    public void setTimeMillis(String timeMillis) {
-        this.timeMillis = timeMillis;
-    }
-
-    public String getFileSuffix() {
-        return fileSuffix;
-    }
-
-    public void setFileSuffix(String fileSuffix) {
-        this.fileSuffix = fileSuffix;
-    }
-
-    public String getRelativePath() {
-        return relativePath;
-    }
-
-    public void setRelativePath(String relativePath) {
-        this.relativePath = relativePath;
-    }
-
-    public String getExt1() {
-        return ext1;
-    }
-
-    public void setExt1(String ext1) {
-        this.ext1 = ext1;
-    }
-
-    public String getExt2() {
-        return ext2;
-    }
-
-    public void setExt2(String ext2) {
-        this.ext2 = ext2;
-    }
-
-    public String getExt3() {
-        return ext3;
-    }
-
-    public void setExt3(String ext3) {
-        this.ext3 = ext3;
-    }
-
-    public String getExt4() {
-        return ext4;
-    }
-
-    public void setExt4(String ext4) {
-        this.ext4 = ext4;
-    }
-
-    public String getExt5() {
-        return ext5;
-    }
-
-    public void setExt5(String ext5) {
-        this.ext5 = ext5;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+//
+// /**
+//  * 又拍云路径变量
+//  *
+//  * @author WANGWEI
+//  * @date 2018年11月21日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// public class UpyunPathEnvironmentInfo implements JsonSerializable {
+//
+//     private static final long serialVersionUID = -3579995914084929142L;
+//
+//     /**
+//      * 顶级机构ID
+//      */
+//     private String rootOrgId;
+//
+//     /**
+//      * 顶级机构域名
+//      */
+//     private String rootOrgDomain;
+//
+//     /**
+//      * 用户ID(包含普普通用户ID和studentId)
+//      */
+//     private String userId;
+//
+//     /**
+//      * 时间戳
+//      */
+//     private String timeMillis;
+//
+//     /**
+//      * 文件后缀(以"."开头,如 ".jpg",".zip")
+//      */
+//     private String fileSuffix;
+//
+//     /**
+//      * 相对路径
+//      */
+//     private String relativePath;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext1;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext2;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext3;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext4;
+//
+//     /**
+//      * 扩展属性
+//      */
+//     private String ext5;
+//
+//     public String getRootOrgId() {
+//         return rootOrgId;
+//     }
+//
+//     public void setRootOrgId(String rootOrgId) {
+//         this.rootOrgId = rootOrgId;
+//     }
+//
+//     public String getRootOrgDomain() {
+//         return rootOrgDomain;
+//     }
+//
+//     public void setRootOrgDomain(String rootOrgDomain) {
+//         this.rootOrgDomain = rootOrgDomain;
+//     }
+//
+//     public String getUserId() {
+//         return userId;
+//     }
+//
+//     public void setUserId(String userId) {
+//         this.userId = userId;
+//     }
+//
+//     public String getTimeMillis() {
+//         return timeMillis;
+//     }
+//
+//     public void setTimeMillis(String timeMillis) {
+//         this.timeMillis = timeMillis;
+//     }
+//
+//     public String getFileSuffix() {
+//         return fileSuffix;
+//     }
+//
+//     public void setFileSuffix(String fileSuffix) {
+//         this.fileSuffix = fileSuffix;
+//     }
+//
+//     public String getRelativePath() {
+//         return relativePath;
+//     }
+//
+//     public void setRelativePath(String relativePath) {
+//         this.relativePath = relativePath;
+//     }
+//
+//     public String getExt1() {
+//         return ext1;
+//     }
+//
+//     public void setExt1(String ext1) {
+//         this.ext1 = ext1;
+//     }
+//
+//     public String getExt2() {
+//         return ext2;
+//     }
+//
+//     public void setExt2(String ext2) {
+//         this.ext2 = ext2;
+//     }
+//
+//     public String getExt3() {
+//         return ext3;
+//     }
+//
+//     public void setExt3(String ext3) {
+//         this.ext3 = ext3;
+//     }
+//
+//     public String getExt4() {
+//         return ext4;
+//     }
+//
+//     public void setExt4(String ext4) {
+//         this.ext4 = ext4;
+//     }
+//
+//     public String getExt5() {
+//         return ext5;
+//     }
+//
+//     public void setExt5(String ext5) {
+//         this.ext5 = ext5;
+//     }
+//
+// }

+ 82 - 82
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunService.java

@@ -1,82 +1,82 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
-
-import java.io.File;
-import java.io.InputStream;
-
-/**
- * 又拍云 服务
- *
- * @author WANGWEI
- * @date 2018年6月29日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public interface UpyunService {
-
-    /**
-     * 写文件
-     *
-     * @param siteId
-     * @param env
-     * @param in
-     * @param md5
-     * @return
-     * @author WANGWEI
-     */
-    UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, InputStream in,
-                            String md5);
-
-    /**
-     * 写文件
-     *
-     * @param siteId
-     * @param env
-     * @param file
-     * @param withMd5
-     * @return
-     * @author WANGWEI
-     */
-    UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
-                            boolean withMd5);
-
-    /**
-     * 写文件
-     *
-     * @param siteId
-     * @param env
-     * @param file
-     * @param md5
-     * @return
-     * @author WANGWEI
-     */
-    UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file, String md5);
-
-    /**
-     * 删除文件
-     *
-     * @param siteId
-     * @param filePath
-     * @author WANGWEI
-     */
-    void delete(String siteId, String filePath);
-
-    /**
-     * 删除文件
-     *
-     * @param upyunId
-     * @param filePath
-     */
-    void deleteByUpyunId(String upyunId, String filePath);
-
-    /**
-     * 创建http请求
-     *
-     * @param filePath
-     * @param withMd5
-     * @return
-     * @author WANGWEI
-     */
-    YunHttpRequest buildUpYunHttpRequest(String siteId, UpyunPathEnvironmentInfo env, String md5);
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
+//
+// import java.io.File;
+// import java.io.InputStream;
+//
+// /**
+//  * 又拍云 服务
+//  *
+//  * @author WANGWEI
+//  * @date 2018年6月29日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// public interface UpyunService {
+//
+//     /**
+//      * 写文件
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param in
+//      * @param md5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, InputStream in,
+//                             String md5);
+//
+//     /**
+//      * 写文件
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param file
+//      * @param withMd5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
+//                             boolean withMd5);
+//
+//     /**
+//      * 写文件
+//      *
+//      * @param siteId
+//      * @param env
+//      * @param file
+//      * @param md5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file, String md5);
+//
+//     /**
+//      * 删除文件
+//      *
+//      * @param siteId
+//      * @param filePath
+//      * @author WANGWEI
+//      */
+//     void delete(String siteId, String filePath);
+//
+//     /**
+//      * 删除文件
+//      *
+//      * @param upyunId
+//      * @param filePath
+//      */
+//     void deleteByUpyunId(String upyunId, String filePath);
+//
+//     /**
+//      * 创建http请求
+//      *
+//      * @param filePath
+//      * @param withMd5
+//      * @return
+//      * @author WANGWEI
+//      */
+//     YunHttpRequest buildUpYunHttpRequest(String siteId, UpyunPathEnvironmentInfo env, String md5);
+//
+// }

+ 110 - 110
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunServiceImpl.java

@@ -1,110 +1,110 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-import cn.com.qmth.examcloud.commons.util.FreeMarkerUtil;
-import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-import java.io.File;
-import java.io.InputStream;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年9月4日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Service
-public class UpyunServiceImpl implements UpyunService {
-
-    private static final Logger LOG = LoggerFactory.getLogger(UpyunServiceImpl.class);
-
-    @Override
-    public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, InputStream in,
-                                   String md5) {
-
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-
-        UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-        UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
-
-        String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
-        path = disposePath(path);
-        UpYunPathInfo pathInfo = upYunClient.writeFile(path, in, md5);
-        return pathInfo;
-    }
-
-    @Override
-    public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
-                                   boolean withMd5) {
-
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-
-        UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-        UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
-
-        String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
-        path = disposePath(path);
-        UpYunPathInfo pathInfo = upYunClient.writeFile(path, file, withMd5);
-        return pathInfo;
-    }
-
-    @Override
-    public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
-                                   String md5) {
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-
-        UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-        UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
-
-        String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
-        path = disposePath(path);
-        UpYunPathInfo pathInfo = upYunClient.writeFile(path, file, md5);
-        return pathInfo;
-    }
-
-    @Override
-    public void delete(String siteId, String filePath) {
-
-        UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-        UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
-
-        upYunClient.deleteFile(filePath);
-    }
-
-    @Override
-    public YunHttpRequest buildUpYunHttpRequest(String siteId, UpyunPathEnvironmentInfo env,
-                                                String md5) {
-
-        env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
-
-        UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-        UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
-
-        String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
-        path = disposePath(path);
-        YunHttpRequest request = upYunClient.buildUpYunHttpRequest(path, md5);
-        return request;
-    }
-
-    @Override
-    public void deleteByUpyunId(String upyunId, String filePath) {
-
-        UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
-
-        upYunClient.deleteFile(filePath);
-    }
-
-    private String disposePath(String path) {
-        for (; ; ) {
-            if (path.startsWith("/")) {
-                path = path.substring(1);
-            } else {
-                return "/" + path;
-            }
-        }
-    }
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// import cn.com.qmth.examcloud.commons.util.FreeMarkerUtil;
+// import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
+// import org.slf4j.Logger;
+// import org.slf4j.LoggerFactory;
+// import org.springframework.stereotype.Service;
+//
+// import java.io.File;
+// import java.io.InputStream;
+//
+// /**
+//  * 类注释
+//  *
+//  * @author WANGWEI
+//  * @date 2018年9月4日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// @Service
+// public class UpyunServiceImpl implements UpyunService {
+//
+//     private static final Logger LOG = LoggerFactory.getLogger(UpyunServiceImpl.class);
+//
+//     @Override
+//     public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, InputStream in,
+//                                    String md5) {
+//
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//
+//         UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+//         UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
+//
+//         String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+//         path = disposePath(path);
+//         UpYunPathInfo pathInfo = upYunClient.writeFile(path, in, md5);
+//         return pathInfo;
+//     }
+//
+//     @Override
+//     public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
+//                                    boolean withMd5) {
+//
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//
+//         UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+//         UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
+//
+//         String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+//         path = disposePath(path);
+//         UpYunPathInfo pathInfo = upYunClient.writeFile(path, file, withMd5);
+//         return pathInfo;
+//     }
+//
+//     @Override
+//     public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file,
+//                                    String md5) {
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//
+//         UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+//         UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
+//
+//         String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+//         path = disposePath(path);
+//         UpYunPathInfo pathInfo = upYunClient.writeFile(path, file, md5);
+//         return pathInfo;
+//     }
+//
+//     @Override
+//     public void delete(String siteId, String filePath) {
+//
+//         UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+//         UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
+//
+//         upYunClient.deleteFile(filePath);
+//     }
+//
+//     @Override
+//     public YunHttpRequest buildUpYunHttpRequest(String siteId, UpyunPathEnvironmentInfo env,
+//                                                 String md5) {
+//
+//         env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+//
+//         UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+//         UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
+//
+//         String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+//         path = disposePath(path);
+//         YunHttpRequest request = upYunClient.buildUpYunHttpRequest(path, md5);
+//         return request;
+//     }
+//
+//     @Override
+//     public void deleteByUpyunId(String upyunId, String filePath) {
+//
+//         UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunId);
+//
+//         upYunClient.deleteFile(filePath);
+//     }
+//
+//     private String disposePath(String path) {
+//         for (; ; ) {
+//             if (path.startsWith("/")) {
+//                 path = path.substring(1);
+//             } else {
+//                 return "/" + path;
+//             }
+//         }
+//     }
+//
+// }

+ 66 - 66
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunSite.java

@@ -1,66 +1,66 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年11月21日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class UpyunSite implements JsonSerializable {
-
-    private static final long serialVersionUID = -1754474062438702321L;
-
-    private String id;
-
-    private String name;
-
-    private String upyunId;
-
-    private String maxSize;
-
-    private String path;
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getUpyunId() {
-        return upyunId;
-    }
-
-    public void setUpyunId(String upyunId) {
-        this.upyunId = upyunId;
-    }
-
-    public String getMaxSize() {
-        return maxSize;
-    }
-
-    public void setMaxSize(String maxSize) {
-        this.maxSize = maxSize;
-    }
-
-    public String getPath() {
-        return path;
-    }
-
-    public void setPath(String path) {
-        this.path = path;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+//
+// /**
+//  * 类注释
+//  *
+//  * @author WANGWEI
+//  * @date 2018年11月21日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// public class UpyunSite implements JsonSerializable {
+//
+//     private static final long serialVersionUID = -1754474062438702321L;
+//
+//     private String id;
+//
+//     private String name;
+//
+//     private String upyunId;
+//
+//     private String maxSize;
+//
+//     private String path;
+//
+//     public String getId() {
+//         return id;
+//     }
+//
+//     public void setId(String id) {
+//         this.id = id;
+//     }
+//
+//     public String getName() {
+//         return name;
+//     }
+//
+//     public void setName(String name) {
+//         this.name = name;
+//     }
+//
+//     public String getUpyunId() {
+//         return upyunId;
+//     }
+//
+//     public void setUpyunId(String upyunId) {
+//         this.upyunId = upyunId;
+//     }
+//
+//     public String getMaxSize() {
+//         return maxSize;
+//     }
+//
+//     public void setMaxSize(String maxSize) {
+//         this.maxSize = maxSize;
+//     }
+//
+//     public String getPath() {
+//         return path;
+//     }
+//
+//     public void setPath(String path) {
+//         this.path = path;
+//     }
+//
+// }

+ 137 - 137
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunSiteManager.java

@@ -1,137 +1,137 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.helpers.XStreamBuilder;
-import cn.com.qmth.examcloud.commons.util.PathUtil;
-import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
-import com.thoughtworks.xstream.XStream;
-import org.apache.commons.lang3.StringUtils;
-
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * upyun site manager
- *
- * @author WANGWEI
- * @date 2018年11月21日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class UpyunSiteManager {
-
-    private static final Map<String, UpYunClient> CLIENT_HOLDERS = new ConcurrentHashMap<>();
-
-    private static final Map<String, UpyunSite> SITE_HOLDERS = new ConcurrentHashMap<>();
-
-    public static void initSite() {
-        String resoucePath = PathUtil.getResoucePath("upyun.xml");
-        File file = new File(resoucePath);
-
-        XStream xStream = XStreamBuilder.newInstance().build();
-        xStream.allowTypes(new Class[]{UpyunSite.class, List.class});
-        xStream.alias("sites", List.class);
-        xStream.alias("site", UpyunSite.class);
-
-        List<UpyunSite> list = null;
-        try {
-            @SuppressWarnings("unchecked")
-            List<UpyunSite> obj = (List<UpyunSite>) xStream.fromXML(file);
-            list = obj;
-        } catch (Exception e) {
-            throw new StatusException("520001", "upyun.xml is wrong", e);
-        }
-
-        for (UpyunSite upyunSite : list) {
-
-            SITE_HOLDERS.put(upyunSite.getId(), upyunSite);
-
-        }
-
-    }
-
-    public static void initClient() {
-        String upyunNum = PropertyHolder.getString("$upyun.site.num");
-        if (StringUtils.isBlank(upyunNum)) {
-            throw new StatusException("520021", "upyunNum is not configured.");
-        }
-        int num = Integer.parseInt(upyunNum);
-        for (int i = 1; i <= num; i++) {
-            String upyunId = i + "";
-            String bucketName = PropertyHolder.getString("$upyun.site." + upyunId + ".bucketName");
-            String userName = PropertyHolder.getString("$upyun.site." + upyunId + ".userName");
-            String password = PropertyHolder.getString("$upyun.site." + upyunId + ".password");
-            String domain = PropertyHolder.getString("$upyun.site." + upyunId + ".domain");
-            String domainBackup = PropertyHolder.getString("$upyun.site." + upyunId + ".domain.backup");
-
-            if (StringUtils.isBlank(bucketName)) {
-                throw new StatusException("520002", "bucketName is not configured. upyunId=" + upyunId);
-            }
-            if (StringUtils.isBlank(userName)) {
-                throw new StatusException("520003", "userName is not configured. upyunId=" + upyunId);
-            }
-            if (StringUtils.isBlank(password)) {
-                throw new StatusException("520004", "password is not configured. upyunId=" + upyunId);
-            }
-            if (StringUtils.isBlank(domain)) {
-                throw new StatusException("520005", "domain is not configured. upyunId=" + upyunId);
-            }
-
-            if (null == CLIENT_HOLDERS.get(upyunId)) {
-                UpYunClient upYunClient = new UpYunClient(bucketName, userName, password, domain, domainBackup);
-                CLIENT_HOLDERS.put(upyunId, upYunClient);
-            }
-        }
-    }
-
-    /**
-     * 方法注释
-     *
-     * @param upyunId
-     * @return
-     * @author WANGWEI
-     */
-    public static UpYunClient getUpYunClientByUpyunId(String upyunId) {
-        UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunId);
-
-        if (null == upYunClient) {
-            throw new StatusException("520006", "upYunClient is null");
-        }
-        return upYunClient;
-    }
-
-    /**
-     * 方法注释
-     *
-     * @param siteId
-     * @return
-     * @author WANGWEI
-     */
-    public static UpYunClient getUpYunClientBySiteId(String siteId) {
-        UpyunSite upyunSite = getUpyunSite(siteId);
-        UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunSite.getUpyunId());
-
-        if (null == upYunClient) {
-            throw new StatusException("520007", "upYunClient is null");
-        }
-        return upYunClient;
-    }
-
-    /**
-     * 方法注释
-     *
-     * @param siteId
-     * @return
-     * @author WANGWEI
-     */
-    public static UpyunSite getUpyunSite(String siteId) {
-        UpyunSite upyunSite = SITE_HOLDERS.get(siteId);
-
-        if (null == upyunSite) {
-            throw new StatusException("520008", "upyunSite is null");
-        }
-        return upyunSite;
-    }
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.commons.helpers.XStreamBuilder;
+// import cn.com.qmth.examcloud.commons.util.PathUtil;
+// import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
+// import com.thoughtworks.xstream.XStream;
+// import org.apache.commons.lang3.StringUtils;
+//
+// import java.io.File;
+// import java.util.List;
+// import java.util.Map;
+// import java.util.concurrent.ConcurrentHashMap;
+//
+// /**
+//  * upyun site manager
+//  *
+//  * @author WANGWEI
+//  * @date 2018年11月21日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// public class UpyunSiteManager {
+//
+//     private static final Map<String, UpYunClient> CLIENT_HOLDERS = new ConcurrentHashMap<>();
+//
+//     private static final Map<String, UpyunSite> SITE_HOLDERS = new ConcurrentHashMap<>();
+//
+//     public static void initSite() {
+//         String resoucePath = PathUtil.getResoucePath("upyun.xml");
+//         File file = new File(resoucePath);
+//
+//         XStream xStream = XStreamBuilder.newInstance().build();
+//         xStream.allowTypes(new Class[]{UpyunSite.class, List.class});
+//         xStream.alias("sites", List.class);
+//         xStream.alias("site", UpyunSite.class);
+//
+//         List<UpyunSite> list = null;
+//         try {
+//             @SuppressWarnings("unchecked")
+//             List<UpyunSite> obj = (List<UpyunSite>) xStream.fromXML(file);
+//             list = obj;
+//         } catch (Exception e) {
+//             throw new StatusException("520001", "upyun.xml is wrong", e);
+//         }
+//
+//         for (UpyunSite upyunSite : list) {
+//
+//             SITE_HOLDERS.put(upyunSite.getId(), upyunSite);
+//
+//         }
+//
+//     }
+//
+//     public static void initClient() {
+//         String upyunNum = PropertyHolder.getString("$upyun.site.num");
+//         if (StringUtils.isBlank(upyunNum)) {
+//             throw new StatusException("520021", "upyunNum is not configured.");
+//         }
+//         int num = Integer.parseInt(upyunNum);
+//         for (int i = 1; i <= num; i++) {
+//             String upyunId = i + "";
+//             String bucketName = PropertyHolder.getString("$upyun.site." + upyunId + ".bucketName");
+//             String userName = PropertyHolder.getString("$upyun.site." + upyunId + ".userName");
+//             String password = PropertyHolder.getString("$upyun.site." + upyunId + ".password");
+//             String domain = PropertyHolder.getString("$upyun.site." + upyunId + ".domain");
+//             String domainBackup = PropertyHolder.getString("$upyun.site." + upyunId + ".domain.backup");
+//
+//             if (StringUtils.isBlank(bucketName)) {
+//                 throw new StatusException("520002", "bucketName is not configured. upyunId=" + upyunId);
+//             }
+//             if (StringUtils.isBlank(userName)) {
+//                 throw new StatusException("520003", "userName is not configured. upyunId=" + upyunId);
+//             }
+//             if (StringUtils.isBlank(password)) {
+//                 throw new StatusException("520004", "password is not configured. upyunId=" + upyunId);
+//             }
+//             if (StringUtils.isBlank(domain)) {
+//                 throw new StatusException("520005", "domain is not configured. upyunId=" + upyunId);
+//             }
+//
+//             if (null == CLIENT_HOLDERS.get(upyunId)) {
+//                 UpYunClient upYunClient = new UpYunClient(bucketName, userName, password, domain, domainBackup);
+//                 CLIENT_HOLDERS.put(upyunId, upYunClient);
+//             }
+//         }
+//     }
+//
+//     /**
+//      * 方法注释
+//      *
+//      * @param upyunId
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public static UpYunClient getUpYunClientByUpyunId(String upyunId) {
+//         UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunId);
+//
+//         if (null == upYunClient) {
+//             throw new StatusException("520006", "upYunClient is null");
+//         }
+//         return upYunClient;
+//     }
+//
+//     /**
+//      * 方法注释
+//      *
+//      * @param siteId
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public static UpYunClient getUpYunClientBySiteId(String siteId) {
+//         UpyunSite upyunSite = getUpyunSite(siteId);
+//         UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunSite.getUpyunId());
+//
+//         if (null == upYunClient) {
+//             throw new StatusException("520007", "upYunClient is null");
+//         }
+//         return upYunClient;
+//     }
+//
+//     /**
+//      * 方法注释
+//      *
+//      * @param siteId
+//      * @return
+//      * @author WANGWEI
+//      */
+//     public static UpyunSite getUpyunSite(String siteId) {
+//         UpyunSite upyunSite = SITE_HOLDERS.get(siteId);
+//
+//         if (null == upyunSite) {
+//             throw new StatusException("520008", "upyunSite is null");
+//         }
+//         return upyunSite;
+//     }
+//
+// }

+ 64 - 64
examcloud-support/src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunTest.java

@@ -1,64 +1,64 @@
-package cn.com.qmth.examcloud.web.upyun;
-
-import cn.com.qmth.examcloud.commons.util.JsonUtil;
-import cn.com.qmth.examcloud.commons.util.MD5;
-import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.RandomUtils;
-import org.apache.http.Consts;
-import org.apache.http.HttpEntity;
-import org.apache.http.StatusLine;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.MultipartEntityBuilder;
-import org.apache.http.entity.mime.content.StringBody;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-import java.io.File;
-import java.util.Map.Entry;
-
-public class UpyunTest {
-
-    public static void testFormApi() {
-        File file = new File("D:/temp/fuck.jpg");
-        String md5 = MD5.md5Hex(file);
-
-        UpyunService upyunService = SpringContextHolder.getBean(UpyunService.class);
-        UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
-        env.setFileSuffix(".jpg");
-        env.setRootOrgId(String.valueOf(RandomUtils.nextLong()));
-        YunHttpRequest upYunSign = upyunService.buildUpYunHttpRequest("test", env, md5);
-        System.out.println("upYunSign: " + JsonUtil.toPrettyJson(upYunSign));
-
-        HttpPost httpPost = new HttpPost(upYunSign.getFormUrl());
-        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
-        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
-        for (Entry<String, String> formFilePart : upYunSign.getFormParams().entrySet()) {
-            builder.addPart(formFilePart.getKey(), new StringBody(formFilePart.getValue(),
-                    ContentType.create("text/plain", Consts.UTF_8)));
-        }
-        builder.addBinaryBody("file", file, ContentType.DEFAULT_BINARY, "fuck.jpg");
-        HttpEntity entity = builder.build();
-        httpPost.setEntity(entity);
-
-        CloseableHttpClient httpclient = HttpClients.createDefault();
-        CloseableHttpResponse resp = null;
-        try {
-            resp = httpclient.execute(httpPost);
-            StatusLine statusLine = resp.getStatusLine();
-            System.out.println(statusLine);
-            System.out.println(EntityUtils.toString(resp.getEntity(), "UTF-8"));
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            IOUtils.closeQuietly(resp);
-            IOUtils.closeQuietly(httpclient);
-        }
-    }
-
-}
+// package cn.com.qmth.examcloud.web.upyun;
+//
+// import cn.com.qmth.examcloud.commons.util.JsonUtil;
+// import cn.com.qmth.examcloud.commons.util.MD5;
+// import cn.com.qmth.examcloud.web.filestorage.YunHttpRequest;
+// import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+// import org.apache.commons.io.IOUtils;
+// import org.apache.commons.lang3.RandomUtils;
+// import org.apache.http.Consts;
+// import org.apache.http.HttpEntity;
+// import org.apache.http.StatusLine;
+// import org.apache.http.client.methods.CloseableHttpResponse;
+// import org.apache.http.client.methods.HttpPost;
+// import org.apache.http.entity.ContentType;
+// import org.apache.http.entity.mime.HttpMultipartMode;
+// import org.apache.http.entity.mime.MultipartEntityBuilder;
+// import org.apache.http.entity.mime.content.StringBody;
+// import org.apache.http.impl.client.CloseableHttpClient;
+// import org.apache.http.impl.client.HttpClients;
+// import org.apache.http.util.EntityUtils;
+//
+// import java.io.File;
+// import java.util.Map.Entry;
+//
+// public class UpyunTest {
+//
+//     public static void testFormApi() {
+//         File file = new File("D:/temp/fuck.jpg");
+//         String md5 = MD5.md5Hex(file);
+//
+//         UpyunService upyunService = SpringContextHolder.getBean(UpyunService.class);
+//         UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
+//         env.setFileSuffix(".jpg");
+//         env.setRootOrgId(String.valueOf(RandomUtils.nextLong()));
+//         YunHttpRequest upYunSign = upyunService.buildUpYunHttpRequest("test", env, md5);
+//         System.out.println("upYunSign: " + JsonUtil.toPrettyJson(upYunSign));
+//
+//         HttpPost httpPost = new HttpPost(upYunSign.getFormUrl());
+//         MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+//         builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+//         for (Entry<String, String> formFilePart : upYunSign.getFormParams().entrySet()) {
+//             builder.addPart(formFilePart.getKey(), new StringBody(formFilePart.getValue(),
+//                     ContentType.create("text/plain", Consts.UTF_8)));
+//         }
+//         builder.addBinaryBody("file", file, ContentType.DEFAULT_BINARY, "fuck.jpg");
+//         HttpEntity entity = builder.build();
+//         httpPost.setEntity(entity);
+//
+//         CloseableHttpClient httpclient = HttpClients.createDefault();
+//         CloseableHttpResponse resp = null;
+//         try {
+//             resp = httpclient.execute(httpPost);
+//             StatusLine statusLine = resp.getStatusLine();
+//             System.out.println(statusLine);
+//             System.out.println(EntityUtils.toString(resp.getEntity(), "UTF-8"));
+//         } catch (Exception e) {
+//             e.printStackTrace();
+//         } finally {
+//             IOUtils.closeQuietly(resp);
+//             IOUtils.closeQuietly(httpclient);
+//         }
+//     }
+//
+// }