Commit 7d5ea99b authored by shajiaiming's avatar shajiaiming

md5 encrypt

parent 3e58950d
......@@ -2,9 +2,9 @@ package md5
import (
config "bwallet/conf"
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"net/url"
......@@ -40,18 +40,18 @@ func Md5() gin.HandlerFunc {
// 验证签名
func verifySign(c *gin.Context) (map[string]string, error) {
_ = c.Request.ParseForm()
req := c.Request.Form
req := c.Request.Form
debug := strings.Join(c.Request.Form["debug"], "")
ak := strings.Join(c.Request.Form["ak"], "")
sn := strings.Join(c.Request.Form["sn"], "")
ts := strings.Join(c.Request.Form["ts"], "")
ak := strings.Join(c.Request.Form["ak"], "")
sn := strings.Join(c.Request.Form["sn"], "")
ts := strings.Join(c.Request.Form["ts"], "")
// 验证来源
value, ok := config.ApiAuthConfig[ak]
if ok {
AppSecret = value["md5"]
} else {
return nil, errno.ErrAk
return nil, errors.New("ak Error")
}
if debug == "1" {
......@@ -66,15 +66,15 @@ func verifySign(c *gin.Context) (map[string]string, error) {
// 验证过期时间
timestamp := time.Now().Unix()
exp, _ := strconv.ParseInt(config.AppSignExpiry, 10, 64)
tsInt, _ := strconv.ParseInt(ts, 10, 64)
if tsInt > timestamp || timestamp-tsInt >= exp {
return nil, errno.ErrTs
exp, _ := strconv.ParseInt(config.AppSignExpiry, 10, 64)
tsInt, _ := strconv.ParseInt(ts, 10, 64)
if tsInt > timestamp || timestamp - tsInt >= exp {
return nil, errors.New("ts Error")
}
// 验证签名
if sn == "" || sn != createSign(req) {
return nil, errno.ErrSn
return nil, errors.New("sn Error")
}
return nil, nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment