weixin4j-[mp|qy]:媒体接口类(MediaApi)查询素材接口调整:去掉offset,count替换为Pageable类
This commit is contained in:
parent
d4da1096a8
commit
1a041e0ea4
@ -444,3 +444,5 @@
|
|||||||
* 2015-08-13
|
* 2015-08-13
|
||||||
|
|
||||||
+ `release`: weixin4j-[mp|qy] upgrade to 1.5.3,weixin4j-server upgrade to 1.0.5
|
+ `release`: weixin4j-[mp|qy] upgrade to 1.5.3,weixin4j-server upgrade to 1.0.5
|
||||||
|
|
||||||
|
+ **weixin4j-[mp|qy]**: 媒体接口类(MediaApi)查询素材接口调整:去掉offset,count替换为Pageable类
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class MediaRecord implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 媒体类型
|
* 媒体类型
|
||||||
*/
|
*/
|
||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false, deserialize = false)
|
||||||
private MediaType mediaType;
|
private MediaType mediaType;
|
||||||
/**
|
/**
|
||||||
* 媒体信息
|
* 媒体信息
|
||||||
@ -40,6 +40,12 @@ public class MediaRecord implements Serializable {
|
|||||||
@JSONField(name = "item")
|
@JSONField(name = "item")
|
||||||
private List<MediaItem> items;
|
private List<MediaItem> items;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页信息
|
||||||
|
*/
|
||||||
|
@JSONField(serialize = false, deserialize = false)
|
||||||
|
private Pageable pageable;
|
||||||
|
|
||||||
public int getTotalCount() {
|
public int getTotalCount() {
|
||||||
return totalCount;
|
return totalCount;
|
||||||
}
|
}
|
||||||
@ -72,10 +78,23 @@ public class MediaRecord implements Serializable {
|
|||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pageable getPageable() {
|
||||||
|
return pageable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageable(Pageable pageable) {
|
||||||
|
this.pageable = pageable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JSONField(serialize = false)
|
||||||
|
public Pagedata<MediaItem> getPagedata() {
|
||||||
|
return new Pagedata<MediaItem>(pageable, totalCount, items);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MediaRecord [totalCount=" + totalCount + ", itemCount="
|
return "MediaRecord [totalCount=" + totalCount + ", itemCount="
|
||||||
+ itemCount + ", mediaType=" + mediaType + ", items=" + items
|
+ itemCount + ", mediaType=" + mediaType + ", items=" + items
|
||||||
+ "]";
|
+ ", pageable=" + pageable + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,11 +5,12 @@ import java.io.Serializable;
|
|||||||
import com.foxinmy.weixin4j.model.Sort.Direction;
|
import com.foxinmy.weixin4j.model.Sort.Direction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 分页数据(页码从1开始
|
||||||
|
*
|
||||||
* @className Pageable
|
* @className Pageable
|
||||||
* @author jy
|
* @author jy
|
||||||
* @date 2014年12月27日
|
* @date 2014年12月27日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see com.foxinmy.weixin4j.model.springframework.data.domain.Pageable
|
|
||||||
*/
|
*/
|
||||||
public class Pageable implements Serializable {
|
public class Pageable implements Serializable {
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ public class Pageable implements Serializable {
|
|||||||
this.page = page;
|
this.page = page;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pageable(int page, int size, Direction direction,
|
public Pageable(int page, int size, Direction direction,
|
||||||
String... properties) {
|
String... properties) {
|
||||||
this(page, size, new Sort(direction, properties));
|
this(page, size, new Sort(direction, properties));
|
||||||
@ -49,6 +51,15 @@ public class Pageable implements Serializable {
|
|||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* page=1,size=20
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Pageable get() {
|
||||||
|
return new Pageable(1, 20);
|
||||||
|
}
|
||||||
|
|
||||||
public int getPageSize() {
|
public int getPageSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@ -56,12 +67,15 @@ public class Pageable implements Serializable {
|
|||||||
public int getPageNumber() {
|
public int getPageNumber() {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sort getSort() {
|
public Sort getSort() {
|
||||||
return sort;
|
return sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSort(Sort sort) {
|
public void setSort(Sort sort) {
|
||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
return (page - 1) * size;
|
return (page - 1) * size;
|
||||||
}
|
}
|
||||||
@ -82,6 +96,7 @@ public class Pageable implements Serializable {
|
|||||||
public Pageable first() {
|
public Pageable first() {
|
||||||
return new Pageable(0, getPageSize(), getSort());
|
return new Pageable(0, getPageSize(), getSort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Pageable [page=" + page + ", size=" + size + ", sort=" + sort
|
return "Pageable [page=" + page + ", size=" + size + ", sort=" + sort
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package com.foxinmy.weixin4j.tuple;
|
package com.foxinmy.weixin4j.tuple;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 聊天消息元件
|
* 企业号会话消息元件
|
||||||
*
|
*
|
||||||
* @className ChatTuple
|
* @className ChatTuple
|
||||||
* @author jy
|
* @author jy
|
||||||
|
|||||||
@ -58,15 +58,33 @@ public class MpArticle implements Serializable {
|
|||||||
@JSONField(name = "cover_url")
|
@JSONField(name = "cover_url")
|
||||||
private String coverUrl;
|
private String coverUrl;
|
||||||
|
|
||||||
@JSONCreator
|
public MpArticle(String thumbMediaId, String title, String content) {
|
||||||
public MpArticle(@JSONField(name = "thumb_media_id") String thumbMediaId,
|
|
||||||
@JSONField(name = "title") String title,
|
|
||||||
@JSONField(name = "content") String content) {
|
|
||||||
this.thumbMediaId = thumbMediaId;
|
this.thumbMediaId = thumbMediaId;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JSONCreator
|
||||||
|
public MpArticle(@JSONField(name = "thumbMediaId") String thumbMediaId,
|
||||||
|
@JSONField(name = "author") String author,
|
||||||
|
@JSONField(name = "title") String title,
|
||||||
|
@JSONField(name = "sourceUrl") String sourceUrl,
|
||||||
|
@JSONField(name = "content") String content,
|
||||||
|
@JSONField(name = "digest") String digest,
|
||||||
|
@JSONField(name = "showCoverPic") String showCoverPic,
|
||||||
|
@JSONField(name = "contentUrl") String contentUrl,
|
||||||
|
@JSONField(name = "coverUrl") String coverUrl) {
|
||||||
|
this.thumbMediaId = thumbMediaId;
|
||||||
|
this.author = author;
|
||||||
|
this.title = title;
|
||||||
|
this.sourceUrl = sourceUrl;
|
||||||
|
this.content = content;
|
||||||
|
this.digest = digest;
|
||||||
|
this.showCoverPic = showCoverPic;
|
||||||
|
this.contentUrl = contentUrl;
|
||||||
|
this.coverUrl = coverUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public String getThumbMediaId() {
|
public String getThumbMediaId() {
|
||||||
return thumbMediaId;
|
return thumbMediaId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -147,3 +147,5 @@
|
|||||||
* 2015-08-13
|
* 2015-08-13
|
||||||
|
|
||||||
+ version upgrade to 1.5.3
|
+ version upgrade to 1.5.3
|
||||||
|
|
||||||
|
+ 媒体接口类(MediaApi)查询素材接口调整:去掉offset,count替换为Pageable类
|
||||||
@ -14,6 +14,7 @@ import com.foxinmy.weixin4j.model.MediaDownloadResult;
|
|||||||
import com.foxinmy.weixin4j.model.MediaItem;
|
import com.foxinmy.weixin4j.model.MediaItem;
|
||||||
import com.foxinmy.weixin4j.model.MediaRecord;
|
import com.foxinmy.weixin4j.model.MediaRecord;
|
||||||
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||||
|
import com.foxinmy.weixin4j.model.Pageable;
|
||||||
import com.foxinmy.weixin4j.mp.api.CustomApi;
|
import com.foxinmy.weixin4j.mp.api.CustomApi;
|
||||||
import com.foxinmy.weixin4j.mp.api.DataApi;
|
import com.foxinmy.weixin4j.mp.api.DataApi;
|
||||||
import com.foxinmy.weixin4j.mp.api.GroupApi;
|
import com.foxinmy.weixin4j.mp.api.GroupApi;
|
||||||
@ -352,22 +353,23 @@ public class WeixinProxy {
|
|||||||
*
|
*
|
||||||
* @param mediaType
|
* @param mediaType
|
||||||
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
|
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
|
||||||
* @param offset
|
* @param pageable
|
||||||
* 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
|
* 分页数据
|
||||||
* @param count
|
|
||||||
* 返回素材的数量,取值在1到20之间
|
|
||||||
* @return 媒体素材的记录对象
|
* @return 媒体素材的记录对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
* @see com.foxinmy.weixin4j.mp.api.MediaApi
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MediaRecord
|
* @see com.foxinmy.weixin4j.mp.model.MediaRecord
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
* @see com.foxinmy.weixin4j.mp.model.MediaItem
|
* @see com.foxinmy.weixin4j.mp.model.MediaItem
|
||||||
|
* @see com.foxinmy.weixin4j.model.MediaItem
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pageable
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pagedata
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html">获取素材列表</a>
|
* href="http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html">获取素材列表</a>
|
||||||
*/
|
*/
|
||||||
public MediaRecord listMaterialMedia(MediaType mediaType, int offset,
|
public MediaRecord listMaterialMedia(MediaType mediaType, Pageable pageable)
|
||||||
int count) throws WeixinException {
|
throws WeixinException {
|
||||||
return mediaApi.listMaterialMedia(mediaType, offset, count);
|
return mediaApi.listMaterialMedia(mediaType, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import com.foxinmy.weixin4j.model.MediaDownloadResult;
|
|||||||
import com.foxinmy.weixin4j.model.MediaItem;
|
import com.foxinmy.weixin4j.model.MediaItem;
|
||||||
import com.foxinmy.weixin4j.model.MediaRecord;
|
import com.foxinmy.weixin4j.model.MediaRecord;
|
||||||
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||||
|
import com.foxinmy.weixin4j.model.Pageable;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||||
@ -513,26 +514,26 @@ public class MediaApi extends MpApi {
|
|||||||
*
|
*
|
||||||
* @param mediaType
|
* @param mediaType
|
||||||
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
|
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
|
||||||
* @param offset
|
* @param pageable
|
||||||
* 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
|
* 分页数据
|
||||||
* @param count
|
|
||||||
* 返回素材的数量,取值在1到20之间
|
|
||||||
* @return 媒体素材的记录对象
|
* @return 媒体素材的记录对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.model.MediaRecord
|
* @see com.foxinmy.weixin4j.model.MediaRecord
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
* @see com.foxinmy.weixin4j.model.MediaItem
|
* @see com.foxinmy.weixin4j.model.MediaItem
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pageable
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pagedata
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html">获取素材列表</a>
|
* href="http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html">获取素材列表</a>
|
||||||
*/
|
*/
|
||||||
public MediaRecord listMaterialMedia(MediaType mediaType, int offset,
|
public MediaRecord listMaterialMedia(MediaType mediaType, Pageable pageable)
|
||||||
int count) throws WeixinException {
|
throws WeixinException {
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
String material_media_list_uri = getRequestUri("material_media_list_uri");
|
String material_media_list_uri = getRequestUri("material_media_list_uri");
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("type", mediaType.name());
|
obj.put("type", mediaType.name());
|
||||||
obj.put("offset", offset);
|
obj.put("offset", pageable.getOffset());
|
||||||
obj.put("count", count);
|
obj.put("count", pageable.getPageSize());
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(material_media_list_uri, token.getAccessToken()),
|
String.format(material_media_list_uri, token.getAccessToken()),
|
||||||
obj.toJSONString());
|
obj.toJSONString());
|
||||||
@ -557,6 +558,7 @@ public class MediaApi extends MpApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
mediaRecord.setMediaType(mediaType);
|
mediaRecord.setMediaType(mediaType);
|
||||||
|
mediaRecord.setPageable(pageable);
|
||||||
return mediaRecord;
|
return mediaRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,17 +573,16 @@ public class MediaApi extends MpApi {
|
|||||||
*/
|
*/
|
||||||
public List<MediaItem> listAllMaterialMedia(MediaType mediaType)
|
public List<MediaItem> listAllMaterialMedia(MediaType mediaType)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
int offset = 0;
|
Pageable pageable = new Pageable(1, 20);
|
||||||
int count = 20;
|
|
||||||
List<MediaItem> mediaList = new ArrayList<MediaItem>();
|
List<MediaItem> mediaList = new ArrayList<MediaItem>();
|
||||||
MediaRecord mediaRecord = null;
|
MediaRecord mediaRecord = null;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mediaRecord = listMaterialMedia(mediaType, offset, count);
|
mediaRecord = listMaterialMedia(mediaType, pageable);
|
||||||
mediaList.addAll(mediaRecord.getItems());
|
mediaList.addAll(mediaRecord.getItems());
|
||||||
if (offset >= mediaRecord.getTotalCount()) {
|
if (pageable.getOffset() >= mediaRecord.getTotalCount()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
offset += count;
|
pageable = pageable.next();
|
||||||
}
|
}
|
||||||
return mediaList;
|
return mediaList;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import com.foxinmy.weixin4j.model.MediaDownloadResult;
|
|||||||
import com.foxinmy.weixin4j.model.MediaItem;
|
import com.foxinmy.weixin4j.model.MediaItem;
|
||||||
import com.foxinmy.weixin4j.model.MediaRecord;
|
import com.foxinmy.weixin4j.model.MediaRecord;
|
||||||
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||||
|
import com.foxinmy.weixin4j.model.Pageable;
|
||||||
import com.foxinmy.weixin4j.mp.api.MediaApi;
|
import com.foxinmy.weixin4j.mp.api.MediaApi;
|
||||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||||
import com.foxinmy.weixin4j.tuple.MpVideo;
|
import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||||
@ -130,8 +131,9 @@ public class MediaTest extends TokenTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listMaterialMedia() throws WeixinException {
|
public void listMaterialMedia() throws WeixinException {
|
||||||
MediaRecord mediaRecord = mediaApi.listMaterialMedia(MediaType.news, 0,
|
Pageable pageable = Pageable.get();
|
||||||
20);
|
MediaRecord mediaRecord = mediaApi.listMaterialMedia(MediaType.news,
|
||||||
|
pageable);
|
||||||
System.err.println(mediaRecord);
|
System.err.println(mediaRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -103,3 +103,5 @@
|
|||||||
* 2015-08-13
|
* 2015-08-13
|
||||||
|
|
||||||
+ version upgrade to 1.5.3
|
+ version upgrade to 1.5.3
|
||||||
|
|
||||||
|
+ 媒体接口类(MediaApi)查询素材接口调整:去掉offset,count替换为Pageable类
|
||||||
@ -13,6 +13,7 @@ import com.foxinmy.weixin4j.model.MediaDownloadResult;
|
|||||||
import com.foxinmy.weixin4j.model.MediaItem;
|
import com.foxinmy.weixin4j.model.MediaItem;
|
||||||
import com.foxinmy.weixin4j.model.MediaRecord;
|
import com.foxinmy.weixin4j.model.MediaRecord;
|
||||||
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||||
|
import com.foxinmy.weixin4j.model.Pageable;
|
||||||
import com.foxinmy.weixin4j.qy.api.AgentApi;
|
import com.foxinmy.weixin4j.qy.api.AgentApi;
|
||||||
import com.foxinmy.weixin4j.qy.api.BatchApi;
|
import com.foxinmy.weixin4j.qy.api.BatchApi;
|
||||||
import com.foxinmy.weixin4j.qy.api.ChatApi;
|
import com.foxinmy.weixin4j.qy.api.ChatApi;
|
||||||
@ -383,22 +384,22 @@ public class WeixinProxy {
|
|||||||
* 企业应用ID
|
* 企业应用ID
|
||||||
* @param mediaType
|
* @param mediaType
|
||||||
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)、文件(file)
|
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)、文件(file)
|
||||||
* @param offset
|
* @param pageable
|
||||||
* 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
|
* 分页数据
|
||||||
* @param count
|
|
||||||
* 返回素材的数量,取值在1到20之间
|
|
||||||
* @return 媒体素材的记录对象
|
* @return 媒体素材的记录对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.qy.api.MediaApi
|
* @see com.foxinmy.weixin4j.qy.api.MediaApi
|
||||||
* @see com.foxinmy.weixin4j.model.MediaRecord
|
* @see com.foxinmy.weixin4j.model.MediaRecord
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
* @see com.foxinmy.weixin4j.model.MediaItem
|
* @see com.foxinmy.weixin4j.model.MediaItem
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pageable
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pagedata
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">获取素材列表</a>
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">获取素材列表</a>
|
||||||
*/
|
*/
|
||||||
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
|
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
|
||||||
int offset, int count) throws WeixinException {
|
Pageable pageable) throws WeixinException {
|
||||||
return mediaApi.listMaterialMedia(agentid, mediaType, offset, count);
|
return mediaApi.listMaterialMedia(agentid, mediaType, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import com.foxinmy.weixin4j.model.MediaDownloadResult;
|
|||||||
import com.foxinmy.weixin4j.model.MediaItem;
|
import com.foxinmy.weixin4j.model.MediaItem;
|
||||||
import com.foxinmy.weixin4j.model.MediaRecord;
|
import com.foxinmy.weixin4j.model.MediaRecord;
|
||||||
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||||
|
import com.foxinmy.weixin4j.model.Pageable;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
import com.foxinmy.weixin4j.qy.model.Callback;
|
import com.foxinmy.weixin4j.qy.model.Callback;
|
||||||
import com.foxinmy.weixin4j.qy.model.Party;
|
import com.foxinmy.weixin4j.qy.model.Party;
|
||||||
@ -410,28 +411,28 @@ public class MediaApi extends QyApi {
|
|||||||
* 企业应用ID
|
* 企业应用ID
|
||||||
* @param mediaType
|
* @param mediaType
|
||||||
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)、文件(file)
|
* 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)、文件(file)
|
||||||
* @param offset
|
* @param pageable
|
||||||
* 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
|
* 分页数据
|
||||||
* @param count
|
|
||||||
* 返回素材的数量,取值在1到20之间
|
|
||||||
* @return 媒体素材的记录对象
|
* @return 媒体素材的记录对象
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @see com.foxinmy.weixin4j.model.MediaRecord
|
* @see com.foxinmy.weixin4j.model.MediaRecord
|
||||||
* @see com.foxinmy.weixin4j.type.MediaType
|
* @see com.foxinmy.weixin4j.type.MediaType
|
||||||
* @see com.foxinmy.weixin4j.model.MediaItem
|
* @see com.foxinmy.weixin4j.model.MediaItem
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pageable
|
||||||
|
* @see com.foxinmy.weixin4j.model.Pagedata
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">获取素材列表</a>
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">获取素材列表</a>
|
||||||
*/
|
*/
|
||||||
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
|
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
|
||||||
int offset, int count) throws WeixinException {
|
Pageable pageable) throws WeixinException {
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
String material_media_list_uri = getRequestUri("material_media_list_uri");
|
String material_media_list_uri = getRequestUri("material_media_list_uri");
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("agentid", agentid);
|
obj.put("agentid", agentid);
|
||||||
obj.put("type",
|
obj.put("type",
|
||||||
mediaType == MediaType.news ? "mpnews" : mediaType.name());
|
mediaType == MediaType.news ? "mpnews" : mediaType.name());
|
||||||
obj.put("offset", offset);
|
obj.put("offset", pageable.getOffset());
|
||||||
obj.put("count", count);
|
obj.put("count", pageable.getPageSize());
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(material_media_list_uri, token.getAccessToken()),
|
String.format(material_media_list_uri, token.getAccessToken()),
|
||||||
obj.toJSONString());
|
obj.toJSONString());
|
||||||
@ -443,6 +444,7 @@ public class MediaApi extends QyApi {
|
|||||||
MediaItem.class));
|
MediaItem.class));
|
||||||
}
|
}
|
||||||
mediaRecord.setMediaType(mediaType);
|
mediaRecord.setMediaType(mediaType);
|
||||||
|
mediaRecord.setPageable(pageable);
|
||||||
return mediaRecord;
|
return mediaRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,17 +461,16 @@ public class MediaApi extends QyApi {
|
|||||||
*/
|
*/
|
||||||
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType)
|
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
int offset = 0;
|
Pageable pageable = new Pageable(1, 20);
|
||||||
int count = 20;
|
|
||||||
List<MediaItem> mediaList = new ArrayList<MediaItem>();
|
List<MediaItem> mediaList = new ArrayList<MediaItem>();
|
||||||
MediaRecord mediaRecord = null;
|
MediaRecord mediaRecord = null;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mediaRecord = listMaterialMedia(agentid, mediaType, offset, count);
|
mediaRecord = listMaterialMedia(agentid, mediaType, pageable);
|
||||||
mediaList.addAll(mediaRecord.getItems());
|
mediaList.addAll(mediaRecord.getItems());
|
||||||
if (offset >= mediaRecord.getTotalCount()) {
|
if (pageable.getOffset() >= mediaRecord.getTotalCount()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
offset += count;
|
pageable = pageable.next();
|
||||||
}
|
}
|
||||||
return mediaList;
|
return mediaList;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user