feat: complete auth
This commit is contained in:
@@ -1,36 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.ipao.vip/rogeecn/mp-qvyun/pkg/wechat"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
)
|
||||
|
||||
func VerifyWechatServer(wechatClient *wechat.Client) fiber.Handler {
|
||||
return func(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.Infof(
|
||||
"begin verify signature, signature: %s, timestamp: %s, nonce: %s, echostr: %s",
|
||||
signature,
|
||||
timestamp,
|
||||
nonce,
|
||||
echostr,
|
||||
)
|
||||
|
||||
// verify the signature
|
||||
if err := wechatClient.VerifyServer(signature, timestamp, nonce); err != nil {
|
||||
return c.SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.SendString(echostr)
|
||||
}
|
||||
func LogAll(c fiber.Ctx) error {
|
||||
log.Info("------------------------------------------")
|
||||
log.Infof("Request Method: %s", c.Method())
|
||||
log.Infof("Request Headers: %s", &c.Request().Header)
|
||||
log.Infof("Request URL: %s", c.OriginalURL())
|
||||
log.Infof("Request Query: %+v", c.Queries())
|
||||
log.Infof("Request Body: %s", c.BodyRaw())
|
||||
log.Info("------------------------------------------")
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user