forked from chanxuehong/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_handler.go
56 lines (42 loc) · 1.9 KB
/
msg_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// @description wechat 是腾讯微信公众平台 api 的 golang 语言封装
// @link https://github.com/c77cc/wechat for the canonical source repository
// @license https://github.com/c77cc/wechat/blob/master/LICENSE
// @authors c77cc(c77cc@gmail.com)
package component
import (
"net/http"
"net/url"
)
// 微信服务器推送过来的消息(事件)处理接口
type MessageHandler interface {
ServeMessage(w http.ResponseWriter, r *Request)
}
type MessageHandlerFunc func(http.ResponseWriter, *Request)
func (fn MessageHandlerFunc) ServeMessage(w http.ResponseWriter, r *Request) {
fn(w, r)
}
// 消息(事件)请求信息
type Request struct {
HttpRequest *http.Request // 可以为 nil, 因为某些 http 框架没有提供此参数
// 下面的字段必须提供
QueryValues url.Values // 回调请求 URL 中的查询参数集合
MsgSignature string // 请求 URL 中的消息体签名: msg_signature
EncryptType string // 请求 URL 中的加密方式: encrypt_type
Timestamp int64 // 回调请求 URL 中的时间戳: timestamp
Nonce string // 回调请求 URL 中的随机数: nonce
RawMsgXML []byte // 消息的"明文"XML 文本
MixedMsg *MixedMessage // RawMsgXML 解析后的消息
AESKey [32]byte // 当前消息 AES 加密的 key
Random []byte // 当前消息加密时所用的 random, 16 bytes
AppId string // 请求消息所属第三方平台的 ID
Token string // 请求消息所属第三方平台的 Token
}
// 微信服务器推送过来的消息(事件)的合集.
type MixedMessage struct {
XMLName struct{} `xml:"xml" json:"-"`
AppId string `xml:"AppId" json:"AppId"`
CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
InfoType string `xml:"InfoType" json:"InfoType"`
VerifyTicket string `xml:"VerifyTicket" json:"VerifyTicket"`
AuthorizerAppid string `xml:"AuthorizerAppid" json:"AuthorizerAppid"`
}