custom

package
v0.0.0-...-7011273 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

客服主动回复消息.

Index

Constants

View Source
const (
	MsgTypeText  = "text"  // 文本消息
	MsgTypeImage = "image" // 图片消息
	MsgTypeVoice = "voice" // 语音消息
	MsgTypeVideo = "video" // 视频消息
	MsgTypeMusic = "music" // 音乐消息
	MsgTypeNews  = "news"  // 图文消息
)
View Source
const (
	NewsArticleCountLimit = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Title       string `json:"title,omitempty"`       // 图文消息标题
	Description string `json:"description,omitempty"` // 图文消息描述
	URL         string `json:"url,omitempty"`         // 点击图文消息跳转链接
	PicURL      string `json:"picurl,omitempty"`      // 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80
}

图文消息里的 Article

type Client

type Client struct {
	*mp.WechatClient
}

func NewClient

func NewClient(AccessTokenServer mp.AccessTokenServer, httpClient *http.Client) Client

兼容保留, 建議實際項目全局維護一個 *mp.WechatClient

func (Client) SendImage

func (clt Client) SendImage(msg *Image) error

发送客服消息, 图片.

func (Client) SendMusic

func (clt Client) SendMusic(msg *Music) error

发送客服消息, 音乐.

func (Client) SendNews

func (clt Client) SendNews(msg *News) (err error)

发送客服消息, 图文.

func (Client) SendText

func (clt Client) SendText(msg *Text) error

发送客服消息, 文本.

func (Client) SendVideo

func (clt Client) SendVideo(msg *Video) error

发送客服消息, 视频.

func (Client) SendVoice

func (clt Client) SendVoice(msg *Voice) error

发送客服消息, 语音.

type CommonMessageHeader

type CommonMessageHeader struct {
	ToUser  string `json:"touser"` // 接收方 OpenID
	MsgType string `json:"msgtype"`
}

type CustomService

type CustomService struct {
	KfAccount string `json:"kf_account"`
}

如果需要以某个客服帐号来发消息(在微信6.0.2及以上版本中显示自定义头像), 则需在JSON数据包的后半部分加入 customservice 参数

type Image

type Image struct {
	CommonMessageHeader

	Image struct {
		MediaId string `json:"media_id"` // 通过上传多媒体文件得到的 MediaId
	} `json:"image"`

	*CustomService `json:"customservice,omitempty"`
}

图片消息

func NewImage

func NewImage(toUser, mediaId, kfAccount string) (image *Image)

新建图片消息.

mediaId 是通过上传多媒体文件得到;
如果不指定客服则 kfAccount 留空.

type Music

type Music struct {
	CommonMessageHeader

	Music struct {
		Title        string `json:"title,omitempty"`          // 音乐标题
		Description  string `json:"description,omitempty"`    // 音乐描述
		MusicURL     string `json:"musicurl,omitempty"`       // 音乐链接
		HQMusicURL   string `json:"hqmusicurl,omitempty"`     // 高质量音乐链接, WIFI环境优先使用该链接播放音乐
		ThumbMediaId string `json:"thumb_media_id,omitempty"` // 缩略图的媒体id, 通过上传多媒体文件得到
	} `json:"music"`

	*CustomService `json:"customservice,omitempty"`
}

音乐消息

func NewMusic

func NewMusic(toUser, thumbMediaId, musicURL, HQMusicURL, title, description,
	kfAccount string) (music *Music)

新建音乐消息.

thumbMediaId 通过上传多媒体文件得到;
title, description 可以为 "";
如果不指定客服则 kfAccount 留空.

type News

type News struct {
	CommonMessageHeader

	News struct {
		Articles []Article `json:"articles,omitempty"` // 多条图文消息信息, 默认第一个item为大图, 注意, 如果图文数超过10, 则将会无响应
	} `json:"news"`

	*CustomService `json:"customservice,omitempty"`
}

图文消息

func NewNews

func NewNews(toUser string, articles []Article, kfAccount string) (news *News)

新建图文消息.

NOTE: articles 的长度不能超过 NewsArticleCountLimit;
如果不指定客服则 kfAccount 留空.

func (*News) CheckValid

func (this *News) CheckValid() (err error)

检查 News 是否有效,有效返回 nil,否则返回错误信息.

type Text

type Text struct {
	CommonMessageHeader

	Text struct {
		Content string `json:"content"` // 支持换行符
	} `json:"text"`

	*CustomService `json:"customservice,omitempty"`
}

文本消息

func NewText

func NewText(toUser, content, kfAccount string) (text *Text)

新建文本消息.

content 支持换行符;
如果不指定客服则 kfAccount 留空.

type Video

type Video struct {
	CommonMessageHeader

	Video struct {
		MediaId      string `json:"media_id"`              // 通过上传多媒体文件得到的 MediaId
		ThumbMediaId string `json:"thumb_media_id"`        // 缩略图的媒体id, 通过上传多媒体文件得到
		Title        string `json:"title,omitempty"`       // 视频消息的标题
		Description  string `json:"description,omitempty"` // 视频消息的描述
	} `json:"video"`

	*CustomService `json:"customservice,omitempty"`
}

视频消息

func NewVideo

func NewVideo(toUser, mediaId, thumbMediaId, title, description,
	kfAccount string) (video *Video)

新建视频消息.

mediaId, thumbMediaId 是通过上传多媒体文件得到;
title, description 可以为 "";
如果不指定客服则 kfAccount 留空.

type Voice

type Voice struct {
	CommonMessageHeader

	Voice struct {
		MediaId string `json:"media_id"` // 通过上传多媒体文件得到的 MediaId
	} `json:"voice"`

	*CustomService `json:"customservice,omitempty"`
}

语音消息

func NewVoice

func NewVoice(toUser, mediaId, kfAccount string) (voice *Voice)

新建语音消息.

mediaId 是通过上传多媒体文件得到;
如果不指定客服则 kfAccount 留空.

Jump to

Keyboard shortcuts

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