media

package
v0.0.0-...-5175aa2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypImage = "image"
	TypVoice = "voice"
	TypVideo = "video"
	TypThumb = "thumb"
)

Variables

This section is empty.

Functions

func DownFile

func DownFile(url string) ([]byte, error)

Types

type ArticleItem

type ArticleItem struct {
	Title        string `json:"title"`
	ThumbMediaID string `json:"thumb_media_id"` //图文消息的封面图片素材id(必须是永久mediaID)
	ShowCoverPic int    `json:"show_cover_pic"` //是否显示封面,0为false,即不显示,1为true,即显示
	Author       string `json:"author"`
	Digest       string `json:"digest"`             //图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空。如果本字段为没有填写,则默认抓取正文前64个字。
	Content      string `json:"content"`            //图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS,涉及图片url必须来源 "上传图文消息内的图片获取URL"接口获取。外部图片url将被过滤。
	URL          string `json:"url"`                //图文页的URL
	SourceURL    string `json:"content_source_url"` //图文消息的原文地址,即点击“阅读原文”后的URL

	//fields for uploading article
	Comment    int `json:"need_open_comment"`     //Uint32 是否打开评论,0不打开,1打开
	OnlyForFan int `json:"only_fans_can_comment"` //Uint32 是否粉丝才可评论,0所有人可评论,1粉丝才可评论
}

type ArticleUpdateWrapper

type ArticleUpdateWrapper struct {
	MediaID string      `json:"media_id"`
	Index   int         `json:"index"`
	Article ArticleItem `json:"articles"`
}

type ArticleWrapper

type ArticleWrapper struct {
	Articles []ArticleItem `json:"articles"`
}

type Base

type Base struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

type CommentResult

type CommentResult struct {
	request.CommonError
	Total    uint32 `json:"total"`
	Comments []struct {
		UserCommentID string `json:"user_comment_id"`
		OpenID        string `json:"openid"`
		CreateTime    int64  `json:"create_time"`
		Content       string `json:"content"`
		Reply         *struct {
			Content    string `json:"content"`
			CreateTime int64  `json:"create_time"`
		} `json:"reply,omitempty"`
	} `json:"comment"`
}

type CommentType

type CommentType uint32
const (
	CTypeBoth     CommentType = 0
	CTypeCommon   CommentType = 1
	CTypeSelected CommentType = 2
)

type GetComment

type GetComment struct {
	MsgID uint32      `json:"msg_data_id"`
	Index uint32      `json:"index,omitempty"`
	Begin uint32      `json:"begin"`
	Count uint32      `json:"count"`
	Type  CommentType `json:"type"`
}

type MaterialCounter

type MaterialCounter struct {
	Voice   int `json:"voice_count"`
	Video   int `json:"video_count"`
	Image   int `json:"image_count"`
	Article int `json:"news_count"`
}

type MaterialList

type MaterialList struct {
	Base

	TotalCount int `json:"total_count"`
	ItemCount  int `json:"item_count"`

	Items []struct {
		MediaID    string `json:"media_id"`
		UpdateTime int    `json:"update_time"`

		//Article
		Content struct {
			Articles []ArticleItem `json:"news_item"`
		} `json:"content"`

		//Image, Voice, Video
		Name string `json:"name"`
		Url  string `json:"url"`
	} `json:"item"`
}

type Media

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

func New

func New(r *request.Request) *Media

func (*Media) CommentClose

func (m *Media) CommentClose(mediaID string, index ...int) error

func (*Media) CommentDel

func (m *Media) CommentDel(isReply bool, MsgID uint32, CommentID uint32, index ...uint32) error

func (*Media) CommentList

func (m *Media) CommentList(req *GetComment) (*CommentResult, error)

func (*Media) CommentMark

func (m *Media) CommentMark(MsgID uint32, UserID uint32, index ...uint32) error

func (*Media) CommentOpen

func (m *Media) CommentOpen(mediaID string, index ...int) error

func (*Media) CommentReply

func (m *Media) CommentReply(msgID uint32, commentID uint32, content string, index ...uint32) error

func (*Media) CommentUnmark

func (m *Media) CommentUnmark(MsgID uint32, UserID uint32, index ...uint32) error

func (*Media) Delete

func (m *Media) Delete(mediaID string) error

can not delete temporary material

func (*Media) DeleteMsg

func (m *Media) DeleteMsg(MsgID int, articleIndex int) error

func (*Media) GetMaterial

func (m *Media) GetMaterial(mediaID string) (*Response, error)

func (*Media) GetMaterialList

func (m *Media) GetMaterialList(typ string, offset int, count int) (*MaterialList, error)

@typ 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news) @offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回 @count 返回素材的数量,取值在1到20之间 注意,这里面不支持 thumb 类型的资源,感觉是wx的坑

func (*Media) GetSendSpeed

func (m *Media) GetSendSpeed() (*Result, error)

func (*Media) GetTmpMaterial

func (m *Media) GetTmpMaterial(mediaID string) (*Response, error)

func (*Media) MaterialCounter

func (m *Media) MaterialCounter() (*MaterialCounter, error)

func (*Media) SendByFilter

func (m *Media) SendByFilter(msg *Message) (*Result, error)

func (*Media) SendByOpenID

func (m *Media) SendByOpenID(msg *Message) (*Result, error)

func (*Media) SendPreview

func (m *Media) SendPreview(msg *Message) error

func (*Media) SendStatus

func (m *Media) SendStatus(MsgID string) (*Result, error)

func (*Media) SetSendSpeed

func (m *Media) SetSendSpeed(speedLevel int) error

func (*Media) UpdateArticle

func (m *Media) UpdateArticle(article *ArticleWrapper) error

func (*Media) UploadArticle

func (m *Media) UploadArticle(article *ArticleWrapper) (*Result, error)

Article is the type of news in wechat development document (permanent material)

func (*Media) UploadImageForArticle

func (m *Media) UploadImageForArticle(rawUri string) (retUrl string, err error)

used to upload pictures in the Article (to satisfy wechat requirement)

func (*Media) UploadMaterial

func (m *Media) UploadMaterial(name string, in io.Reader, permanent bool, typ string, description ...VideoDescription) (*Result, error)

1、临时素材media_id是可复用的。 2、媒体文件在微信后台保存时间为3天,即3天后media_id失效。 3、上传临时素材的格式、大小限制与公众平台官网一致。 图片(image): 2M,支持PNG\JPEG\JPG\GIF格式 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式 视频(video):10MB,支持MP4格式 缩略图(thumb):64KB,支持JPG格式

@name 文件名,需要带后缀 @in io.Reader 接口,读取需要上传的数据 @permanent 是否上传永久文件? true 是, false临时文件 @typ 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb):w @description 上传视频使用

func (*Media) VideoToMessage

func (m *Media) VideoToMessage(v *Video) (*Result, error)

type Message

type Message struct {
	ToWxName      string     `json:"towxname,omitempty"` //available only in preview
	ToUser        *ToUser    `json:"touser,omitempty"`   //send by openIDs, minimum number is 2 and maximum number is 10000
	Filter        *MsgFilter `json:"filter,omitempty"`   //send by tag, is_to_all must be false
	MsgWrapper    MsgWrapper //MpNews(article), MpText, MpVoice, MpImage, MpVideo (video should be specially handled), MpCard
	IgnoreReprint int        `json:"send_ignore_reprint"` //图文消息被判定为转载时,是否继续群发。 1为继续群发(转载),0为停止群发。 该参数默认为0。

	ClientMsgId string `json:"clientmsgid"` //使用 clientmsgid 参数,避免重复推送
	// contains filtered or unexported fields
}

type MpCard

type MpCard struct {
	CardID string `json:"card_id"`
}

func (MpCard) Type

func (MpCard) Type() string

type MpImage

type MpImage struct {
	MediaIDs           []string `json:"media_ids"`
	Recommend          string   `json:"recommend"`
	NeedOpenComment    int      `json:"need_open_comment"`
	OnlyFansCanComment int      `json:"only_fans_can_comment"`
}

func (MpImage) Type

func (MpImage) Type() string

type MpNews

type MpNews struct {
	MediaID string `json:"media_id"`
}

func (MpNews) Type

func (MpNews) Type() string

type MpText

type MpText struct {
	Content string `json:"content"`
}

func (MpText) Type

func (MpText) Type() string

type MpVideo

type MpVideo struct {
	MediaID     string `json:"media_id"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

func (MpVideo) Type

func (MpVideo) Type() string

type MpVoice

type MpVoice struct {
	MediaID string `json:"media_id"`
}

func (MpVoice) Type

func (MpVoice) Type() string

type MsgFilter

type MsgFilter struct {
	IsToAll bool `json:"is_to_all"`
	TagID   int  `json:"tag_id"`
}

type MsgWrapper

type MsgWrapper interface {
	Type() string
}

type Response

type Response struct {
	Base

	//temporary video result
	VideoUrl string `json:"video_url"`
	//permanent video result
	Title       string `json:"title"`
	Description string `json:"description"`
	DownUrl     string `json:"down_url"`
	ContentType string

	//News type of material
	News []ArticleItem `json:"news_item"`

	//other types of material including image,voice,thumb
	Filename string `json:"-"`
	Data     []byte `json:"-"`
}

type Result

type Result struct {
	Base

	//upload article(news)
	Url string `json:"url"`

	Type      string `json:"type"` //values: image, voice, video, thumb
	MediaID   string `json:"media_id"`
	CreatedAt int64  `json:"created_at"`

	MsgID     int    `json:"msg_id"`
	MsgStatus string `json:"msg_status"`
	MsgDataID int    `json:"msg_data_id"`

	SpeedLevel int `json:"speed"`
	RealSpeed  int `json:"realspeed"`
}

type ToUser

type ToUser []string

func (*ToUser) Add

func (t *ToUser) Add(OpenID ...string)

func (*ToUser) MarshalJSON

func (t *ToUser) MarshalJSON() ([]byte, error)

type Video

type Video struct {
	VideoDescription
	MpVideo
}

type VideoDescription

type VideoDescription struct {
	Title string `json:"title"`
	Intro string `json:"introduction"`
}

Jump to

Keyboard shortcuts

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