Commit 5addc6ee by 程裕兵

feat:bind app id

parent 7f2eb0c8
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
......
...@@ -9,6 +9,7 @@ import com.jiejing.filecenter.api.authority.vo.SignatureVO; ...@@ -9,6 +9,7 @@ import com.jiejing.filecenter.api.authority.vo.SignatureVO;
import com.jiejing.filecenter.api.common.enums.AccessTypeEnum; import com.jiejing.filecenter.api.common.enums.AccessTypeEnum;
import com.jiejing.filecenter.api.common.util.UploadUtil; import com.jiejing.filecenter.api.common.util.UploadUtil;
import com.jiejing.filecenter.api.resource.ResourceApi; import com.jiejing.filecenter.api.resource.ResourceApi;
import com.jiejing.fitness.finance.service.utils.FileUtils;
import com.jiejing.paycenter.api.merchant.MerchantQueryApi; import com.jiejing.paycenter.api.merchant.MerchantQueryApi;
import com.jiejing.paycenter.api.merchant.request.GetApplyMerchantRequest; import com.jiejing.paycenter.api.merchant.request.GetApplyMerchantRequest;
import com.jiejing.paycenter.api.merchant.vo.MerchantApplyVO; import com.jiejing.paycenter.api.merchant.vo.MerchantApplyVO;
...@@ -17,6 +18,7 @@ import java.net.MalformedURLException; ...@@ -17,6 +18,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -51,11 +53,19 @@ public class TestController { ...@@ -51,11 +53,19 @@ public class TestController {
request.setBizCode("BRAND_INFO"); request.setBizCode("BRAND_INFO");
request.setTenantId(1L); request.setTenantId(1L);
request.setTenantType("BRAND"); request.setTenantType("BRAND");
request.setResourceName(IdWorker.getIdStr()); request.setResourceName(IdWorker.getIdStr() + getSuffix(url));
request.setResourceNameToMD5(false);
JsonResult<SignatureVO> result = authorityApi.getAuthoritySignatureForInner(request); JsonResult<SignatureVO> result = authorityApi.getAuthoritySignatureForInner(request);
UploadUtil.uploadFile(new URL(url).openStream(), request.getResourceName(), result.getResult(), 1000000); result.assertSuccess();
SignatureVO signatureVO = result.getResult();
UploadUtil.uploadFile(FileUtils.getInputStream(url), request.getResourceName(), signatureVO, 1000000);
return result; return result;
} }
private String getSuffix(String url) {
String[] split = url.split("\\?");
String fileName = StringUtils.substringAfterLast(split[0], "/");
String[] names = fileName.split("\\.");
return "." + names[names.length - 1];
}
} }
...@@ -177,6 +177,11 @@ ...@@ -177,6 +177,11 @@
<version>0.1.16-jiejing-SNAPSHOT</version> <version>0.1.16-jiejing-SNAPSHOT</version>
</dependency> </dependency>
<!-- logback aliyun end --> <!-- logback aliyun end -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
<!-- ======================= tools end ======================= --> <!-- ======================= tools end ======================= -->
<!-- ======================= test start ======================= --> <!-- ======================= test start ======================= -->
......
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
<groupId>com.jiejing.event</groupId> <groupId>com.jiejing.event</groupId>
<artifactId>scs-event</artifactId> <artifactId>scs-event</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
......
package com.jiejing.fitness.finance.service.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
/**
* @author chengyubing
* @since 2024/1/23 15:17
*/
public class FileUtils {
public static File downloadToMemory(String url) {
try {
InputStream in = getInputStream(url);
File tempFile = File.createTempFile(UUID.randomUUID().toString(), getSuffix(url));
tempFile.deleteOnExit();
try (FileOutputStream out = new FileOutputStream(tempFile)) {
IOUtils.copy(in, out);
}
return tempFile;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static String getSuffix(String url) {
String[] split = url.split("\\?");
String fileName = StringUtils.substringAfterLast(split[0], "/");
String[] names = fileName.split("\\.");
return "." + names[names.length - 1];
}
public static InputStream getInputStream(String url) {
int max = 5;
try {
HttpURLConnection connection = (HttpURLConnection) (new URL(url).openConnection());
// 设置不自动跟随重定向
connection.setInstanceFollowRedirects(false);
int count = 0;
int responseCode;
do {
if (count++ > max) {
throw new RuntimeException("资源链接过多的重定向");
}
responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP
|| responseCode == HttpURLConnection.HTTP_MOVED_PERM) {
// 获取重定向后的URL
String redirectedUrl = connection.getHeaderField("Location");
System.out.println("重定向到新地址:" + redirectedUrl);
connection = (HttpURLConnection) new URL(redirectedUrl).openConnection();
// 再次设置为不自动跟随重定向
connection.setInstanceFollowRedirects(false);
continue;
}
break;
} while (true);
return connection.getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment