View Source WeChat.Material (wechat v0.15.1)

素材管理

Summary

Types

文章

文章列表

素材的数量

素材的类型

媒体文件ID

Functions

新增其他类型永久素材 - 官方文档

新增其他类型永久素材(binary) - 官方文档

新增永久图文素材 - 官方文档

上传图文消息内的图片获取URL - 官方文档

上传图文消息内的图片获取URL(binary) - 官方文档

新增临时素材(文件路径) - 官方文档

上传图文消息素材 - 官方文档

获取批量推送类型为 mpvideo 时要求的 media_id - 官方文档

Types

@type article() :: WeChat.Material.Article.t()

文章

@type articles() :: [article()]

文章列表

@type material_count() :: 1..20

素材的数量

@type material_type() :: :image | :video | :voice | :news | :thumb | String.t()

素材的类型

  • image - 图片
  • video - 视频
  • voice - 语音
  • news - 图文
  • thumb - 缩略图

support type

  • String.t :: ["image", "video", "voice", "news"]
  • atom :: [:image, :video, :voice, :news]
@type media_id() :: String.t()

媒体文件ID

Functions

Link to this function

add_material(client, type, file_path)

View Source
@spec add_material(WeChat.client(), material_type(), file_path()) :: WeChat.response()

新增其他类型永久素材 - 官方文档

请注意:图片素材将进入公众平台官网素材管理模块中的默认分组。

Link to this function

add_material(client, type, filename, file_data)

View Source
@spec add_material(WeChat.client(), material_type(), filename(), file_data()) ::
  WeChat.response()

新增其他类型永久素材(binary) - 官方文档

请注意:图片素材将进入公众平台官网素材管理模块中的默认分组。

Link to this function

add_news(client, articles)

View Source
@spec add_news(WeChat.client(), articles()) :: WeChat.response()

新增永久图文素材 - 官方文档

对于常用的素材,开发者可通过本接口上传到微信服务器,永久使用。新增的永久素材也可以在公众平台官网素材管理模块中查询管理。

Link to this function

add_video_material(client, title, introduction, file_path)

View Source
@spec add_video_material(WeChat.client(), title(), introduction(), file_path()) ::
  WeChat.response()

新增其他类型永久素材 - 视频 - 官方文档

请注意:图片素材将进入公众平台官网素材管理模块中的默认分组。

Link to this function

add_video_material(client, title, introduction, filename, file_data)

View Source
@spec add_video_material(
  WeChat.client(),
  title(),
  introduction(),
  filename(),
  file_data()
) ::
  WeChat.response()

新增其他类型永久素材(binary) - 视频 - 官方文档

请注意:图片素材将进入公众平台官网素材管理模块中的默认分组。

Link to this function

batch_get_material(client, type, count \\ 10, offset \\ 0)

View Source
@spec batch_get_material(
  WeChat.client(),
  material_type(),
  material_count(),
  offset :: integer()
) ::
  WeChat.response()

获取素材列表 - 官方文档

在新增了永久素材后,开发者可以分类型获取永久素材的列表。

请注意:

  • 获取永久素材的列表,也包含公众号在公众平台官网素材管理模块中新建的图文消息、语音、视频等素材
  • 临时素材无法通过本接口获取
  • 调用该接口需https协议

参数说明

  • type: 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
  • offset: 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
  • count: 返回素材的数量,取值在1到20之间
Link to this function

del_material(client, media_id)

View Source
@spec del_material(WeChat.client(), media_id()) :: WeChat.response()

删除永久素材 - 官方文档

在新增了永久素材后,开发者可以根据本接口来删除不再需要的永久素材,节省空间。

请注意:

  • 请谨慎操作本接口,因为它可以删除公众号在公众平台官网素材管理模块中新建的图文消息、语音、视频等素材(但需要先通过获取素材列表来获知素材的media_id)
  • 临时素材无法通过本接口删除
  • 调用该接口需https协议
Link to this function

get_material(client, media_id)

View Source
@spec get_material(WeChat.client(), media_id()) :: WeChat.response()

获取永久素材 - 官方文档

在新增了永久素材后,开发者可以根据media_id通过本接口下载永久素材。公众号在公众平台官网素材管理模块中新建的永久素材, 可通过"获取素材列表"获知素材的media_id。

请注意:临时素材无法通过本接口获取

Link to this function

get_material_count(client)

View Source
@spec get_material_count(WeChat.client()) :: WeChat.response()

获取素材总数 - 官方文档

开发者可以根据本接口来获取永久素材的列表,需要时也可保存到本地。

请注意:

  • 永久素材的总数,也会计算公众平台官网素材管理中的素材
  • 图片和图文消息素材(包括单图文和多图文)的总数上限为100000,其他素材的总数上限为1000
  • 调用该接口需https协议
Link to this function

get_media(client, media_id)

View Source
@spec get_media(WeChat.client(), media_id()) :: WeChat.response()

获取临时素材 - 官方文档

公众号可以使用本接口获取临时素材(即下载临时的多媒体文件)。

Link to this function

stream_get_material(client, type, count \\ 20)

View Source
@spec stream_get_material(WeChat.client(), material_type(), material_count()) ::
  Enumerable.t()

获取素材列表(stream) - 官方文档

在新增了永久素材后,开发者可以分类型获取永久素材的列表。

请注意:

  • 获取永久素材的列表,也包含公众号在公众平台官网素材管理模块中新建的图文消息、语音、视频等素材
  • 临时素材无法通过本接口获取
  • 调用该接口需https协议

参数说明

  • type: 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
  • count: 返回素材的数量,取值在1到20之间
Link to this function

update_news(client, media_id, article, index \\ 0)

View Source
@spec update_news(WeChat.client(), media_id(), article(), index :: integer()) ::
  WeChat.response()

修改永久图文素材 - 官方文档

开发者可以通过本接口对永久图文素材进行修改。

请注意:

  • 也可以在公众平台官网素材管理模块中保存的图文消息(永久图文素材)
  • 调用该接口需https协议
Link to this function

upload_image(client, file_path)

View Source
@spec upload_image(WeChat.client(), file_path()) :: WeChat.response()

上传图文消息内的图片获取URL - 官方文档

本接口所上传的图片不占用公众号的素材库中图片数量的100000个的限制。图片仅支持jpg/png格式,大小必须在1MB以下。

Link to this function

upload_image(client, filename, file_data)

View Source
@spec upload_image(WeChat.client(), filename(), file_data()) :: WeChat.response()

上传图文消息内的图片获取URL(binary) - 官方文档

本接口所上传的图片不占用公众号的素材库中图片数量的100000个的限制。图片仅支持jpg/png格式,大小必须在1MB以下。

Link to this function

upload_media(client, type, file_path)

View Source
@spec upload_media(WeChat.client(), material_type(), file_path()) :: WeChat.response()

新增临时素材(文件路径) - 官方文档

公众号经常有需要用到一些临时性的多媒体素材的场景,例如在使用接口特别是发送消息时,对多媒体文件、多媒体消息的获取和调用等操作, 是通过media_id来进行的。素材管理接口对所有认证的订阅号和服务号开放。通过本接口,公众号可以新增临时素材(即上传临时多媒体文件)。

Link to this function

upload_media(client, type, filename, file_data)

View Source
@spec upload_media(WeChat.client(), material_type(), filename(), file_data()) ::
  WeChat.response()

新增临时素材(文件内容) - 官方文档

公众号经常有需要用到一些临时性的多媒体素材的场景,例如在使用接口特别是发送消息时,对多媒体文件、多媒体消息的获取和调用等操作, 是通过media_id来进行的。素材管理接口对所有认证的订阅号和服务号开放。通过本接口,公众号可以新增临时素材(即上传临时多媒体文件)。

Link to this function

upload_news(client, articles)

View Source
@spec upload_news(WeChat.client(), articles()) :: WeChat.response()

上传图文消息素材 - 官方文档

Link to this function

upload_video(client, media_id, title, description)

View Source
@spec upload_video(WeChat.client(), media_id(), title(), description()) ::
  WeChat.response()

获取批量推送类型为 mpvideo 时要求的 media_id - 官方文档

media_id 需通过 [素材管理] -> [新增素材] 来得到