mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 22:11:40 +08:00
补充永久素材相关方法到接口中,优化接口参数
This commit is contained in:
parent
08338b0835
commit
49a4ab6a6e
@ -111,6 +111,135 @@ public interface WxMpService {
|
||||
*/
|
||||
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 上传非图文永久素材
|
||||
*
|
||||
* 上传的多媒体文件有格式和大小限制,如下:
|
||||
* 图片(image): 图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式
|
||||
* 语音(voice):语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式
|
||||
* 视频(video):在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON
|
||||
* 缩略图(thumb):文档未说明
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
|
||||
* </pre>
|
||||
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
|
||||
* @param material 上传的素材, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterial}
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 上传永久图文素材
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
|
||||
* </pre>
|
||||
* @param news 上传的图文消息, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialNews}
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 下载声音或者图片永久素材
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
|
||||
* </pre>
|
||||
* @param media_id 永久素材的id
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取视频永久素材的信息和下载地址
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
|
||||
* </pre>
|
||||
* @param media_id 永久素材的id
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取图文永久素材的信息
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
|
||||
* </pre>
|
||||
* @param media_id 永久素材的id
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 更新图文永久素材
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
|
||||
* </pre>
|
||||
* @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate}
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 删除永久素材
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/5/e66f61c303db51a6c0f90f46b15af5f5.html
|
||||
* </pre>
|
||||
* @param media_id 永久素材的id
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public boolean materialDelete(String media_id) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取各类素材总数
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/16/8cc64f8c189674b421bee3ed403993b8.html
|
||||
* </pre>
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public WxMpMaterialCountResult materialCount() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分页获取图文素材列表
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
|
||||
* </pre>
|
||||
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
|
||||
* @param count 返回素材的数量,取值在1到20之间
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分页获取其他媒体素材列表
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
|
||||
* </pre>
|
||||
* @param type 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
|
||||
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
|
||||
* @param count 返回素材的数量,取值在1到20之间
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* @see #mediaUpload(String, String, InputStream)
|
||||
* @param mediaType
|
||||
|
@ -8,6 +8,7 @@ import com.google.gson.internal.Streams;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.bean.WxMenu;
|
||||
@ -272,10 +273,10 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
}
|
||||
}
|
||||
|
||||
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(String type, int offset, int count) throws WxErrorException {
|
||||
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("type", type);
|
||||
params.put("type", WxConsts.MATERIAL_NEWS);
|
||||
params.put("offset", offset);
|
||||
params.put("count", count);
|
||||
String responseText = post(url, new Gson().toJson(params));
|
||||
|
@ -195,7 +195,7 @@ public class WxMpMaterialAPITest {
|
||||
|
||||
@Test(dependsOnMethods = {"testUpdateNewsInfo"})
|
||||
public void testMaterialNewsList() throws WxErrorException {
|
||||
WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(WxConsts.MATERIAL_NEWS, 0, 20);
|
||||
WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = wxService.materialNewsBatchGet(0, 20);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user