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 541ffb42
authored
Dec 23, 2020
by
18356073052
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
上传企微临时素材
1 parent
4fd9f143
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
6 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeMaterialController.java
linkwe-wecom/pom.xml
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeMaterialService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeMaterialServiceImpl.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/wecom/WeMaterialController.java
View file @
541ffb4
...
@@ -7,6 +7,7 @@ import com.linkwechat.common.core.page.TableDataInfo;
...
@@ -7,6 +7,7 @@ import com.linkwechat.common.core.page.TableDataInfo;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.common.enums.BusinessType
;
import
com.linkwechat.wecom.domain.WeMaterial
;
import
com.linkwechat.wecom.domain.WeMaterial
;
import
com.linkwechat.wecom.domain.dto.ResetCategoryDto
;
import
com.linkwechat.wecom.domain.dto.ResetCategoryDto
;
import
com.linkwechat.wecom.domain.dto.WeMediaDto
;
import
com.linkwechat.wecom.domain.vo.WeMaterialFileVO
;
import
com.linkwechat.wecom.domain.vo.WeMaterialFileVO
;
import
com.linkwechat.wecom.service.IWeMaterialService
;
import
com.linkwechat.wecom.service.IWeMaterialService
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -111,5 +112,13 @@ public class WeMaterialController extends BaseController {
...
@@ -111,5 +112,13 @@ public class WeMaterialController extends BaseController {
return
AjaxResult
.
success
();
return
AjaxResult
.
success
();
}
}
@PreAuthorize
(
"@ss.hasPermi('wechat:material:temporaryMaterialMediaId')"
)
@Log
(
title
=
"获取素材media_id"
,
businessType
=
BusinessType
.
OTHER
)
@PutMapping
(
"/temporaryMaterialMediaId"
)
@ApiOperation
(
"获取素材media_id"
)
public
AjaxResult
temporaryMaterialMediaId
(
@RequestParam
(
value
=
"url"
)
String
url
,
@RequestParam
(
value
=
"type"
)
String
type
,
@RequestParam
(
value
=
"name"
)
String
name
){
WeMediaDto
weMediaDto
=
materialService
.
uploadTemporaryMaterial
(
url
,
type
,
name
);
return
AjaxResult
.
success
(
weMediaDto
);
}
}
}
linkwe-wecom/pom.xml
View file @
541ffb4
...
@@ -22,6 +22,11 @@
...
@@ -22,6 +22,11 @@
<groupId>
com.linkwechat
</groupId>
<groupId>
com.linkwechat
</groupId>
<artifactId>
linkwe-common
</artifactId>
<artifactId>
linkwe-common
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
<version>
5.2.9.RELEASE
</version>
</dependency>
</dependencies>
</dependencies>
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWeMaterialService.java
View file @
541ffb4
...
@@ -92,4 +92,14 @@ public interface IWeMaterialService {
...
@@ -92,4 +92,14 @@ public interface IWeMaterialService {
*/
*/
public
WeMediaDto
uploadTemporaryMaterial
(
String
url
,
String
type
);
public
WeMediaDto
uploadTemporaryMaterial
(
String
url
,
String
type
);
/**
* 上传企微临时素材
* @param url 素材路径
* @param type 素材类型
* @param name 素材名称
* @return
*/
public
WeMediaDto
uploadTemporaryMaterial
(
String
url
,
String
type
,
String
name
);
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeMaterialServiceImpl.java
View file @
541ffb4
...
@@ -5,7 +5,7 @@ import cn.hutool.core.date.DateUtil;
...
@@ -5,7 +5,7 @@ import cn.hutool.core.date.DateUtil;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.config.ServerConfig
;
import
com.linkwechat.common.config.ServerConfig
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.enums.MediaType
;
//
import com.linkwechat.common.enums.MediaType;
import
com.linkwechat.common.exception.wecom.WeComException
;
import
com.linkwechat.common.exception.wecom.WeComException
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.common.utils.StringUtils
;
...
@@ -20,15 +20,19 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -20,15 +20,19 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.FileItemFactory
;
import
org.apache.commons.fileupload.FileItemFactory
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.http.entity.ContentType
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -61,7 +65,7 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
...
@@ -61,7 +65,7 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
// 上传文件路径
// 上传文件路径
String
filePath
=
RuoYiConfig
.
getUploadPath
();
String
filePath
=
RuoYiConfig
.
getUploadPath
();
String
fileName
=
""
;
String
fileName
=
""
;
if
(
MediaType
.
FILE
.
getType
().
equals
(
type
))
{
if
(
com
.
linkwechat
.
common
.
enums
.
MediaType
.
FILE
.
getType
().
equals
(
type
))
{
fileName
=
FileUploadUtils
.
uploadFile
(
file
);
fileName
=
FileUploadUtils
.
uploadFile
(
file
);
}
else
{
}
else
{
// 上传并返回新文件名称
// 上传并返回新文件名称
...
@@ -69,7 +73,7 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
...
@@ -69,7 +73,7 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
}
}
String
url
=
serverConfig
.
getUrl
()
+
fileName
;
String
url
=
serverConfig
.
getUrl
()
+
fileName
;
//上传临时素材
//上传临时素材
Optional
<
MediaType
>
mediaType
=
MediaType
.
of
(
type
);
Optional
<
com
.
linkwechat
.
common
.
enums
.
MediaType
>
mediaType
=
com
.
linkwechat
.
common
.
enums
.
MediaType
.
of
(
type
);
if
(!
mediaType
.
isPresent
())
{
if
(!
mediaType
.
isPresent
())
{
throw
new
WeComException
(
"媒体类型出错!"
);
throw
new
WeComException
(
"媒体类型出错!"
);
}
}
...
@@ -143,5 +147,23 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
...
@@ -143,5 +147,23 @@ public class WeMaterialServiceImpl implements IWeMaterialService {
}
}
@Override
public
WeMediaDto
uploadTemporaryMaterial
(
String
url
,
String
type
,
String
name
)
{
HttpURLConnection
conn
=
null
;
try
{
URL
materialUrl
=
new
URL
(
url
);
conn
=
(
HttpURLConnection
)
materialUrl
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setConnectTimeout
(
20
*
1000
);
InputStream
inputStream
=
conn
.
getInputStream
();
MultipartFile
multipartFile
=
new
MockMultipartFile
(
name
,
name
,
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
,
inputStream
);
return
weMediaClient
.
upload
(
multipartFile
,
type
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
log
.
error
(
"上传临时文件失败......url:{},type:{},name:{},ex:{},st:{}"
,
url
,
type
,
name
,
e
.
getMessage
(),
e
.
getStackTrace
());
}
return
null
;
}
}
}
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