Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3a7b7f0a
authored
Dec 23, 2020
by
18356073052
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
上传企微临时素材
1 parent
e964d653
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMediaClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeMaterialServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMediaClient.java
View file @
3a7b7f0
...
@@ -6,6 +6,8 @@ import com.dtflys.forest.annotation.Query;
...
@@ -6,6 +6,8 @@ import com.dtflys.forest.annotation.Query;
import
com.linkwechat.wecom.domain.dto.WeMediaDto
;
import
com.linkwechat.wecom.domain.dto.WeMediaDto
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.InputStream
;
/**
/**
* 素材管理
* 素材管理
* @Author: Robin
* @Author: Robin
...
@@ -30,4 +32,14 @@ public interface WeMediaClient {
...
@@ -30,4 +32,14 @@ public interface WeMediaClient {
*/
*/
@Post
(
url
=
"/media/uploadimg"
)
@Post
(
url
=
"/media/uploadimg"
)
WeMediaDto
uploadimg
(
@DataFile
(
value
=
"file"
)
MultipartFile
multipartFile
);
WeMediaDto
uploadimg
(
@DataFile
(
value
=
"file"
)
MultipartFile
multipartFile
);
/**
* 上传临时素材
* Inputstream 对象
* 使用byte数组和Inputstream对象时一定要定义fileName属性
*/
@Post
(
url
=
"/media/upload"
)
WeMediaDto
upload
(
@DataFile
(
value
=
"file"
,
fileName
=
"${1}"
)
InputStream
in
,
String
filename
,
@Query
(
"type"
)
String
type
);
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeMaterialServiceImpl.java
View file @
3a7b7f0
...
@@ -155,10 +155,9 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
...
@@ -155,10 +155,9 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
URL
materialUrl
=
new
URL
(
url
);
URL
materialUrl
=
new
URL
(
url
);
conn
=
(
HttpURLConnection
)
materialUrl
.
openConnection
();
conn
=
(
HttpURLConnection
)
materialUrl
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestMethod
(
"GET"
);
conn
.
setConnectTimeout
(
20
*
1000
);
//
conn.setConnectTimeout(20 * 1000);
InputStream
inputStream
=
conn
.
getInputStream
();
InputStream
inputStream
=
conn
.
getInputStream
();
MultipartFile
multipartFile
=
new
MockMultipartFile
(
name
,
name
,
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
,
inputStream
);
return
weMediaClient
.
upload
(
inputStream
,
name
,
type
);
return
weMediaClient
.
upload
(
multipartFile
,
type
);
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
e
.
printStackTrace
();
e
.
printStackTrace
();
log
.
error
(
"上传临时文件失败......url:{},type:{},name:{},ex:{},st:{}"
,
url
,
type
,
name
,
e
.
getMessage
(),
e
.
getStackTrace
());
log
.
error
(
"上传临时文件失败......url:{},type:{},name:{},ex:{},st:{}"
,
url
,
type
,
name
,
e
.
getMessage
(),
e
.
getStackTrace
());
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment