|
|
|
@ -4,12 +4,12 @@ import com.fr.design.DesignerEnvManager;
|
|
|
|
|
import com.fr.design.extra.PluginConstants; |
|
|
|
|
import com.fr.design.mainframe.alphafine.download.FineMarketDownloadManager; |
|
|
|
|
import com.fr.design.mainframe.alphafine.model.TemplateResource; |
|
|
|
|
import com.fr.ftp.util.Base64; |
|
|
|
|
import com.fr.general.CloudCenter; |
|
|
|
|
import com.fr.general.http.HttpToolbox; |
|
|
|
|
import com.fr.json.JSONArray; |
|
|
|
|
import com.fr.json.JSONObject; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.security.SecurityToolbox; |
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
import com.fr.third.org.apache.http.HttpEntity; |
|
|
|
|
import com.fr.third.org.apache.http.HttpException; |
|
|
|
@ -24,15 +24,10 @@ import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
|
import com.fr.third.org.apache.http.impl.client.HttpClients; |
|
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
|
|
|
|
|
import javax.crypto.Cipher; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
import java.security.KeyFactory; |
|
|
|
|
import java.security.interfaces.RSAPublicKey; |
|
|
|
|
import java.security.spec.X509EncodedKeySpec; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
@ -102,11 +97,15 @@ public class FineMarketClientHelper {
|
|
|
|
|
File destFile = createDestFile(destDir, resource); |
|
|
|
|
|
|
|
|
|
StableUtils.makesureFileExist(destFile); |
|
|
|
|
FileOutputStream writer = new FileOutputStream(destFile.getAbsolutePath()); |
|
|
|
|
|
|
|
|
|
InputStream content = null; |
|
|
|
|
FileOutputStream writer = null; |
|
|
|
|
try { |
|
|
|
|
writer = new FileOutputStream(destFile.getAbsolutePath()); |
|
|
|
|
|
|
|
|
|
HttpEntity entity = fileRes.getEntity(); |
|
|
|
|
long totalSize = entity.getContentLength(); |
|
|
|
|
InputStream content = entity.getContent(); |
|
|
|
|
content = entity.getContent(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] data = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
@ -119,9 +118,15 @@ public class FineMarketClientHelper {
|
|
|
|
|
totalBytesRead += bytesRead; |
|
|
|
|
process.process(totalBytesRead / (double) totalSize); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
} finally { |
|
|
|
|
content.close(); |
|
|
|
|
writer.flush(); |
|
|
|
|
writer.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().info("download resource{} success", resourceId); |
|
|
|
|
process.process(FineMarketDownloadManager.PROCESS_SUCCESS); |
|
|
|
|
|
|
|
|
@ -132,9 +137,9 @@ public class FineMarketClientHelper {
|
|
|
|
|
throw new HttpException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CloseableHttpResponse getFileResponse(TemplateResource resource, String resourceId) throws Exception { |
|
|
|
|
CloseableHttpResponse fileRes = postDownloadHttpResponse(getResourceDownloadUrl(resource), resourceId); |
|
|
|
|
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { |
|
|
|
@ -206,7 +211,7 @@ public class FineMarketClientHelper {
|
|
|
|
|
RequestBuilder builder = RequestBuilder.post() |
|
|
|
|
.setHeader("User-Agent", "Mozilla/5.0") |
|
|
|
|
.setUri(url) |
|
|
|
|
.addParameter("id", encrypt(id)) |
|
|
|
|
.addParameter("id", SecurityToolbox.encrypt(id, CERTIFICATE_PUBLIC_KEY)) |
|
|
|
|
.addParameter("userId", String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid())); |
|
|
|
|
|
|
|
|
|
if (params != null) { |
|
|
|
@ -318,15 +323,4 @@ public class FineMarketClientHelper {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String encrypt(String str) throws Exception { |
|
|
|
|
//base64编码的公钥
|
|
|
|
|
byte[] decoded = Base64.decodeBase64(CERTIFICATE_PUBLIC_KEY); |
|
|
|
|
RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); |
|
|
|
|
//RSA加密
|
|
|
|
|
Cipher cipher = Cipher.getInstance("RSA"); |
|
|
|
|
cipher.init(Cipher.ENCRYPT_MODE, pubKey); |
|
|
|
|
String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes(StandardCharsets.UTF_8))); |
|
|
|
|
return outStr; |
|
|
|
|
} |
|
|
|
|
} |