|
12345678910111213141516171819202122232425262728 |
- package mw
-
- import (
- "applet/app/cfg"
- "applet/app/e"
- "applet/app/lib/aes"
- "applet/app/lib/aes/md"
- "applet/app/utils"
- "errors"
- "github.com/gin-gonic/gin"
- )
-
- // CheckSign is 中间件 用来检查签名
- func CheckSign(c *gin.Context) {
- if !(utils.GenerateMD5Hash(c.Request.Host) == md.ConvenientKeyForTest || (c.GetHeader("is_check") == "false" && !cfg.Prd)) {
- err := aes.CheckSign(c)
- if err != nil {
- if cfg.Prd {
- e.OutErr(c, 400, errors.New("请求失败~~"))
- } else {
- e.OutErr(c, 400, "验签失败: "+err.Error())
- }
- return
- }
- c.Next()
- c.Set("is_sign", true)
- }
- }
|