Browse Source

wechat server validate

ls 4 years ago
parent
commit
0ae6720930
1 changed files with 7 additions and 2 deletions
  1. 7 2
      wechat/server.go

+ 7 - 2
wechat/server.go

@@ -20,9 +20,14 @@ func NewServer(appID, appSecret, token, encodingAESKey string) *Server {
 }
 
 // Echo notify echo GET
-func (wc Server) Echo(s FormSignature) (data string, err error) {
-	if ok := makeSignature(wc.Token, s.Signature, s.TimeStamp, s.Nonce); ok {
+func (ws Server) Echo(s FormSignature) (data string, err error) {
+	if ok := makeSignature(ws.Token, s.Signature, s.TimeStamp, s.Nonce); ok {
 		data = s.Echostr
 	}
 	return
 }
+
+// Validate 验证请求合法性
+func (ws Server) Validate(signature, timestamp, nonce string) bool {
+	return makeSignature(ws.Token, signature, timestamp, nonce)
+}