37 lines
835 B
Go
37 lines
835 B
Go
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)
|
|
}
|
|
}
|