wxdev

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

公众号模板消息

Index

Constants

View Source
const (
	// PermanentQRCode 永久二维码
	PermanentQRCode = 0
)

Variables

View Source
var ErrNoTokenServer = errors.New("No specify token server")

Functions

This section is empty.

Types

type ArticleItem

type ArticleItem struct {
	Title       CDataContent
	Description CDataContent
	PicUrl      CDataContent
	Url         CDataContent
}

ArticleItem 图文消息文章列表

type Button

type Button map[string]interface{}

Button 菜单

func LoadMenu

func LoadMenu(jsonstr []byte) ([]Button, error)

LoadMenu 解析JSON配置菜单

func LoadMenuFromFile

func LoadMenuFromFile(path string) ([]Button, error)

LoadMenuFromFile 从文件中加载菜单配置

func NewButtonArticle

func NewButtonArticle(name, mediaid string) Button

NewButtonArticle 图文消息

func NewButtonClick

func NewButtonClick(name, key string) Button

NewButtonClick creates click button

func NewButtonLocation

func NewButtonLocation(name, key string) Button

NewButtonLocation 发送位置

func NewButtonMedia

func NewButtonMedia(name, mediaid string) Button

NewButtonMedia 图片/音频/视频素材

func NewButtonMiniApp

func NewButtonMiniApp(name, appid, pagepath, uri string) Button

NewButtonMiniApp 打开小程序按钮 appid: 小程序的appid(仅认证公众号可配置) pagepath: 小程序的页面路径 参数uri: 网页 链接,用户点击菜单可打开链接,不超过1024字节。不支持小程序的老版本客户端将打开本url。

func NewButtonPhoto

func NewButtonPhoto(name, key string) Button

NewButtonPhoto 拍照按钮

func NewButtonPhotoOrAlbum

func NewButtonPhotoOrAlbum(name, key string) Button

NewButtonPhotoOrAlbum 拍照或相册按钮

func NewButtonScanPush

func NewButtonScanPush(name, key string) Button

NewButtonScanPush 扫码推事件

func NewButtonScanWait

func NewButtonScanWait(name, key string) Button

NewButtonScanWait 扫码带提示事件

func NewButtonView

func NewButtonView(name, url string) Button

NewButtonView creates view button

func NewButtonWXPic

func NewButtonWXPic(name, key string) Button

NewButtonWXPic 微信相册发图

func NewParentMenu

func NewParentMenu(name string) Button

NewParentMenu creates parent menu

func (Button) AddSubMenu

func (b Button) AddSubMenu(menu Button) Button

AddSubMenu 增加子菜单

type CDataContent

type CDataContent struct {
	Text string `xml:",cdata"`
}

func CDataWrap

func CDataWrap(content string) CDataContent

CDataWrap 包装为CDATA 内容

type CSMsgReply

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

CSMsgReply 客服消息

func NewCSMsgReply

func NewCSMsgReply(to string) CSMsgReply

NewCSMsgReply 创建客服消息

func (CSMsgReply) WithImage

func (reply CSMsgReply) WithImage(mediaid string)

WithImage 图片消息

func (CSMsgReply) WithText

func (reply CSMsgReply) WithText(content string)

WithText 文本消息

func (CSMsgReply) WithVideo

func (reply CSMsgReply) WithVideo(mediaid, thumbMediaid, title, desc string)

WithVideo 视频消息

func (CSMsgReply) WithVoice

func (reply CSMsgReply) WithVoice(mediaid string)

WithVoice 语音消息

type JSSDKSignature

type JSSDKSignature struct {
	AppID, Noncestr, Sign string
	Timestamp             int64
}

JSSDKSignature JSSDK 签名对象

type MatchRule

type MatchRule map[string]string

MatchRule 个性化菜单匹配规则

func (MatchRule) MatchCity

func (m MatchRule) MatchCity(city string) MatchRule

MatchCity 匹配城市

func (MatchRule) MatchCountry

func (m MatchRule) MatchCountry(country string) MatchRule

MatchCountry 国家匹配

func (MatchRule) MatchLanguage

func (m MatchRule) MatchLanguage(language string) MatchRule

MatchLanguage 匹配语言

func (MatchRule) MatchProvince

func (m MatchRule) MatchProvince(province string) MatchRule

MatchProvince 匹配省份

func (MatchRule) MatchSex

func (m MatchRule) MatchSex(sex WXSexType) MatchRule

MatchSex 性别匹配

func (MatchRule) MatchTag

func (m MatchRule) MatchTag(tagid string) MatchRule

MatchTag 标签匹配

type MediaObject

type MediaObject struct {
	FileName string
	Type     string
	Data     io.ReadCloser
	Size     int64
}

MediaObject 多媒体对象

type OptionFunc

type OptionFunc func(*WXClient)

OptionFunc 配置函数

func WithTokenServer

func WithTokenServer(uri string) OptionFunc

WithTokenServer 设置Token server

func WithValidationToken

func WithValidationToken(token string) OptionFunc

type PicInfo

type PicInfo struct {
	Count       int      `xml:",omitempty"`
	MD5SumItems []string `xml:"PicList>item>PicMd5Sum,omitempty"`
}

PicInfo 发送的图片信息

type StuffType

type StuffType string

StuffType 素材类型

const (
	StuffTypeImage StuffType = "image"
	StuffTypeVoice StuffType = "voice"
	StuffTypeVideo StuffType = "video"
	StuffTypeThumb StuffType = "thumb"
)

素材类型定义

type TmplData

type TmplData struct {
	ToUser     string                   `json:"touser"`
	TemplateID string                   `json:"template_id"`
	URL        string                   `json:"url"`
	FontColor  string                   `json:"color"`
	Data       map[string]tmplFieldData `json:"data"`
	MiniApp    struct {
		AppID    string `json:"appid"`
		PagePath string `json:"pagepath"`
	} `json:"miniprogram"`
}

TmplData 模板数据

func NewTmplData

func NewTmplData(openid, tmplid string) *TmplData

NewTmplData 创建模板对象

func (*TmplData) LinkMiniApp

func (t *TmplData) LinkMiniApp(appid, page string)

LinkMiniApp 设置模板消息跳转至的小程序

func (*TmplData) Put

func (t *TmplData) Put(key, value, color string)

Put 追加数据项

type TmplMessageSendReply

type TmplMessageSendReply struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
	MsgID   int64  `json:"msgid"`
}

TmplMessageSendReply 模板消息发送结果

type WXArticleMsgResponse

type WXArticleMsgResponse struct {
	WXMsgResponse
	ArticleCount int
	Articles     []ArticleItem `xml:"Articles>item"`
}

WXArticleMsgResponse 图文消息

func NewArticleMsg

func NewArticleMsg(from, to string, items ...ArticleItem) WXArticleMsgResponse

NewArticleMsg 图文消息

type WXBoolType

type WXBoolType byte

func (WXBoolType) ToBool

func (t WXBoolType) ToBool() bool

ToBool 转换为bool类型

type WXClient

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

WXClient 公众号客户端

func NewWXClient

func NewWXClient(appid string, options ...OptionFunc) *WXClient

NewWXClient 创建公众号客户端

func (*WXClient) APPID

func (c *WXClient) APPID() string

APPID 微信APPID

func (*WXClient) BatchGetUserInfo

func (c *WXClient) BatchGetUserInfo(openids ...string) ([]WXUserInfo, error)

BatchGetUserInfo 批量获取用户信息

func (*WXClient) CheckSignature

func (c *WXClient) CheckSignature(qryArgs url.Values) (string, error)

CheckSignature 微信接入验证

func (*WXClient) ClearMenu

func (c *WXClient) ClearMenu() error

ClearMenu 清空菜单

func (*WXClient) CreateMenu

func (c *WXClient) CreateMenu(items ...Button) error

CreateMenu 创建菜单

func (*WXClient) CreatePersonalMenu

func (c *WXClient) CreatePersonalMenu(rule MatchRule, items ...Button) (string, error)

CreatePersonalMenu 创建个性化菜单

func (*WXClient) CreateQRCode

func (c *WXClient) CreateQRCode(sceneValue interface{}, seconds int) (io.Reader, error)

CreateQRCode 创建二维码

func (*WXClient) DeletePersonalMenu

func (c *WXClient) DeletePersonalMenu(menuid string) error

DeletePersonalMenu 删除个性化菜单

func (*WXClient) DownloadHQVoice

func (c *WXClient) DownloadHQVoice(mediaid string) (MediaObject, error)

DownloadHQVoice 下载高清语音文件 格式为speex,16K采样率

func (*WXClient) DownloadMedia

func (c *WXClient) DownloadMedia(mediaid string) (MediaObject, error)

DownloadMedia 下载多媒体文件

func (*WXClient) DownloadVideo

func (c *WXClient) DownloadVideo(mediaid string) (string, error)

DownloadVideo 下载视频文件,返回视频链接

func (*WXClient) EnableDebug

func (c *WXClient) EnableDebug()

EnableDebug 启用debug模式

func (*WXClient) GenJSAPISign

func (c *WXClient) GenJSAPISign(u *url.URL) (JSSDKSignature, error)

GenJSAPISign 生成JSSDK签名

func (*WXClient) GetUserInfo

func (c *WXClient) GetUserInfo(openid string) (user WXUserInfo, err error)

GetUserInfo 获取用户基本信息

func (*WXClient) MessageHandleFunc

func (c *WXClient) MessageHandleFunc(handler func(WXMessageRequest) WXMessageResponse)

MessageHandleFunc 消息处理函数

func (*WXClient) SendCSMsg

func (c *WXClient) SendCSMsg(msg CSMsgReply) error

SendCSMsg 发送客服消息

func (*WXClient) SendTmplMessage

func (c *WXClient) SendTmplMessage(data *TmplData) (int64, error)

SendTmplMessage 发送模板消息

func (*WXClient) ServeHTTP

func (c *WXClient) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 自定义消息处理器

func (*WXClient) ServerGin

func (c *WXClient) ServerGin(ctx *gin.Context)

ServerGin 支持Gin web Framework

func (*WXClient) TestPersonalMenu

func (c *WXClient) TestPersonalMenu(wxuserid string) ([]Button, error)

TestPersonalMenu 测试个性化菜单 wxuserid 可以是粉丝的OpenID,也可以是粉丝的微信号

func (*WXClient) UploadTempStuff

func (c *WXClient) UploadTempStuff(t StuffType, filename string, file io.Reader) (string, error)

UploadTempStuff 上传临时素材

func (*WXClient) UploadTempStuffFile

func (c *WXClient) UploadTempStuffFile(t StuffType, filename string) (string, error)

UploadTempStuffFile 上传文件至临时素材库

type WXEventType

type WXEventType string

WXEventType 事件类型

const (
	EventTypeSubscribe   WXEventType = "subscribe"
	EventTypeUnsubscribe WXEventType = "unsubscribe"
	EventTypeScan        WXEventType = "SCAN"
	EventTypeLocation    WXEventType = "LOCATION"
	EventTypeClick       WXEventType = "CLICK"
	EventTypeView        WXEventType = "VIEW"
	// 自定义菜单事件
	EventTypeScanPush       WXEventType = "scancode_push"
	EventTypeScanWait       WXEventType = "scancode_waitmsg"
	EventTypePhoto          WXEventType = "pic_sysphoto"
	EventTypePhotoOrAlbum   WXEventType = "pic_photo_or_album"
	EventTypePicWeiXin      WXEventType = "pic_weixin"
	EventTypeLocationSelect WXEventType = "location_select"
)

事件类型定义

type WXImgMsgResponse

type WXImgMsgResponse struct {
	WXMsgResponse
	MediaID CDataContent `xml:"Image>MediaId,omitempty"`
}

WXImgMsgResponse 图片体消息

func NewImgMsg

func NewImgMsg(from, to, mediaid string) WXImgMsgResponse

NewImgMsg 图片消息

type WXMessageHandler

type WXMessageHandler func(WXMessageRequest) WXMessageResponse

WXMessageHandler 消息处理器

type WXMessageOKResponse

type WXMessageOKResponse struct{}

WXMessageOKResponse 返回success

type WXMessageRequest

type WXMessageRequest struct {
	XMLName                            xml.Name      `xml:"xml"`
	ToUserName                         string        `xml:",omitempty"`
	FromUserName                       string        `xml:",omitempty"`
	CreateTime                         int64         `xml:",omitempty"`
	MsgType                            WXMessageType `xml:",omitempty"`
	Content                            string        `xml:",omitempty"`
	MsgId                              int64         `xml:",omitempty"`
	PicUrl                             string        `xml:",omitempty"`
	MediaId                            string        `xml:",omitempty"`
	ThumbMediaId                       string        `xml:",omitempty"` //视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
	Format                             string        `xml:",omitempty"`
	Recognition                        string        `xml:",omitempty"` //语音识别结果,UTF8编码
	Location_X                         float64       `xml:",omitempty"`
	Location_Y                         float64       `xml:",omitempty"`
	Scale                              int           `xml:",omitempty"` //地图缩放大小
	Poiname, Label                     string        `xml:",omitempty"` // 地理位置信息
	Title                              string        `xml:",omitempty"`
	Description                        string        `xml:",omitempty"`
	Url                                string        `xml:",omitempty"`
	Event                              WXEventType   `xml:",omitempty"`
	EventKey                           string        `xml:",omitempty"`
	Ticket                             string        `xml:",omitempty"`
	Latitude, Longitude, Precision     float64       `xml:",omitempty"`
	ScanCodeInfo, ScanType, ScanResult string        `xml:",omitempty"`
	SendPicsInfo                       PicInfo       `xml:",omitempty"`
}

WXMessageRequest 微信消息

func (WXMessageRequest) GetEventKey

func (r WXMessageRequest) GetEventKey() string

GetEventKey 返回EventKey

func (WXMessageRequest) IsEvent

func (r WXMessageRequest) IsEvent() bool

IsEvent 下发消息是否来源于事件

func (WXMessageRequest) IsScanEvent

func (r WXMessageRequest) IsScanEvent() bool

IsScanEvent 消息是否为扫码事件

type WXMessageResponse

type WXMessageResponse interface{}

WXMessageResponse 微信回复消息

type WXMessageType

type WXMessageType string

WXMessageType 微信消息类型

const (
	WXMsgTypeEvent      WXMessageType = "event"
	WXMsgTypeText       WXMessageType = "text"
	WXMsgTypeImage      WXMessageType = "image"
	WXMsgTypeVoice      WXMessageType = "voice"
	WXMsgTypeVideo      WXMessageType = "video"
	WXMsgTypeShortVideo WXMessageType = "shortvideo"
	WXMsgTypeLink       WXMessageType = "link"
	WXMsgTypeLocation   WXMessageType = "location"
	WXMsgTypeMusic      WXMessageType = "music"
	WXMsgTypeNews       WXMessageType = "news"
	WXMsgTypeTransferCS WXMessageType = "transfer_customer_service"
)

微信消息类型定义

type WXMsgResponse

type WXMsgResponse struct {
	XMLName      xml.Name      `xml:"xml"`
	ToUserName   string        `xml:",omitempty"`
	FromUserName string        `xml:",omitempty"`
	CreateTime   int64         `xml:",omitempty"`
	MsgType      WXMessageType `xml:",omitempty"`
}

type WXMusicMsgResponse

type WXMusicMsgResponse struct {
	WXMsgResponse
	Music struct {
		Title        CDataContent `xml:",omitempty"`
		Description  CDataContent `xml:",omitempty"`
		MusicURL     CDataContent `xml:",omitempty"`
		HQMusicUrl   CDataContent `xml:",omitempty"`
		ThumbMediaId CDataContent `xml:",omitempty"`
	} `xml:"Music"`
}

WXMusicMsgResponse 音乐消息

func NewMusicMsg

func NewMusicMsg(from, to, mediaid, title, desc, uri, hquri string) WXMusicMsgResponse

NewMusicMsg 音乐消息

type WXSexType

type WXSexType byte
const (
	WXSexTypeMale   WXSexType = 1
	WXSexTypeFemale WXSexType = 2
)

func (WXSexType) String

func (t WXSexType) String() string

type WXTextMsgResponse

type WXTextMsgResponse struct {
	WXMsgResponse
	Content CDataContent `xml:",omitempty"`
}

WXTextMsgResponse 回复微信消息

func NewTextMsg

func NewTextMsg(from, to, content string) WXTextMsgResponse

NewTextMsg 创建文本消息

type WXTransferCSResponse

type WXTransferCSResponse struct {
	WXMsgResponse
	Account CDataContent `xml:"TransInfo>KfAccount,omitempty"`
}

WXTransferCSResponse 转发消息至微信客服系统

func TransferCustomerService

func TransferCustomerService(from, to, account string) WXTransferCSResponse

TransferCustomerService 创建转发客服系统响应

type WXUserInfo

type WXUserInfo struct {
	Subscribe     WXBoolType     `json:"subscribe"`
	OpenID        string         `json:"openid"`
	NickName      string         `json:"nickname"`
	Sex           WXSexType      `json:"sex"`
	Language      string         `json:"language"`
	City          string         `json:"city"`
	Province      string         `json:"province"`
	Country       string         `json:"country"`
	HeadImgUrl    string         `json:"headimgurl"`
	SubscribeTime dtime.JSONTime `json:"subscribe_time"`
	UnionID       string         `json:"unionid"`
	Remark        string         `json:"remark"`
	GroupID       int            `json:"groupid"`
	TagIDList     []int          `json:"tagid_list"`
	ErrCode       int            `json:"errcode"`
	ErrMsg        string         `json:"errmsg"`
}

WXUserInfo 微信公众号用户基本信息

type WXVideoMsgResponse

type WXVideoMsgResponse struct {
	WXMsgResponse
	MediaID     CDataContent `xml:"Video>MediaId,omitempty"`
	Title       CDataContent `xml:"Video>Title,omitempty"`
	Description CDataContent `xml:"Video>Description,omitempty"`
}

WXVideoMsgResponse 视频消息

func NewVideoMsg

func NewVideoMsg(from, to, mediaid, title, desc string) WXVideoMsgResponse

NewVideoMsg 视频消息

type WXVoiceMsgResponse

type WXVoiceMsgResponse struct {
	WXMsgResponse
	MediaID CDataContent `xml:"Voice>MediaId,omitempty"`
}

WXVoiceMsgResponse 语音体消息

func NewVoiceMsg

func NewVoiceMsg(from, to, mediaid string) WXVoiceMsgResponse

NewVoiceMsg 语音消息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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