feat: add middlewares

This commit is contained in:
Rogee
2024-12-06 17:15:28 +08:00
parent 29894cff9c
commit 869625d70a
10 changed files with 169 additions and 125 deletions

View File

@@ -0,0 +1,33 @@
package middlewares
import (
"github.com/gofiber/fiber/v3"
log "github.com/sirupsen/logrus"
)
// 此方法用于微信首次接入时的数据验证
func (f *Middlewares) WeChatVerify(c fiber.Ctx) error {
// get the query parameters
signature := c.Query("signature")
timestamp := c.Query("timestamp")
nonce := c.Query("nonce")
echostr := c.Query("echostr")
if signature == "" || timestamp == "" || nonce == "" || echostr == "" {
return c.Next()
}
log.WithField("method", "Verify").WithFields(log.Fields{
"signature": signature,
"timestamp": timestamp,
"nonce": nonce,
"echostr": echostr,
}).Debug("begin verify signature")
// verify the signature
if err := f.client.Verify(signature, timestamp, nonce); err != nil {
return c.SendString(err.Error())
}
return c.SendString(echostr)
}