media

package
v0.0.0-...-0447b3e Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2016 License: GPL-3.0, Apache-2.0 Imports: 10 Imported by: 0

README

上传图片示例

package main

import (
	"fmt"

	"github.com/chanxuehong/wechat/mp"
	"github.com/chanxuehong/wechat/mp/media"
)

var TokenServer = mp.NewDefaultTokenServer("appid", "appsecret", nil)

func main() {
	clt := media.NewClient(TokenServer, nil)
	info, err := clt.UploadImage("d:\\img.jpg")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(info)
}

Documentation

Overview

媒体相关操作.

Index

Constants

View Source
const (
	MediaTypeImage = "image"
	MediaTypeVoice = "voice"
	MediaTypeVideo = "video"
	MediaTypeThumb = "thumb"
	MediaTypeNews  = "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"`               // 图文消息缩略图的 media_id, 可以在上传多媒体文件接口中获得
	Title            string `json:"title"`                        // 图文消息的标题
	Author           string `json:"author,omitempty"`             // 图文消息的作者
	Digest           string `json:"digest,omitempty"`             // 图文消息的摘要
	Content          string `json:"content"`                      // 图文消息页面的内容,支持HTML标签
	ContentSourceURL string `json:"content_source_url,omitempty"` // 在图文消息页面点击“阅读原文”后的页面
	ShowCoverPic     int    `json:"show_cover_pic"`               // 是否显示封面, 1为显示, 0为不显示
}

图文消息里的 Article

func (*Article) SetShowCoverPic

func (article *Article) SetShowCoverPic(b bool)

type Client

type Client struct {
	mp.WechatClient
}

func NewClient

func NewClient(TokenServer mp.TokenServer, HttpClient *http.Client) *Client

创建一个新的 Client.

如果 HttpClient == nil 则默认用 http.DefaultClient

func (*Client) CreateNews

func (clt *Client) CreateNews(articles []Article) (info *MediaInfo, err error)

根据上传的缩略图媒体创建图文消息素材.

articles 的长度不能大于 NewsArticleCountLimit.

func (*Client) CreateVideo

func (clt *Client) CreateVideo(mediaId, title, description string) (info *MediaInfo, err error)

根据上传的视频文件 media_id 创建视频媒体, 群发视频消息应该用这个函数得到的 media_id.

NOTE: title, description 可以为空.

func (*Client) DownloadMedia

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

下载多媒体到文件.

func (*Client) DownloadMediaToWriter

func (clt *Client) DownloadMediaToWriter(mediaId string, writer io.Writer) error

下载多媒体到 io.Writer.

func (*Client) UploadImage

func (clt *Client) UploadImage(filepath string) (info *MediaInfo, err error)

上传多媒体图片

func (*Client) UploadImageFromReader

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

上传多媒体图片

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

func (*Client) UploadThumb

func (clt *Client) UploadThumb(_filepath string) (info *MediaInfo, err error)

上传多媒体缩略图

func (*Client) UploadThumbFromReader

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

上传多媒体缩略图

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

func (*Client) UploadVideo

func (clt *Client) UploadVideo(filepath string) (info *MediaInfo, err error)

上传多媒体视频

func (*Client) UploadVideoFromReader

func (clt *Client) UploadVideoFromReader(filename string, reader io.Reader) (info *MediaInfo, err error)

上传多媒体视频

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

func (*Client) UploadVoice

func (clt *Client) UploadVoice(filepath string) (info *MediaInfo, err error)

上传多媒体语音

func (*Client) UploadVoiceFromReader

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

上传多媒体语音

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

type MediaInfo

type MediaInfo struct {
	MediaType string `json:"type"`       // 图片(image)、语音(voice)、视频(video)、缩略图(thumb)和 图文消息(news)
	MediaId   string `json:"media_id"`   // 媒体的唯一标识
	CreatedAt int64  `json:"created_at"` // 媒体创建的时间戳
}

Jump to

Keyboard shortcuts

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