|
@@ -11,6 +11,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.Base64;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Locale;
|
|
|
+import java.util.Map;
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
import javax.crypto.Mac;
|
|
@@ -29,6 +30,8 @@ import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
@@ -105,6 +108,36 @@ public class UpYunClient {
|
|
|
this.md5Password = MD5.encrypt32(password);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建又拍云签名
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param filePath
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public UpYunSign buildUpYunSign(String filePath) {
|
|
|
+ String path = formatPath(filePath);
|
|
|
+ String url = "https://" + API_DOMAIN + path;
|
|
|
+
|
|
|
+ Map<String, String> headers = Maps.newHashMap();
|
|
|
+ String date = getDate();
|
|
|
+ String authorization = null;
|
|
|
+ try {
|
|
|
+ authorization = sign(userName, md5Password, METHOD_PUT, path, date, "", "");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("100005", "[upyun]. fail to build sign", e);
|
|
|
+ }
|
|
|
+ headers.put(AUTHORIZATION, authorization);
|
|
|
+ headers.put(DATE, date);
|
|
|
+ headers.put(MKDIR, "true");
|
|
|
+
|
|
|
+ UpYunSign sign = new UpYunSign();
|
|
|
+ sign.setUrl(url);
|
|
|
+ sign.setHeaders(headers);
|
|
|
+
|
|
|
+ return sign;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 上传文件
|
|
|
*
|