Skip to content

企业号素材管理

borball edited this page Dec 28, 2016 · 5 revisions

企业号素材管理

###临时素材

上传

//image
InputStream inputStream;
String mediaId = Medias.defaultMedias().upload(MediaType.image, inputStream, "image.png");

//voice
InputStream inputStream;
String media = Medias.defaultMedias().upload(MediaType.voice, inputStream, "test.mp3");

//video
InputStream inputStream;
String media = Medias.defaultMedias().upload(MediaType.video, inputStream, "test.mp4");

//file
InputStream inputStream;
String media = Medias.defaultMedias().upload(MediaType.file, inputStream, "groups.csv");

或者:

//image
InputStream inputStream;
String mediaId = Medias.with(corpSetting).upload(MediaType.image, inputStream, "image.png");

//voice
InputStream inputStream;
String media = Medias.with(corpSetting).upload(MediaType.voice, inputStream, "test.mp3");

//video
InputStream inputStream;
String media = Medias.with(corpSetting).upload(MediaType.video, inputStream, "test.mp4");

//file
InputStream inputStream;
String media = Medias.with(corpSetting).upload(MediaType.file, inputStream, "groups.csv");

获取

String mediaId = "";
File file = Medias.defaultMedias().download(mediaId);

或者使用:

Medias.with(corpSetting).download(download);

###永久素材

上传

int agentId;
InputStream inputStream;
String mediaId = Materials.defaultMaterials().upload(agentId, MediaType.image, inputStream, "image.png");

int agentId;
InputStream inputStream;
String mediaId = Materials.defaultMaterials().upload(agentId, MediaType.voice, inputStream, "test.mp3");

int agentId;
InputStream inputStream;
String mediaId = Materials.defaultMaterials().upload(agentId, MediaType.video, inputStream, "test.mp4");

int agentId;
InputStream inputStream;
String mediaId = Materials.defaultMaterials().upload(agentId, MediaType.file, inputStream, "groups.csv");

MpNews mpNews = new MpNews();
...
int agentId;
String mediaId = Materials.defaultMaterials().addMpNews(agentId, mpNews);

获取

//普通素材
int agentId;
String mediaId;
File file = Materials.defaultMaterials().download(agentId, mediaId);

//图文素材
int agentId;
String mediaId;
MpNews mpNews = Materials.defaultMaterials().getMpNews(agentId, mediaId);

删除

//普通素材
int agentId;
String mediaId;
Materials.defaultMaterials().delete(agentId, mediaId);

//图文素材
int agentId;
String mediaId;
Materials.defaultMaterials().delete(agentId, mediaId);

修改永久图文素材

//图文素材
int agentId;
String mediaId;
MpNews mpNews;
Materials.defaultMaterials().updateMpNews(agentId, mediaId, mpNews);

获取素材总数

//图文素材
int agentId;
Counts counts = Materials.defaultMaterials().count(agentId);

获取素材列表

int agentId;
MaterialSearchResult result = Materials.defaultMaterials().list(agentId, MediaType.image, 0, 10);

微信官方:管理素材