wechat

package
v0.0.0-...-9ec6d84 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2020 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheTimeout = errors.New("cache timeout")

Functions

func HttpGetJson

func HttpGetJson(url string, obj interface{}) (body []byte, err error)

func JsonResponse

func JsonResponse(obj interface{}) []byte

create a json formatted response

func NewCrypter

func NewCrypter(token, aes_key string) (mc *wechatMsgCrypter, err error)

Types

type CDATA

type CDATA string

func (CDATA) MarshalXML

func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type CacheMap

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

func NewCacheMap

func NewCacheMap(duration time.Duration, limit int) *CacheMap

func (*CacheMap) Get

func (tm *CacheMap) Get(key string) (value interface{}, success bool)

func (*CacheMap) Remove

func (tm *CacheMap) Remove(key string)

func (*CacheMap) Set

func (tm *CacheMap) Set(key string, value interface{})

func (*CacheMap) Shrink

func (tm *CacheMap) Shrink()

type WechatApiServer

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

doc: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183

func NewApiServer

func NewApiServer() *WechatApiServer

func (*WechatApiServer) ServeHTTP

func (srv *WechatApiServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WechatAuthServer

type WechatAuthServer struct {
	WechatClient
	// contains filtered or unexported fields
}

https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842

func NewAuthServer

func NewAuthServer() *WechatAuthServer

func (*WechatAuthServer) ServeHTTP

func (srv *WechatAuthServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

/auth?appid=...&secret=...&call=...&lang= /auth/info?appid=...&secret=...&call=...&lang=

type WechatCardServer

type WechatCardServer struct {
	WechatClient
	// contains filtered or unexported fields
}

func NewCardServer

func NewCardServer() *WechatCardServer

func (*WechatCardServer) ServeHTTP

func (srv *WechatCardServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WechatClient

type WechatClient struct {
}

func (*WechatClient) GetAccessToken

func (c *WechatClient) GetAccessToken(hostUrl, appid, secret string) (accessToken string, err *WxError)

func (*WechatClient) GetJsTicket

func (c *WechatClient) GetJsTicket(hostUrl, appid, secret string) (jsTicket string, err *WxError)

func (*WechatClient) HostUrl

func (c *WechatClient) HostUrl(r *http.Request) string

func (*WechatClient) NormalizeUrl

func (srv *WechatClient) NormalizeUrl(r *http.Request, url string, query string) string

type WechatJsConfigServer

type WechatJsConfigServer struct {
	WechatClient
	// contains filtered or unexported fields
}

func NewJsConfigServer

func NewJsConfigServer() *WechatJsConfigServer

func (*WechatJsConfigServer) ServeHTTP

func (srv *WechatJsConfigServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WechatJsTicketServer

type WechatJsTicketServer struct {
	WechatClient
	// contains filtered or unexported fields
}

func NewJsTicketServer

func NewJsTicketServer() *WechatJsTicketServer

func (*WechatJsTicketServer) ServeHTTP

func (srv *WechatJsTicketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WechatMessageServer

type WechatMessageServer struct {
	WechatClient
}

doc: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319

func NewMessageServer

func NewMessageServer() *WechatMessageServer

func (*WechatMessageServer) ServeHTTP

func (srv *WechatMessageServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WechatPayServer

type WechatPayServer struct {
	WechatClient
	// contains filtered or unexported fields
}

func NewPayServer

func NewPayServer() *WechatPayServer

func (*WechatPayServer) ServeHTTP

func (srv *WechatPayServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WxAccessToken

type WxAccessToken struct {
	WxError
	AccessToken string `json:"access_token"`
	ExpiresIn   uint64 `json:"expires_in"`
}

type WxError

type WxError struct {
	ErrCode int    `json:"errcode,omitempty"`
	ErrMsg  string `json:"errmsg,omitempty"`
}

wechat error response

func NewError

func NewError(err error) *WxError

func NewErrorStr

func NewErrorStr(msg string) *WxError

func (*WxError) Serialize

func (e *WxError) Serialize() []byte

func (*WxError) String

func (e *WxError) String() string

func (*WxError) Success

func (e *WxError) Success() bool

type WxMessage

type WxMessage struct {
	ToUserName   string
	FromUserName string
	CreateTime   uint64
	MsgType      string

	MsgId        uint64  `json:",omitempty"` // message
	Content      string  `json:",omitempty"` // message: text
	MediaId      string  `json:",omitempty"` // message: picture,voice,video
	PicUrl       string  `json:",omitempty"` // message: picture
	Format       string  `json:",omitempty"` // message: voice
	Recognition  string  `json:",omitempty"` // message: voice
	ThumbMediaId string  `json:",omitempty"` // message: video
	Location_X   float64 `json:",omitempty"` // message: geometry
	Location_Y   float64 `json:",omitempty"` // message: geometry
	Scale        int32   `json:",omitempty"` // message: geometry
	Label        string  `json:",omitempty"` // message: geometry
	Title        string  `json:",omitempty"` // message: link
	Description  string  `json:",omitempty"` // message: link
	Url          string  `json:",omitempty"` // message: link

	Event     string  `json:",omitempty"` // event
	EventKey  string  `json:",omitempty"` // event: menu,scan
	Ticket    string  `json:",omitempty"` // event: scan
	Latitude  float64 `json:",omitempty"` // event: location
	Longitude float64 `json:",omitempty"` // event: location
	Precision float64 `json:",omitempty"` // event: location
}

xml to json cover 90% wechat message and events https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140453 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140454

type WxReply

type WxReply struct {
	ToUserName   string
	FromUserName string
	CreateTime   uint64
	MsgType      string

	// text
	Content CDATA `xml:",omitempty"`

	// image
	Image *struct {
		MediaId CDATA
	} `xml:",omitempty"`

	// voice
	Voice *struct {
		MediaId CDATA
	} `xml:",omitempty"`

	// video
	Video *struct {
		MediaId     CDATA
		Title       CDATA
		Description CDATA
	} `xml:",omitempty"`

	// music
	Music *struct {
		Title        CDATA
		Description  CDATA
		MusicUrl     CDATA
		HQMusicUrl   CDATA
		ThumbMediaId CDATA
	} `xml:",omitempty"`

	// news
	ArticleCount int32 `xml:",omitempty"`
	Articles     []struct {
		Item struct {
			Title       CDATA
			Description CDATA
			PicUrl      CDATA
			Url         CDATA
		}
	} `xml:",omitempty"`
}

json to xml https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140543

Jump to

Keyboard shortcuts

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