补充永久素材相关方法到接口中,优化接口参数

This commit is contained in:
codepiano 2015-07-27 22:28:05 +08:00
parent 08338b0835
commit 49a4ab6a6e
3 changed files with 156 additions and 26 deletions

View File

@ -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

View File

@ -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));

View File

@ -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;
}