Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fit-finance
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fitness-server
fit-finance
Commits
5addc6ee
Commit
5addc6ee
authored
Feb 27, 2024
by
程裕兵
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:bind app id
parent
7f2eb0c8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
3 deletions
+102
-3
app/pom.xml
+4
-0
app/src/main/java/com/jiejing/fitness/finance/app/controller/TestController.java
+13
-3
pom.xml
+5
-0
service/pom.xml
+5
-0
service/src/main/java/com/jiejing/fitness/finance/service/utils/FileUtils.java
+75
-0
No files found.
app/pom.xml
View file @
5addc6ee
...
...
@@ -44,6 +44,10 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
...
...
app/src/main/java/com/jiejing/fitness/finance/app/controller/TestController.java
View file @
5addc6ee
...
...
@@ -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.util.UploadUtil
;
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.request.GetApplyMerchantRequest
;
import
com.jiejing.paycenter.api.merchant.vo.MerchantApplyVO
;
...
...
@@ -17,6 +18,7 @@ import java.net.MalformedURLException;
import
java.net.URL
;
import
javax.annotation.Resource
;
import
javax.validation.Valid
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
...
@@ -51,11 +53,19 @@ public class TestController {
request
.
setBizCode
(
"BRAND_INFO"
);
request
.
setTenantId
(
1L
);
request
.
setTenantType
(
"BRAND"
);
request
.
setResourceName
(
IdWorker
.
getIdStr
());
request
.
setResourceNameToMD5
(
false
);
request
.
setResourceName
(
IdWorker
.
getIdStr
()
+
getSuffix
(
url
));
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
;
}
private
String
getSuffix
(
String
url
)
{
String
[]
split
=
url
.
split
(
"\\?"
);
String
fileName
=
StringUtils
.
substringAfterLast
(
split
[
0
],
"/"
);
String
[]
names
=
fileName
.
split
(
"\\."
);
return
"."
+
names
[
names
.
length
-
1
];
}
}
pom.xml
View file @
5addc6ee
...
...
@@ -177,6 +177,11 @@
<version>
0.1.16-jiejing-SNAPSHOT
</version>
</dependency>
<!-- logback aliyun end -->
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
4.12.0
</version>
</dependency>
<!-- ======================= tools end ======================= -->
<!-- ======================= test start ======================= -->
...
...
service/pom.xml
View file @
5addc6ee
...
...
@@ -31,6 +31,11 @@
<groupId>
com.jiejing.event
</groupId>
<artifactId>
scs-event
</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
...
...
service/src/main/java/com/jiejing/fitness/finance/service/utils/FileUtils.java
0 → 100644
View file @
5addc6ee
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
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment