34 lines
821 B
Go
34 lines
821 B
Go
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)
|
|
}
|