material

package
v0.0.0-...-5652a87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

永久素材API.

Index

Constants

View Source
const (
	MaterialTypeImage = "image"
	MaterialTypeVoice = "voice"
	MaterialTypeVideo = "video"
	MaterialTypeThumb = "thumb"
	MaterialTypeNews  = "news"
)
View Source
const (
	NewsArticleCountLimit = 10 // 图文素材里文章的个数限制
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ThumbMediaId     string `json:"thumb_media_id"`               // 必须; 图文消息的封面图片素材id(必须是永久mediaID)
	Title            string `json:"title"`                        // 必须; 标题
	Author           string `json:"author,omitempty"`             // 必须; 作者
	Digest           string `json:"digest,omitempty"`             // 必须; 图文消息的摘要, 仅有单图文消息才有摘要, 多图文此处为空
	Content          string `json:"content"`                      // 必须; 图文消息的具体内容, 支持HTML标签, 必须少于2万字符, 小于1M, 且此处会去除JS
	ContentSourceURL string `json:"content_source_url,omitempty"` // 必须; 图文消息的原文地址, 即点击"阅读原文"后的URL
	ShowCoverPic     int    `json:"show_cover_pic"`               // 必须; 是否显示封面, 0为false, 即不显示, 1为true, 即显示
	URL              string `json:"url,omitempty"`                // !!!创建的时候不需要此参数!!! 图文页的URL, 文章创建成功以后, 会由微信自动生成
}

func (*Article) SetShowCoverPic

func (article *Article) SetShowCoverPic(b bool)

type BatchGetMaterialResult

type BatchGetMaterialResult struct {
	TotalCount int            `json:"total_count"` // 该类型的素材的总数
	ItemCount  int            `json:"item_count"`  // 本次调用获取的素材的数量
	Items      []MaterialInfo `json:"item"`        // 本次调用获取的素材列表
}

type BatchGetNewsResult

type BatchGetNewsResult struct {
	TotalCount int        `json:"total_count"` // 该类型的素材的总数
	ItemCount  int        `json:"item_count"`  // 本次调用获取的素材的数量
	Items      []NewsInfo `json:"item"`        // 本次调用获取的素材列表
}

type Client

type Client mp.Client

func NewClient

func NewClient(srv mp.AccessTokenServer, clt *http.Client) *Client

func (*Client) AddNews

func (clt *Client) AddNews(news News) (mediaId string, err error)

新增永久图文素材.

func (*Client) BatchGetMaterial

func (clt *Client) BatchGetMaterial(MaterialType string, offset, count int) (rslt *BatchGetMaterialResult, err error)

获取素材列表.

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

func (*Client) BatchGetNews

func (clt *Client) BatchGetNews(offset, count int) (rslt *BatchGetNewsResult, err error)

获取图文素材列表.

offset:       从全部素材的该偏移位置开始返回, 0表示从第一个素材 返回
count:        返回素材的数量, 取值在1到20之间

func (*Client) DeleteMaterial

func (clt *Client) DeleteMaterial(mediaId string) (err error)

删除永久素材.

func (*Client) DownloadMaterial

func (clt *Client) DownloadMaterial(mediaId, filepath string) (written int64, err error)

下载多媒体到文件.

对于视频素材, 先通过 Client.GetVideo 得到 VideoInfo, 然后通过 VideoInfo.DownURL 来下载

func (*Client) DownloadMaterialToWriter

func (clt *Client) DownloadMaterialToWriter(mediaId string, writer io.Writer) (written int64, err error)

下载多媒体到 io.Writer.

对于视频素材, 先通过 Client.GetVideo 得到 VideoInfo, 然后通过 VideoInfo.DownURL 来下载

func (*Client) GetMaterialCount

func (clt *Client) GetMaterialCount() (info *MaterialCountInfo, err error)

获取素材总数.

func (*Client) GetNews

func (clt *Client) GetNews(mediaId string) (news News, err error)

获取永久图文素材.

func (*Client) GetVideo

func (clt *Client) GetVideo(mediaId string) (info *VideoInfo, err error)

获取视频消息素材.

func (*Client) MaterialIterator

func (clt *Client) MaterialIterator(MaterialType string, offset, count int) (iter *MaterialIterator, err error)

func (*Client) NewsIterator

func (clt *Client) NewsIterator(offset, count int) (iter *NewsIterator, err error)

func (*Client) UpdateNews

func (clt *Client) UpdateNews(mediaId string, index int, article *Article) (err error)

修改永久图文素材.

func (*Client) UploadImage

func (clt *Client) UploadImage(filepath string) (mediaId, _url string, err error)

上传多媒体图片

func (*Client) UploadImageFromReader

func (clt *Client) UploadImageFromReader(filename string, reader io.Reader) (mediaId, _url string, err error)

上传多媒体图片

NOTE: 参数 filename 不是文件路径, 是指定 multipart/form-data 里面文件名称

func (*Client) UploadThumb

func (clt *Client) UploadThumb(filepath string) (mediaId, _url string, err error)

上传多媒体缩略图

func (*Client) UploadThumbFromReader

func (clt *Client) UploadThumbFromReader(filename string, reader io.Reader) (mediaId, _url string, err error)

上传多媒体缩略图

NOTE: 参数 filename 不是文件路径, 是指定 multipart/form-data 里面文件名称

func (*Client) UploadVideo

func (clt *Client) UploadVideo(_filepath string, title, introduction string) (mediaId string, err error)

上传多媒体视频

func (*Client) UploadVideoFromReader

func (clt *Client) UploadVideoFromReader(filename string, reader io.Reader, title, introduction string) (mediaId string, err error)

上传多媒体缩视频

NOTE: 参数 filename 不是文件路径, 是指定 multipart/form-data 里面文件名称

func (*Client) UploadVoice

func (clt *Client) UploadVoice(_filepath string) (mediaId string, err error)

上传多媒体语音

func (*Client) UploadVoiceFromReader

func (clt *Client) UploadVoiceFromReader(filename string, reader io.Reader) (mediaId string, err error)

上传多媒体语音

NOTE: 参数 filename 不是文件路径, 是指定 multipart/form-data 里面文件名称

type MaterialCountInfo

type MaterialCountInfo struct {
	VoiceCount int `json:"voice_count"`
	VideoCount int `json:"video_count"`
	ImageCount int `json:"image_count"`
	NewsCount  int `json:"news_count"`
}

公众号永久素材总数信息

type MaterialInfo

type MaterialInfo struct {
	MediaId    string `json:"media_id"`    // 素材id
	Name       string `json:"name"`        // 文件名称
	UpdateTime int64  `json:"update_time"` // 最后更新时间
	URL        string `json:"url"`         // 当获取的列表是图片素材列表时, 该字段是图片的URL
}

type MaterialIterator

type MaterialIterator struct {
	// contains filtered or unexported fields
}

MaterialIterator

iter, err := Client.MaterialIterator(MaterialTypeImage, 0, 10)
if err != nil {
    // TODO: 增加你的代码
}

for iter.HasNext() {
    items, err := iter.NextPage()
    if err != nil {
        // TODO: 增加你的代码
    }
    // TODO: 增加你的代码
}

func (*MaterialIterator) HasNext

func (iter *MaterialIterator) HasNext() bool

func (*MaterialIterator) NextPage

func (iter *MaterialIterator) NextPage() (items []MaterialInfo, err error)

func (*MaterialIterator) TotalCount

func (iter *MaterialIterator) TotalCount() int

type News

type News []Article

type NewsInfo

type NewsInfo struct {
	MediaId string `json:"media_id"` // 素材id
	Content struct {
		Articles []Article `json:"news_item,omitempty"`
	} `json:"content"`
	UpdateTime int64 `json:"update_time"` // 最后更新时间
}

type NewsIterator

type NewsIterator struct {
	// contains filtered or unexported fields
}

NewsIterator

iter, err := Client.NewsIterator(0, 10)
if err != nil {
    // TODO: 增加你的代码
}

for iter.HasNext() {
    items, err := iter.NextPage()
    if err != nil {
        // TODO: 增加你的代码
    }
    // TODO: 增加你的代码
}

func (*NewsIterator) HasNext

func (iter *NewsIterator) HasNext() bool

func (*NewsIterator) NextPage

func (iter *NewsIterator) NextPage() (items []NewsInfo, err error)

func (*NewsIterator) TotalCount

func (iter *NewsIterator) TotalCount() int

type VideoInfo

type VideoInfo struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	DownURL     string `json:"down_url"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL