Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xm-sportstest
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
xiamai-test
xm-sportstest
Commits
ebe485ab
Commit
ebe485ab
authored
Jul 03, 2024
by
yangfangfang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
B端订单
parent
ac17498b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
239 deletions
+0
-239
src/main/java/com/xiaomai/cases/polar/finance/revenueAndExpenditure/ResourceUtil.java
+0
-131
src/main/java/com/xiaomai/cases/polar/finance/revenueAndExpenditure/SignatureVO.java
+0
-104
src/main/java/com/xiaomai/cases/polar/finance/revenueAndExpenditure/TestUploadResources.java
+0
-4
No files found.
src/main/java/com/xiaomai/cases/polar/finance/revenueAndExpenditure/ResourceUtil.java
deleted
100644 → 0
View file @
ac17498b
package
com
.
xiaomai
.
cases
.
polar
.
finance
.
revenueAndExpenditure
;
import
org.apache.http.Consts
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.entity.mime.HttpMultipartMode
;
import
org.apache.http.entity.mime.MultipartEntityBuilder
;
import
org.apache.http.entity.mime.content.StringBody
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.log4j.Logger
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
/**
* @Author adu
* @Description 传文件留到阿里云oss
* @Date 13:13 2021-04-22
*/
public
class
ResourceUtil
{
public
static
final
Logger
logger
=
Logger
.
getLogger
(
ResourceUtil
.
class
);
public
static
final
String
OSS_ACCESS_KEY_ID
=
"OSSAccessKeyId"
;
public
static
final
String
POLICY
=
"policy"
;
public
static
final
String
SIGNATURE
=
"Signature"
;
public
static
final
String
KEY
=
"key"
;
public
static
final
String
SUCCESS_ACTION_STATUS
=
"success_action_status"
;
public
static
final
String
FILE
=
"file"
;
public
static
final
String
CALL_BACK
=
"callback"
;
public
static
final
String
RESPONSE_STATUS
=
"200"
;
public
static
final
String
CONTENT_TYPE
=
"multipart/form-data"
;
/**
* 上传文件留到阿里云oss
*
* @param inputStream 文件流
* @param fileName 文件名称
* @param signatureVO 临时访问阿里云授权签名
* @return true 上传成功,false 失败
* @throws IOException 关闭文件流或httpClient连接时可能会异常
*/
public
static
boolean
uploadFile
(
InputStream
inputStream
,
String
fileName
,
SignatureVO
signatureVO
,
int
timeout
)
throws
IOException
{
CloseableHttpClient
client
=
HttpClients
.
createDefault
();
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
//connectTimeout:指客户端和服务器建立连接的timeout,
.
setConnectTimeout
(
2000
)
//connectionRequestTimout:指从连接池获取连接的timeout
.
setConnectionRequestTimeout
(
2000
)
//socketTimeout:指客户端从服务器读取数据的timeout,超出后会抛出SocketTimeOutException,根据需要自定义
.
setSocketTimeout
(
timeout
)
.
build
();
HttpPost
post
=
new
HttpPost
(
signatureVO
.
getHost
());
post
.
setConfig
(
requestConfig
);
BufferedReader
br
=
null
;
try
{
// 参数顺序问题,该死的回调,千万要注意参数的顺序,死坑死坑
MultipartEntityBuilder
builder
=
MultipartEntityBuilder
.
create
();
builder
.
setMode
(
HttpMultipartMode
.
BROWSER_COMPATIBLE
);
StringBody
accessKeyId
=
new
StringBody
(
signatureVO
.
getAccessId
(),
ContentType
.
MULTIPART_FORM_DATA
);
builder
.
addPart
(
OSS_ACCESS_KEY_ID
,
accessKeyId
);
StringBody
policy
=
new
StringBody
(
signatureVO
.
getPolicy
(),
ContentType
.
MULTIPART_FORM_DATA
);
builder
.
addPart
(
POLICY
,
policy
);
StringBody
callBackStr
=
new
StringBody
(
signatureVO
.
getCallback
(),
ContentType
.
MULTIPART_FORM_DATA
);
builder
.
addPart
(
CALL_BACK
,
callBackStr
);
StringBody
signature
=
new
StringBody
(
signatureVO
.
getSignature
(),
ContentType
.
MULTIPART_FORM_DATA
);
builder
.
addPart
(
SIGNATURE
,
signature
);
// 兼容key中的中文名称
StringBody
key
=
new
StringBody
(
signatureVO
.
getKey
(),
ContentType
.
APPLICATION_JSON
);
builder
.
addPart
(
KEY
,
key
);
builder
.
addBinaryBody
(
FILE
,
inputStream
,
ContentType
.
create
(
CONTENT_TYPE
),
fileName
);
StringBody
successActionStatus
=
new
StringBody
(
RESPONSE_STATUS
,
ContentType
.
MULTIPART_FORM_DATA
);
builder
.
addPart
(
SUCCESS_ACTION_STATUS
,
successActionStatus
);
HttpEntity
entity
=
builder
.
build
();
post
.
setEntity
(
entity
);
//发送请求
HttpResponse
response
=
client
.
execute
(
post
);
int
status
=
response
.
getStatusLine
().
getStatusCode
();
if
(
Integer
.
valueOf
(
RESPONSE_STATUS
).
equals
(
status
))
{
return
true
;
}
else
{
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
inputStream
=
entity
.
getContent
();
br
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
Consts
.
UTF_8
));
StringBuilder
message
=
new
StringBuilder
();
String
body
;
while
((
body
=
br
.
readLine
())
!=
null
)
{
message
.
append
(
body
);
}
logger
.
error
(
"文件上传失败!message:{}"
+
message
);
}
return
true
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"文件上传异常!"
,
e
);
}
finally
{
if
(
br
!=
null
){
br
.
close
();
}
inputStream
.
close
();
client
.
close
();
}
return
false
;
}
}
src/main/java/com/xiaomai/cases/polar/finance/revenueAndExpenditure/SignatureVO.java
deleted
100644 → 0
View file @
ac17498b
/*
* Copyright © 2020 Hangzhou Jiejing Technology Co., Ltd. All rights reserved.
*
* The copyright of the company's program code belongs to Hangzhou Jiejing Technology Co., Ltd.
* No one can illegally copy it without the explicit permission of this website.
* Official website: www.xiaomai5.com
*
* Copyright © 2020 杭州杰竞科技有限公司 版权所有.
*
* 本公司程序代码的版权归杭州杰竞科技有限公司所有,未经本网站的明确许可,任何人不得非法复制。
* 官网: www.xiaomai5.com
*/
package
com
.
xiaomai
.
cases
.
polar
.
finance
.
revenueAndExpenditure
;
/**
* @author adu
* @date 2021-04-22
*/
public
class
SignatureVO
{
//资源ID
private
Long
resourceId
;
//接入ID
private
String
accessId
;
//访问策略
private
String
policy
;
//签名
private
String
signature
;
//对象路径
private
String
key
;
//接入点
private
String
host
;
//过期时间
private
String
expire
;
//回调地址
private
String
callback
;
public
Long
getResourceId
()
{
return
resourceId
;
}
public
void
setResourceId
(
Long
resourceId
)
{
this
.
resourceId
=
resourceId
;
}
public
String
getAccessId
()
{
return
accessId
;
}
public
void
setAccessId
(
String
accessId
)
{
this
.
accessId
=
accessId
;
}
public
String
getPolicy
()
{
return
policy
;
}
public
void
setPolicy
(
String
policy
)
{
this
.
policy
=
policy
;
}
public
String
getSignature
()
{
return
signature
;
}
public
void
setSignature
(
String
signature
)
{
this
.
signature
=
signature
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getHost
()
{
return
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
String
getExpire
()
{
return
expire
;
}
public
void
setExpire
(
String
expire
)
{
this
.
expire
=
expire
;
}
public
String
getCallback
()
{
return
callback
;
}
public
void
setCallback
(
String
callback
)
{
this
.
callback
=
callback
;
}
}
src/main/java/com/xiaomai/cases/polar/finance/revenueAndExpenditure/TestUploadResources.java
View file @
ebe485ab
...
...
@@ -123,10 +123,6 @@ public class TestUploadResources extends XMBaseTest {
JSONObject
listByVoucherIdResult
=
orderTools
.
listByVoucherId
(
getDetailId
);
id1
=
listByVoucherIdResult
.
getJSONArray
(
"result"
).
getJSONObject
(
0
).
getString
(
"id"
);
//收支的id
//上传资源
JSONObject
resourceResult
=
revenueAndExpenditureTools
.
mobileResource
(
"VOUCHER_INFO"
,
"BRAND"
,
"imgFile/test1.jpg"
);
String
resourceId
=
XMJSONPath
.
readPath
(
resourceResult
,
"$.result.resourceId"
);
//上传图片
JSONObject
jsonObject
=
new
JSONObject
();
...
...
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