forked from binarywang/WxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWxCpMediaService.java
136 lines (125 loc) · 4.98 KB
/
WxCpMediaService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* <pre>
* 媒体管理接口.
* Created by BinaryWang on 2017/6/24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpMediaService {
/**
* <pre>
* 上传多媒体文件.
* 上传的多媒体文件有格式和大小限制,如下:
* 图片(image): 1M,支持JPG格式
* 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
* 视频(video):10MB,支持MP4格式
* 缩略图(thumb):64KB,支持JPG格式
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
* </pre>
*
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param inputStream 输入流,需要调用方控制关闭该输入流
* @return the wx media upload result
* @throws WxErrorException the wx error exception
* @throws IOException the io exception
*/
WxMediaUploadResult upload(String mediaType, String fileType, InputStream inputStream)
throws WxErrorException, IOException;
/**
* <pre>
* 上传多媒体文件.
* </pre>
*
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param filename 文件名.例如:wework.txt
* @param url 远程链接
* @return wx media upload result
* @throws WxErrorException the wx error exception
* @throws IOException the io exception
*/
WxMediaUploadResult upload(String mediaType, String filename, String url)
throws WxErrorException, IOException;
/**
* <pre>
* 上传多媒体文件.
* </pre>
*
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param file 文件对象, 上传的文件内容
* @param filename 上传内容的实际文件名.例如:wework.txt
* @return wx media upload result
* @throws WxErrorException the wx error exception
*/
WxMediaUploadResult upload(String mediaType, File file, String filename) throws WxErrorException;
/**
* <pre>
* 上传多媒体文件.
* </pre>
*
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param inputStream 上传的文件内容
* @param filename 上传内容的实际文件名.例如:wework.txt
* @return wx media upload result
* @throws WxErrorException the wx error exception
*/
WxMediaUploadResult upload(String mediaType, InputStream inputStream, String filename) throws WxErrorException;
/**
* 上传多媒体文件.
*
* @param mediaType 媒体类型
* @param file 文件对象
* @return the wx media upload result
* @throws WxErrorException the wx error exception
* @see #upload(String, String, InputStream) #upload(String, String, InputStream)
*/
WxMediaUploadResult upload(String mediaType, File file) throws WxErrorException;
/**
* <pre>
* 下载多媒体文件.
* 根据微信文档,视频文件下载不了,会返回null
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
* </pre>
*
* @param mediaId 媒体id
* @return 保存到本地的临时文件 file
* @throws WxErrorException the wx error exception
*/
File download(String mediaId) throws WxErrorException;
/**
* <pre>
* 获取高清语音素材.
* 可以使用本接口获取从JSSDK的uploadVoice接口上传的临时语音素材,格式为speex,16K采样率。该音频比上文的临时素材获取接口(格式为amr,8K采样率)更加清晰,适合用作语音识别等对音质要求较高的业务。
* 请求方式:GET(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
* 仅企业微信2.4及以上版本支持。
* 文档地址:https://work.weixin.qq.com/api/doc#90000/90135/90255
* </pre>
*
* @param mediaId 媒体id
* @return 保存到本地的临时文件 jssdk file
* @throws WxErrorException the wx error exception
*/
File getJssdkFile(String mediaId) throws WxErrorException;
/**
* <pre>
* 上传图片.
* 上传图片得到图片URL,该URL永久有效
* 返回的图片URL,仅能用于图文消息(mpnews)正文中的图片展示;若用于非企业微信域名下的页面,图片将被屏蔽。
* 每个企业每天最多可上传100张图片
* 接口url格式:https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN
* </pre>
*
* @param file 上传的文件对象
* @return 返回图片url string
* @throws WxErrorException the wx error exception
*/
String uploadImg(File file) throws WxErrorException;
}