Commit 7d5ea99b authored by shajiaiming's avatar shajiaiming

md5 encrypt

parent 3e58950d
...@@ -2,9 +2,9 @@ package md5 ...@@ -2,9 +2,9 @@ package md5
import ( import (
config "bwallet/conf" config "bwallet/conf"
"bwallet/pkg/errno"
"bwallet/pkg/handler" "bwallet/pkg/handler"
"bwallet/pkg/util" "bwallet/pkg/util"
"errors"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/url" "net/url"
...@@ -40,18 +40,18 @@ func Md5() gin.HandlerFunc { ...@@ -40,18 +40,18 @@ func Md5() gin.HandlerFunc {
// 验证签名 // 验证签名
func verifySign(c *gin.Context) (map[string]string, error) { func verifySign(c *gin.Context) (map[string]string, error) {
_ = c.Request.ParseForm() _ = c.Request.ParseForm()
req := c.Request.Form req := c.Request.Form
debug := strings.Join(c.Request.Form["debug"], "") debug := strings.Join(c.Request.Form["debug"], "")
ak := strings.Join(c.Request.Form["ak"], "") ak := strings.Join(c.Request.Form["ak"], "")
sn := strings.Join(c.Request.Form["sn"], "") sn := strings.Join(c.Request.Form["sn"], "")
ts := strings.Join(c.Request.Form["ts"], "") ts := strings.Join(c.Request.Form["ts"], "")
// 验证来源 // 验证来源
value, ok := config.ApiAuthConfig[ak] value, ok := config.ApiAuthConfig[ak]
if ok { if ok {
AppSecret = value["md5"] AppSecret = value["md5"]
} else { } else {
return nil, errno.ErrAk return nil, errors.New("ak Error")
} }
if debug == "1" { if debug == "1" {
...@@ -66,15 +66,15 @@ func verifySign(c *gin.Context) (map[string]string, error) { ...@@ -66,15 +66,15 @@ func verifySign(c *gin.Context) (map[string]string, error) {
// 验证过期时间 // 验证过期时间
timestamp := time.Now().Unix() timestamp := time.Now().Unix()
exp, _ := strconv.ParseInt(config.AppSignExpiry, 10, 64) exp, _ := strconv.ParseInt(config.AppSignExpiry, 10, 64)
tsInt, _ := strconv.ParseInt(ts, 10, 64) tsInt, _ := strconv.ParseInt(ts, 10, 64)
if tsInt > timestamp || timestamp-tsInt >= exp { if tsInt > timestamp || timestamp - tsInt >= exp {
return nil, errno.ErrTs return nil, errors.New("ts Error")
} }
// 验证签名 // 验证签名
if sn == "" || sn != createSign(req) { if sn == "" || sn != createSign(req) {
return nil, errno.ErrSn return nil, errors.New("sn Error")
} }
return nil, nil 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