server

package
v0.0.0-...-69192e6 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 消息类型
	MsgTypeText       = "text"       // 文本消息
	MsgTypeImage      = "image"      // 图片消息
	MsgTypeVoice      = "voice"      // 语音消息
	MsgTypeVideo      = "video"      // 视频消息
	MsgTypeShortVideo = "shortvideo" // 小视频消息
	MsgTypeLocation   = "location"   // 地理位置消息
	MsgTypeLink       = "link"       // 链接消息
	// 事件类型
	EvtTypeSubscribe   = "subscribe"   // 关注事件/用户未关注时扫描带参数二维码事件
	EvtTypeUnsubscribe = "unsubscribe" // 取消关注事件
	EvtTypeScan        = "SCAN"        // 用户已关注时扫描带参数二维码事件
	EvtTypeLocation    = "LOCATION"    // 上报地理位置事件
	EvtTypeClick       = "CLICK"       // 自定义菜单拉取消息事件
	EvtTypeView        = "VIEW"        // 自定义菜单跳转链接事件
)

Variables

View Source
var (
	ErrTokenNotFound          = errors.New("token is not found in store")
	ErrEncodingAESKeyNotFound = errors.New("encoding aes key is not found in store")
)

Functions

This section is empty.

Types

type Article

type Article struct {
	Title       CDATA
	Description CDATA
	PicURL      CDATA `xml:"PicUrl"`
	URL         CDATA `xml:"Url"`
}

type CDATA

type CDATA struct {
	Value string `xml:",cdata"`
}

type Context

type Context struct {
	Req    *http.Request
	ReqMsg *ReqMsg
	// contains filtered or unexported fields
}

func (*Context) AppID

func (ctx *Context) AppID() string

应用ID

func (*Context) ReplyImageMsg

func (ctx *Context) ReplyImageMsg(mediaID string) error

被动回复图片消息

func (*Context) ReplyMusicMsg

func (ctx *Context) ReplyMusicMsg(title, descr, musicURL, hqMusicURL, thumbMediaID string) error

被动回复音乐消息

func (*Context) ReplyNewsMsg

func (ctx *Context) ReplyNewsMsg(articles []*Article) error

被动回复图文消息

func (*Context) ReplyTextMsg

func (ctx *Context) ReplyTextMsg(content string) error

被动回复文本消息

func (*Context) ReplyVideoMsg

func (ctx *Context) ReplyVideoMsg(title, descr, MediaID string) error

被动回复视频消息

func (*Context) ReplyVoiceMsg

func (ctx *Context) ReplyVoiceMsg(mediaID string) error

被动回复语音消息

func (*Context) SafeMode

func (ctx *Context) SafeMode() bool

是否为安全模式

func (*Context) Transfer2CustomerService

func (ctx *Context) Transfer2CustomerService(kfAccount ...string) error

将消息转发到客服

type Handler

type Handler func(*Context)

消息处理器

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) GetEncodingAESKey

func (sto *MemoryStore) GetEncodingAESKey(appID string) (encodingAESKey string, err error)

func (*MemoryStore) GetToken

func (sto *MemoryStore) GetToken(appID string) (token string, err error)

func (*MemoryStore) SetEncodingAESKey

func (sto *MemoryStore) SetEncodingAESKey(appID, encodingAESKey string)

func (*MemoryStore) SetToken

func (sto *MemoryStore) SetToken(appID, token string)

type ReqMsg

type ReqMsg struct {
	XMLName      xml.Name `xml:"xml"`
	Encrypt      string
	ToUserName   string // 开发者微信号
	FromUserName string // 发送方OpenID
	CreateTime   int64  // 消息创建时间
	MsgType      string // 消息类型
	// 普通消息参数
	Content      string  // 文本消息内容
	PicURL       string  `xml:"PicUrl"`  // 图片链接
	MediaID      string  `xml:"MediaId"` // 图片/语音/视频消息媒体ID
	Format       string  // 语音格式
	Recognition  string  // 语音识别结果
	ThumbMediaID string  `xml:"ThumbMediaId"` // 视频消息缩略图的媒体ID
	LocationX    float64 `xml:"Location_X"`   // 地理位置维度
	LocationY    float64 `xml:"Location_Y"`   // 地理位置经度
	Scale        int     // 地图缩放大小
	Label        string  // 地理位置信息
	Title        string  // 消息标题
	Description  string  // 消息描述
	URL          string  `xml:"Url"`   // 消息链接
	MsgID        int64   `xml:"MsgId"` // 消息ID
	// 事件推送参数
	Event     string  // 事件类型
	EventKey  string  // 事件KEY值
	Ticket    string  // 二维码的Ticket
	Latitude  float64 // 地理位置纬度
	Longitude float64 // 地理位置经度
	Precision float64 // 地理位置精度
}

type Server

type Server struct {
	Store          Store
	DefaultHandler Handler
	MsgHandlers    map[string]Handler
	EvtHandlers    map[string]Handler
}

消息服务端

func New

func New(store Store) *Server

实例化消息服务端

func (*Server) OnEvt

func (srv *Server) OnEvt(typ string, h Handler)

注册普通消息处理器

func (*Server) OnMsg

func (srv *Server) OnMsg(typ string, h Handler)

注册事件推送处理器

func (*Server) ServeHTTP

func (srv *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)

type Store

type Store interface {
	GetToken(appID string) (token string, err error)
	GetEncodingAESKey(appID string) (encodingAESKey string, err error)
}

Jump to

Keyboard shortcuts

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