media

package
v0.0.0-...-f32fcc8 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddBriefMediaUrl      = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
	DownloadBriefMediaUrl = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s"
	DownloadHQVoiceUrl    = "https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=%s&media_id=%s"
)

临时素材媒体文件在微信后台保存时间为3天,即3天后media_id失效。

View Source
const (
	AddNewsMediaUrl        = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=%s"
	AddFeverMediaUrl       = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=%s&type=%s"
	AddNewsImageUrl        = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s"
	DownloadFerverMediaUrl = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=%s"
	DeleteForeverMediaUrl  = "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=%s"
	UpdateNewsMediaUrl     = "https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=%s"
	GetForeverMediaNumUrl  = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s"
	GetForeverMediaListUrl = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=%s"
)

永久图片素材新增后,将带有URL返回给开发者,开发者可以在腾讯系域名内使用(腾讯系域名外使用,图片将被屏蔽)。 公众号的素材库保存总数量有上限:图文消息素材、图片素材上限为5000,其他类型为1000。 图文消息的具体内容中,微信后台将过滤外部的图片链接,图片url需通过"上传图文消息内的图片获取URL"接口上传图片获取。 上传图文消息内的图片获取URL接口所上传的图片,不占用公众号的素材库中图片数量的5000个的限制,图片仅支持jpg/png格式,大小必须在1MB以下。 图文消息支持正文中插入自己帐号和其他公众号已群发文章链接的能力。

View Source
const (
	MediaTypeOfVideo MediaType = "video" //视频(video):10MB,支持MP4格式
	MediaTypeOfNews            = "news"  //图文素材
	MediaTypeOfImage           = "image" //图片(image): 2M,支持PNG\JPEG\JPG\GIF格式
	MediaTypeOfVoice           = "voice" //语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
	MediaTypeOfThumb           = "thumb" //缩略图素材 64KB,支持JPG格式
)
View Source
const (
	UploadBroadcastVideoUrl = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token=%s"
)

Variables

This section is empty.

Functions

func UploadBroadcastVideo

func UploadBroadcastVideo(accessToken, mediaID, title, description string) (string, error)

此处media_id需通过素材管理->新增素材来得到,然后请求接口获取可以广播的视频mediaID

Types

type BriefMedia

type BriefMedia struct {
	AccessToken string
}

func NewBriefMedia

func NewBriefMedia(accessToken string) *BriefMedia

func (*BriefMedia) DownloadHQVoice

func (bm *BriefMedia) DownloadHQVoice(mediaID, savePath string) (string, error)

获取从JSSDK的uploadVoice接口上传的临时语音素材,格式为speex,16K采样率。 该音频比上文的临时素材获取接口(格式为amr,8K采样率)更加清晰, 适合用作语音识别等对音质要求较高的业务。

func (*BriefMedia) DownloadMedia

func (bm *BriefMedia) DownloadMedia(mediaID, savePath string) (string, error)

下载临时素材接口上传的多媒体文件,只能下载除视频外的文件

func (*BriefMedia) DownloadVideoMedia

func (bm *BriefMedia) DownloadVideoMedia(mediaID, savePath string) (string, error)

视频文件不支持https下载,调用该接口需http协议。

func (*BriefMedia) UploadImageByUrl

func (bm *BriefMedia) UploadImageByUrl(imgUrl string) (*BriefMeidaInfo, error)

func (*BriefMedia) UploadImageFile

func (bm *BriefMedia) UploadImageFile(file string) (*BriefMeidaInfo, error)

func (*BriefMedia) UploadMediaFile

func (bm *BriefMedia) UploadMediaFile(filePath string, fileType MediaType) (*BriefMeidaInfo, error)

func (*BriefMedia) UploadThumbByUrl

func (bm *BriefMedia) UploadThumbByUrl(thumbUrl string) (*BriefMeidaInfo, error)

func (*BriefMedia) UploadThumbFile

func (bm *BriefMedia) UploadThumbFile(file string) (*BriefMeidaInfo, error)

func (*BriefMedia) UploadVideoFile

func (bm *BriefMedia) UploadVideoFile(file string) (*BriefMeidaInfo, error)

func (*BriefMedia) UploadVoiceFile

func (bm *BriefMedia) UploadVoiceFile(file string) (*BriefMeidaInfo, error)

type BriefMeidaInfo

type BriefMeidaInfo struct {
	MediaID     string    `json:"media_id"`   //媒体文件上传后,获取标识
	Type        MediaType `json:"type"`       //媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb,主要用于视频与音乐格式的缩略图)
	CreatedTime int64     `json:"created_at"` //媒体文件上传时间戳
}

临时素材media_id是可复用的。

type ForeverMedia

type ForeverMedia struct {
	AccessToken string
}

func NewForeverMedia

func NewForeverMedia(accessToken string) *ForeverMedia

func (*ForeverMedia) AddNews

func (fm *ForeverMedia) AddNews(items ...*NewsItem) (string, error)

func (*ForeverMedia) DeleteMedia

func (fm *ForeverMedia) DeleteMedia(mediaID string) error

删除永久素材

func (*ForeverMedia) DownloadMedia

func (fm *ForeverMedia) DownloadMedia(mediaID, savePath string) (string, error)

下载临时素材接口上传的多媒体文件,只能下载除视频外的文件

func (*ForeverMedia) DownloadVideoMedia

func (fm *ForeverMedia) DownloadVideoMedia(mediaID, savePath string) (string, error)

视频文件不支持https下载,调用该接口需http协议。

func (*ForeverMedia) GetForeverMediaNum

func (fm *ForeverMedia) GetForeverMediaNum() (*ForeverMediaNum, error)

func (*ForeverMedia) GetImageList

func (fm *ForeverMedia) GetImageList(offset, count int) (*MediaList, error)

func (*ForeverMedia) GetMediaList

func (fm *ForeverMedia) GetMediaList(mediaType MediaType, offset, count int) (*MediaList, error)

func (*ForeverMedia) GetNewsMediaList

func (fm *ForeverMedia) GetNewsMediaList(offset, count int) (*NewsMediaList, error)

获取图文素材列表

func (*ForeverMedia) GetVideoList

func (fm *ForeverMedia) GetVideoList(offset, count int) (*MediaList, error)

func (*ForeverMedia) GetVoiceList

func (fm *ForeverMedia) GetVoiceList(offset, count int) (*MediaList, error)

func (*ForeverMedia) UpdateNewsItem

func (fm *ForeverMedia) UpdateNewsItem(mediaID string, index int, newsItem *NewsItem) error

func (*ForeverMedia) UploadImageByUrl

func (fm *ForeverMedia) UploadImageByUrl(imgUrl string) (*ForeverMeidaInfo, error)

func (*ForeverMedia) UploadImageFile

func (fm *ForeverMedia) UploadImageFile(file string) (*ForeverMeidaInfo, error)

func (*ForeverMedia) UploadMediaFile

func (fm *ForeverMedia) UploadMediaFile(filePath string, fileType MediaType) (*ForeverMeidaInfo, error)

func (*ForeverMedia) UploadNewsImageByUrl

func (fm *ForeverMedia) UploadNewsImageByUrl(imgUrl string) (string, error)

func (*ForeverMedia) UploadNewsImageFile

func (fm *ForeverMedia) UploadNewsImageFile(imgFile string) (string, error)

"上传图文消息内的图片获取URL"接口所上传的图片,不占用公众号的素材库中图片数量的5000个的限制, 图片仅支持jpg/png格式,大小必须在1MB以下。

func (*ForeverMedia) UploadThumbByUrl

func (fm *ForeverMedia) UploadThumbByUrl(thumbUrl string) (*ForeverMeidaInfo, error)

func (*ForeverMedia) UploadThumbFile

func (fm *ForeverMedia) UploadThumbFile(file string) (*ForeverMeidaInfo, error)

func (*ForeverMedia) UploadVideoFile

func (fm *ForeverMedia) UploadVideoFile(filePath, title, introduction string) (*ForeverMeidaInfo, error)

func (*ForeverMedia) UploadVoiceFile

func (fm *ForeverMedia) UploadVoiceFile(file string) (*ForeverMeidaInfo, error)

type ForeverMediaNum

type ForeverMediaNum struct {
	ImageNum int `json:"image_count"` //图片总数量
	VoiceNum int `json:"voice_count"` //语音总数量
	VideoNum int `json:"video_count"` //视频总数量
	NewsNum  int `json:"news_count"`  //图文总数量
}

请求永久素材数量时返回的信息

type ForeverMediaQuery

type ForeverMediaQuery struct {
	Type   MediaType `json:"type"`   //素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
	Offset int       `json:"offset"` //从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
	Count  int       `json:"count"`  //返回素材的数量,取值在1到20之间
}

type ForeverMeidaInfo

type ForeverMeidaInfo struct {
	MediaID  string `json:"media_id"` //新增的永久素材的media_id
	ImageUrl string `json:"url"`      //新增的图片素材的图片URL(仅新增图片素材时会返回该字段)
}

添加永久素材后返回的信息

type MediaItem

type MediaItem struct {
	MediaID    string `json:"media_id"`
	Name       string `json:"name"`
	UpdateTime int64  `json:"update_time"`
	Url        string `json:"url"`
}

非图文素材

type MediaList

type MediaList struct {
	TotalCount int          `json:"total_count"`
	ItemCount  int          `json:"item_count"`
	Item       []*MediaItem `json:"item"`
}

其他类型(图片、语音、视频)的返回如下:

type MediaType

type MediaType string

type NewsItem

type NewsItem struct {
	Title              string `json:"title,omitempty"`
	ThumbMediaId       string `json:"thumb_media_id,omitempty"`
	Author             string `json:"author,omitempty"`
	ContentSourceUrl   string `json:"content_source_url,omitempty"`
	Content            string `json:"content,omitempty"`
	Digest             string `json:"digest,omitempty"`
	ShowCoverPic       int    `json:"show_cover_pic,omitempty"`
	NeedOpenComment    int    `json:"need_open_comment,omitempty"`
	OnlyFansCanComment int    `json:"only_fans_can_comment,omitempty"`
}

图文类型素材的item

func NewNewsItem

func NewNewsItem(thumbMediaID, author, title, contentSourceUrl, content, digest string, showCoverPic, needOpenComment, onlyFansCanComment bool) *NewsItem

type NewsItems

type NewsItems struct {
	MediaID    string      `json:"media_id"`
	Content    []*NewsItem `json:"content"`
	UpdateTime int64       `json:"update_time"`
}

type NewsMediaList

type NewsMediaList struct {
	TotalCount int          `json:"total_count"`
	ItemCount  int          `json:"item_count"`
	Item       []*NewsItems `json:"item"`
}

永久图文消息素材列表的响应

type NewsSources

type NewsSources struct {
	Articles []*NewsItem `json:"articles"`
}

上传图文素材的数据类型

type UpdateNewsItem

type UpdateNewsItem struct {
	MediaID  string    `json:"media_id"` //要修改的图文消息的id
	Index    int       `json:"index"`    //要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为0
	Articles *NewsItem `json:"articles"`
}

更新图文素材的数据类型

Jump to

Keyboard shortcuts

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