WANG hace 6 años
padre
commit
d3c4f73c34

+ 15 - 12
examcloud-exchange-inner-service/src/main/java/cn/com/qmth/examcloud/exchange/inner/service/upyun/UpYunClient.java

@@ -1,8 +1,6 @@
 package cn.com.qmth.examcloud.exchange.inner.service.upyun;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
@@ -22,6 +20,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
 
+import com.UpYun;
 import com.upyun.UpException;
 import com.upyun.UpYunUtils;
 
@@ -52,6 +51,8 @@ public class UpYunClient {
 	 */
 	protected String password = null;
 
+	protected String md5Password = null;
+
 	public static final String API_DOMAIN = "v0.api.upyun.com";
 
 	private static final String MKDIR = "mkdir";
@@ -81,7 +82,8 @@ public class UpYunClient {
 
 		this.bucketName = bucketName;
 		this.userName = userName;
-		this.password = md5(password);
+		this.password = password;
+		this.md5Password = md5(password);
 	}
 
 	/**
@@ -93,15 +95,16 @@ public class UpYunClient {
 	 * @return
 	 */
 	public String writeFile(String filePath, File file) {
-		InputStream in = null;
+
+		UpYun upYun = new UpYun(bucketName, userName, password);
 		try {
-			in = new FileInputStream(file);
-			return writeFile(filePath, in);
-		} catch (IOException e) {
-			throw new ExamCloudRuntimeException(e);
-		} finally {
-			IOUtils.closeQuietly(in);
+			upYun.writeFile(filePath, file, true);
+		} catch (Exception e) {
+			throw new StatusException("EX-100001", "upyun upload failure");
 		}
+
+		String path = "	http://" + bucketName + ".b0.upaiyun.com" + filePath;
+		return path;
 	}
 
 	/**
@@ -123,8 +126,8 @@ public class UpYunClient {
 			String date = getGMTDate();
 			httpPut.addHeader(DATE, date);
 
-			httpPut.addHeader(AUTHORIZATION,
-					UpYunUtils.sign(METHOD_PUT, date, filePath, userName, password, null).trim());
+			httpPut.addHeader(AUTHORIZATION, UpYunUtils
+					.sign(METHOD_PUT, date, filePath, userName, this.md5Password, null).trim());
 
 			httpPut.addHeader(MKDIR, "true");
 

+ 2 - 2
examcloud-exchange-starter/src/main/resources/application-dev.properties

@@ -19,8 +19,8 @@ $facepp.apiSecret=bzMjy-JfwtVUxVDMzagFh7ggbQBC71f1
 
 $upyun.site.1.bucketName=exam-cloud-test
 $upyun.site.1.userName=examcloud
-$upyun.site.1.password=examcloud123456
+$upyun.site.1.password=ecs87863577!@#
 
 $upyun.site.2.bucketName=exam-cloud-test
 $upyun.site.2.userName=examcloud
-$upyun.site.2.password=examcloud123456
+$upyun.site.2.password=ecs87863577!@#

+ 1 - 1
examcloud-exchange-starter/src/main/resources/application-prod.properties

@@ -27,5 +27,5 @@ $upyun.site.1.password=ecs87863577!@#
 
 $upyun.site.2.bucketName=exam-cloud-test
 $upyun.site.2.userName=examcloud
-$upyun.site.2.password=examcloud123456
+$upyun.site.2.password=ecs87863577!@#
 

+ 2 - 2
examcloud-exchange-starter/src/main/resources/application-test.properties

@@ -19,8 +19,8 @@ $dir=/home/qmth/project/examcloud/examcloud-exchange/dir
 
 $upyun.site.1.bucketName=exam-cloud-test
 $upyun.site.1.userName=examcloud
-$upyun.site.1.password=examcloud123456
+$upyun.site.1.password=ecs87863577!@#
 
 $upyun.site.2.bucketName=exam-cloud-test
 $upyun.site.2.userName=examcloud
-$upyun.site.2.password=examcloud123456
+$upyun.site.2.password=ecs87863577!@#