Documentation ¶
Overview ¶
用户管理
Index ¶
- Constants
- Variables
- func DecodeRawMessage[T any](data []byte) (*T, error)
- func HttpGet[T any](url string) (*T, error)
- func HttpGetRaw(url string) ([]byte, error)
- func PostJSON[T any](url string, body interface{}) (*T, error)
- func PostJSONReturnRaw(url string, body interface{}) ([]byte, error)
- func ValidateSignature(tok, timestamp, nonce, signature string) bool
- type BaseEvent
- type BaseMessage
- type ClickEvent
- type ClickEventHandler
- type Engine
- func (e *Engine) Code2Session(jscode string) (*SessionInfo, error)
- func (e *Engine) CreateMenu(menu []byte) (*ErrorMsg, error)
- func (e *Engine) GetAccessToken() (string, error)
- func (e *Engine) GetCurrentSelfMenuInfo() error
- func (e *Engine) GetPhoneNumber(code string) (*PhoneInfo, error)
- func (e *Engine) GetUserInfo() (*UserInfo, error)
- func (e *Engine) GrantAccessToken() error
- func (e *Engine) HandleMessage(c context.Context, data []byte) error
- func (e *Engine) RegClickEventHandler(h ClickEventHandler)
- func (e *Engine) RegImageMessageHandler(h ImageMessageHandler)
- func (e *Engine) RegLinkMessageHandler(h LinkMessageHandler)
- func (e *Engine) RegLocationEventHandler(h LocationEventHandler)
- func (e *Engine) RegLocationMessageHandler(h LocationMessageHandler)
- func (e *Engine) RegScanEventHandler(h ScanEventHandler)
- func (e *Engine) RegSubscribeEventHandler(h SubscribeEventHandler)
- func (e *Engine) RegTextMessageHandler(h TextMessageHandler)
- func (e *Engine) RegUnsubscribeEventHandler(h UnsubscribeEventHandler)
- func (e *Engine) RegVideoMessageHandler(h VideoMessageHandler)
- func (e *Engine) RegViewEventHandler(h ViewEventHandler)
- func (e *Engine) RegVoiceMessageHandler(h VoiceMessageHandler)
- func (e *Engine) ValidateSignature(timestamp, nonce, signature string) bool
- type ErrInvalidEventType
- type ErrInvalidMessageType
- type ErrorMsg
- type IEngine
- type IRepository
- type ImageMessage
- type ImageMessageHandler
- type LinkMessage
- type LinkMessageHandler
- type LocationEvent
- type LocationEventHandler
- type LocationMessage
- type LocationMessageHandler
- type PhoneInfo
- type QRCodeInfo
- func CreateLimitQRCode(e IEngine, id int32) (*QRCodeInfo, error)
- func CreateLimitQRCodeByStr(e IEngine, id string) (*QRCodeInfo, error)
- func CreateQRCode(e IEngine, id int32, expireSeconds int32) (*QRCodeInfo, error)
- func CreateQRCodeByStr(e IEngine, id string, expireSeconds int32) (*QRCodeInfo, error)
- type ScanEvent
- type ScanEventHandler
- type SessionInfo
- type SubscribeEvent
- type SubscribeEventHandler
- type TextMessage
- type TextMessageHandler
- type UnsubscribeEvent
- type UnsubscribeEventHandler
- type UserInfo
- type VideoMessage
- type VideoMessageHandler
- type ViewEvent
- type ViewEventHandler
- type VoiceMessage
- type VoiceMessageHandler
- type Watermark
- type WeiXinApiConfig
Constants ¶
View Source
const ( MsgTypeText = "text" // 文本消息 MsgTypeImage = "image" // 图片消息 MsgTypeVoice = "voice" // 语音消息 MsgTypeVideo = "video" // 视频消息 MsgTypeShortVideo = "shortvideo" // 小视频消息 MsgTypeLocation = "location" // 地理位置消息 MsgTypeLink = "link" // 链接消息 MsgTypeEvent = "event" // 事件推送 )
微信支持的消息类型
View Source
const ( EventTypeClick = "CLICK" // 自定义菜单事件 EventTypeView = "VIEW" // 点菜单跳转链接 EventTypeLocation = "LOCATION" // 上报地理位置 EventTypeScan = "SCAN" // 用户已关注 EventTypeSubscribe = "subscribe" // 用户未关注 EventTypeUnsubscribe = "unsubscribe" // 取消订阅 )
Variables ¶
View Source
var ( ErrInvalidHandler = errors.New("未注册消息处理函数") ErrInvalidXMLToken = errors.New("xml解析token出错") )
View Source
var ErrRepoLocked = errors.New("Repository is already locked")
View Source
var ErrTokenInvalid = errors.New("AccessToken is invalid")
Functions ¶
func DecodeRawMessage ¶
func HttpGetRaw ¶
func PostJSONReturnRaw ¶
func ValidateSignature ¶
验证签名是否合法
Types ¶
type BaseEvent ¶
type BaseEvent struct { BaseMessage Event string // 事件类型,subscribe(订阅)、unsubscribe(取消订阅) }
type BaseMessage ¶
type ClickEvent ¶
自定义菜单事件 事件类型,CLICK
type ClickEventHandler ¶
type ClickEventHandler func(m *ClickEvent) error
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func New ¶
func New(cfg *WeiXinApiConfig) *Engine
func (*Engine) Code2Session ¶
func (e *Engine) Code2Session(jscode string) (*SessionInfo, error)
func (*Engine) GetAccessToken ¶
func (*Engine) GetCurrentSelfMenuInfo ¶
func (*Engine) GetUserInfo ¶
func (*Engine) GrantAccessToken ¶
从微信服务器获取Access Token,并保存到repository里面,后续调用GetAccessToken时,再从repository里面获取
func (*Engine) RegClickEventHandler ¶
func (e *Engine) RegClickEventHandler(h ClickEventHandler)
func (*Engine) RegImageMessageHandler ¶
func (e *Engine) RegImageMessageHandler(h ImageMessageHandler)
func (*Engine) RegLinkMessageHandler ¶
func (e *Engine) RegLinkMessageHandler(h LinkMessageHandler)
func (*Engine) RegLocationEventHandler ¶
func (e *Engine) RegLocationEventHandler(h LocationEventHandler)
func (*Engine) RegLocationMessageHandler ¶
func (e *Engine) RegLocationMessageHandler(h LocationMessageHandler)
func (*Engine) RegScanEventHandler ¶
func (e *Engine) RegScanEventHandler(h ScanEventHandler)
func (*Engine) RegSubscribeEventHandler ¶
func (e *Engine) RegSubscribeEventHandler(h SubscribeEventHandler)
func (*Engine) RegTextMessageHandler ¶
func (e *Engine) RegTextMessageHandler(h TextMessageHandler)
func (*Engine) RegUnsubscribeEventHandler ¶
func (e *Engine) RegUnsubscribeEventHandler(h UnsubscribeEventHandler)
func (*Engine) RegVideoMessageHandler ¶
func (e *Engine) RegVideoMessageHandler(h VideoMessageHandler)
func (*Engine) RegViewEventHandler ¶
func (e *Engine) RegViewEventHandler(h ViewEventHandler)
func (*Engine) RegVoiceMessageHandler ¶
func (e *Engine) RegVoiceMessageHandler(h VoiceMessageHandler)
func (*Engine) ValidateSignature ¶
验证签名是否合法
type ErrInvalidEventType ¶
type ErrInvalidEventType struct {
Type string
}
func (*ErrInvalidEventType) Error ¶
func (err *ErrInvalidEventType) Error() string
type ErrInvalidMessageType ¶
type ErrInvalidMessageType struct {
Type string
}
func (*ErrInvalidMessageType) Error ¶
func (err *ErrInvalidMessageType) Error() string
type IRepository ¶
type ImageMessage ¶
type ImageMessage struct { BaseMessage PicUrl string // 图片链接(由系统生成) MediaId string // 图片消息媒体id,可以调用获取临时素材接口拉取数据。 }
ImageMessage 图片消息 图片为image
type ImageMessageHandler ¶
type ImageMessageHandler func(m *ImageMessage) error
type LinkMessage ¶
type LinkMessage struct { BaseMessage Title string // 消息标题 Description string // 消息描述 Url string // 消息链接 }
LinkMessage 链接消息,链接为link
type LinkMessageHandler ¶
type LinkMessageHandler func(m *LinkMessage) error
type LocationEvent ¶
type LocationEvent struct { BaseEvent Latitude float32 //地理位置纬度 Longitude float32 //地理位置经度 Precision float32 //地理位置精度 }
上报地理位置事件 事件类型,LOCATION
type LocationEventHandler ¶
type LocationEventHandler func(m *LocationEvent) error
type LocationMessage ¶
type LocationMessage struct { BaseMessage LocationX float64 `xml:"Location_X"` // 地理位置纬度 LocationY float64 `xml:"Location_Y"` // 地理位置经度 Scale int // 地图缩放大小 Label string // 地理位置信息 }
LocationMessage 地理位置消息,地理位置为location
type LocationMessageHandler ¶
type LocationMessageHandler func(m *LocationMessage) error
type QRCodeInfo ¶
type QRCodeInfo struct { ErrorMsg Ticket string `json:"ticket"` ExpiresIn int32 `json:"expire_seconds"` URL string `json:"url"` }
func CreateLimitQRCode ¶
func CreateLimitQRCode(e IEngine, id int32) (*QRCodeInfo, error)
func CreateLimitQRCodeByStr ¶
func CreateLimitQRCodeByStr(e IEngine, id string) (*QRCodeInfo, error)
func CreateQRCode ¶
func CreateQRCode(e IEngine, id int32, expireSeconds int32) (*QRCodeInfo, error)
func CreateQRCodeByStr ¶
func CreateQRCodeByStr(e IEngine, id string, expireSeconds int32) (*QRCodeInfo, error)
type ScanEvent ¶
type ScanEvent struct { BaseEvent EventKey string // 事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id Ticket string //二维码的ticket,可用来换取二维码图片 }
用户已关注时的事件推送
type ScanEventHandler ¶
type SessionInfo ¶
type SubscribeEvent ¶
type SubscribeEvent struct { BaseEvent EventKey string // 事件KEY值,qrscene_为前缀,后面为二维码的参数值 Ticket string // 二维码的ticket,可用来换取二维码图片 }
事件类型,subscribe 事件类型,unsubscribe(取消订阅)
type SubscribeEventHandler ¶
type SubscribeEventHandler func(m *SubscribeEvent) error
type TextMessageHandler ¶
type TextMessageHandler func(m *TextMessage) error
type UnsubscribeEvent ¶
type UnsubscribeEvent struct { BaseEvent EventKey string // 事件KEY值,qrscene_为前缀,后面为二维码的参数值 Ticket string // 二维码的ticket,可用来换取二维码图片 }
事件类型,unsubscribe 事件类型,unsubscribe(取消订阅)
type UnsubscribeEventHandler ¶
type UnsubscribeEventHandler func(m *UnsubscribeEvent) error
type VideoMessage ¶
type VideoMessage struct { BaseMessage MediaId string // 视频消息媒体id,可以调用获取临时素材接口拉取数据。 ThumbMediaId string // 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。 }
VideoMessage 视频/小视频消息 视频为video,小视频为shortvideo
type VideoMessageHandler ¶
type VideoMessageHandler func(m *VideoMessage) error
type ViewEventHandler ¶
type VoiceMessage ¶
type VoiceMessage struct { BaseMessage MediaId string // 语音消息媒体id,可以调用获取临时素材接口拉取数据。 Format string // 语音格式,如amr,speex等 Recongnition string // 消息id,64位整型 }
VoiceMessage 语音消息 语音为voice
type VoiceMessageHandler ¶
type VoiceMessageHandler func(m *VoiceMessage) error
type WeiXinApiConfig ¶
type WeiXinApiConfig struct { AppId string AppSecret string AppToken string WeiXinDomain string Repository IRepository // AccessToken string HandleTextMessage func(m *TextMessage) error HandleImageMessage func(m *ImageMessage) error HandleVoiceMessage func(m *VoiceMessage) error HandleVideoMessage func(m *VideoMessage) error HandleLocationMessage func(m *LocationMessage) error HandleLinkMessage func(m *LinkMessage) error HandleClickEvent func(m *ClickEvent) error HandleLocationEvent func(m *LocationEvent) error HandleViewEvent func(m *ViewEvent) error HandleScanEvent func(m *ScanEvent) error HandleSubscribeEvent func(m *SubscribeEvent) error HandleUnsubscribeEvent func(m *UnsubscribeEvent) error }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.