Documentation
¶
Overview ¶
*
- 微信信息加解密/签名/随机数
- 1. HashStrings([]string) -- 微信常用的签名算法 []string -> sort -> sha1 -> hex
- 2. GetRandomBytes(int) -- 获取指定长度的随机串,随机字符为 数字/小写字母/大写字母
*
- 微信消息/事件的缺省处理函数
- 当前处理的消息/事件未全部覆盖,可以根据需要在此扩充
*
- 服务号消息/事件的结构定义和解析,触发消息/事件处理
- 1. wxapi.ParseMessageBody() --- 获取消息/事件的(消息体,时间戳,nonce,error),主要用于调试
- 2. wxapi.GetReply([]byte) --- 根据消息体触发消息处理函数得到返回结果。如果使用default_rest.go的实现不需要关心它
*
- 消息/事件的响应消息体构造和序列化为XML,被msg_parse.go调用
- 目前支持消息类型有限,可以根据需要扩充
Index ¶
- Constants
- Variables
- func EncryptReply(replyMsg string, timestamp string, nonce string) []byte
- func GetMessageBody(r *http.Request) ([]byte, string, string, error)
- func GetRandomBytes(n int) []byte
- func GetReply(msgBody []byte) (string, error)
- func HashStrings(sl []string) string
- func ParseMessageBody(u *url.URL, body []byte) ([]byte, string, string, error)
- func StartWxMsgParsers(workNum int)
- type BaseMsg
- type EventMsg
- type Msg
- type ReplyMsg
- type ReplyMsgBase
- type ReplyTextMsg
- type SubscribeEvent
- type SuccessTextMsg
- type TextMsg
- type ViewEvent
Constants ¶
View Source
const ( SUCCESS_TEXT = "success" // msgType MT_TEXT = "text" MT_EVENT = "event" // event type ET_SUBSCRIBE = "subscribe" ET_UNSUBSCRIBE = "unsubscribe" ET_VIEW = "VIEW" )
View Source
const ( SIGNATURE = iota TIMESTAMP NONCE )
Variables ¶
View Source
var ( HandleTextMsg = func(textMsg *TextMsg) ReplyMsg { return NewReplyTextMsg(textMsg.FromUserName, textMsg.ToUserName, textMsg.Content) } HandleViewEvent = func(viewEvent *ViewEvent) ReplyMsg { return NewSuccessMsg() } HandleSubscribeEvent = func(subscribeEvent *SubscribeEvent) ReplyMsg { return NewReplyTextMsg(subscribeEvent.FromUserName, subscribeEvent.ToUserName, "welcome") } HandleUnsubscribeEvent = func(subscribeEvent *SubscribeEvent) ReplyMsg { return NewSuccessMsg() } )
View Source
var MustSignatureArgs = []string{"signature", "timestamp", "nonce"}
Functions ¶
func EncryptReply ¶
根据响应消息生成加密消息
func GetMessageBody ¶
获取服务号收到的消息参数,返回 (消息体, 时间戳, nonce, error)
func GetRandomBytes ¶
func HashStrings ¶
func ParseMessageBody ¶
从GetMessageBody()独立出来,可以通过各种方式调用,方便调试
Types ¶
type ReplyMsgBase ¶
type ReplyTextMsg ¶
type ReplyTextMsg struct { ReplyMsgBase Content string }
---------- reply Text Message ---------------
func NewReplyTextMsg ¶
func NewReplyTextMsg(toUserName, fromUserName, content string) *ReplyTextMsg
func (*ReplyTextMsg) ToXML ¶
func (msg *ReplyTextMsg) ToXML() string
type SubscribeEvent ¶
subscribe, unsubscribe
type SuccessTextMsg ¶
type SuccessTextMsg struct { }
------------------ reply only "success" ----------
func NewSuccessMsg ¶
func NewSuccessMsg() *SuccessTextMsg
func (*SuccessTextMsg) ToXML ¶
func (msg *SuccessTextMsg) ToXML() string
Click to show internal directories.
Click to hide internal directories.