wwx

package
v0.0.0-...-2e0c1f2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeText     = "text"
	TypeImage    = "image"
	TypeVoice    = "voice"
	TypeVideo    = "video"
	TypeLocation = "location"
	TypeLink     = "link"

	TypeEvent = "event"

	EventSubscribe   = "subscribe"
	EventUnsubscribe = "unsubscribe"
	EventScan        = "SCAN"
	EventLocation    = "LOCATION"
	EventClick       = "CLICK"
	EventView        = "VIEW"
)

Variables

This section is empty.

Functions

func DecryptAES

func DecryptAES(req EncryptedRequest, opts DecryptAESOptions) (buf []byte, err error)

func Handler

func Handler(altKeys ...string) winter.HandlerFunc

func Installer

func Installer(opts ...Option) wext.Installer

Types

type CDATA

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

type Context

type Context interface {
	context.Context

	// AppID returns the app_id
	AppID() string

	// Req returns the decoded request
	Req() Request

	// Res returns the response
	Res() *Response

	// Text send text response
	Text(s string)

	// Empty send empty response
	Empty()
}

Context WeChat handling context

type DecryptAESOptions

type DecryptAESOptions struct {
	Token          string
	AESKey         string
	AppID          string
	SkipValidation bool
}

type EncryptAESOptions

type EncryptAESOptions struct {
	Token     string
	AESKey    string
	AppID     string
	Nonce     string
	Timestamp string
}

type EncryptedRequest

type EncryptedRequest struct {
	Signature    string `json:"signature"`
	Timestamp    string `json:"timestamp"`
	Nonce        string `json:"nonce"`
	OpenID       string `json:"openid"`
	EncryptType  string `json:"encrypt_type"`
	MsgSignature string `json:"msg_signature"`
	Body         []byte `json:"body"`
}

type EncryptedRequestData

type EncryptedRequestData struct {
	XMLName    xml.Name `xml:"xml"`
	ToUserName string   `xml:"ToUserName"`
	Encrypt    string   `xml:"Encrypt"`
}

type EncryptedResponse

type EncryptedResponse struct {
	XMLName      xml.Name `xml:"xml"`
	Encrypt      CDATA    `xml:"Encrypt"`
	MsgSignature CDATA    `xml:"MsgSignature"`
	Timestamp    string   `xml:"TimeStamp"`
	Nonce        CDATA    `xml:"Nonce"`
}

func EncryptAES

func EncryptAES(buf []byte, opts EncryptAESOptions) (res EncryptedResponse, err error)

type HandlerFunc

type HandlerFunc func(c Context)

type Option

type Option = func(opts *options)

func SkipValidation

func SkipValidation(s bool) Option

SkipValidation set skipValidation

func WithAppID

func WithAppID(appID string) Option

WithAppID set AppID

func WithAppSecret

func WithAppSecret(appSecret string) Option

WithAppSecret set AppSecret

func WithEncodingAESKey

func WithEncodingAESKey(aesKey string) Option

WithEncodingAESKey set EncodingAESKey

func WithEventHandler

func WithEventHandler(evt string, h HandlerFunc) Option

WithEventHandler set message handler

func WithMessageHandler

func WithMessageHandler(typ string, h HandlerFunc) Option

WithMessageHandler set message handler

func WithRedisKey

func WithRedisKey(altKeys ...string) Option

WithRedisKey set redis to use

func WithToken

func WithToken(token string) Option

WithToken set Token

type Request

type Request struct {
	XMLName xml.Name `xml:"xml"`

	ToUserName   string `xml:"ToUserName"`
	FromUserName string `xml:"FromUserName"`
	CreateTime   int64  `xml:"CreateTime"`

	MsgID   int64  `xml:"MsgId"`
	MsgType string `xml:"MsgType"`

	MsgDataID string `xml:"MsgDataId"`
	Idx       int64  `xml:"Idx"`

	// text
	Content string `xml:"Content"`

	// image
	PicURL  string `xml:"PicUrl"`
	MediaID string `xml:"MediaId"`

	// voice
	//MediaID string `xml:"MediaId"`
	Format      string `xml:"Format"`
	Recognition string `xml:"Recognition"`

	// video
	//MediaID string `xml:"MediaId"`
	ThumbMediaID string `xml:"ThumbMediaId"`

	// location
	LocationX float64 `xml:"Location_X"`
	LocationY float64 `xml:"Location_Y"`
	Scale     int     `xml:"Scale"`
	Label     string  `xml:"Label"`

	// link
	Title       string `xml:"Title"`
	Description string `xml:"Description"`
	URL         string `xml:"Url"`

	// Event
	Event     string  `xml:"Event"`
	EventKey  string  `xml:"EventKey"`
	Ticket    string  `xml:"Ticket"`
	Latitude  float64 `xml:"Latitude"`
	Longitude float64 `xml:"Longitude"`
	Precision float64 `xml:"Precision"`
}

type Response

type Response struct {
	XMLName xml.Name `xml:"xml"`

	ToUserName   CDATA `xml:"ToUserName"`
	FromUserName CDATA `xml:"FromUserName"`
	CreateTime   int64 `xml:"CreateTime"`
	MsgType      CDATA `xml:"MsgType"`
	Content      CDATA `xml:"Content,omitempty"`

	Empty bool `xml:"-"`
}

type ValidationRequest

type ValidationRequest struct {
	Signature string `json:"signature"`
	Timestamp string `json:"timestamp"`
	Nonce     string `json:"nonce"`
	Echostr   string `json:"echostr"`
}

Jump to

Keyboard shortcuts

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