package wsign import ( "errors" "fmt" "github.com/gin-gonic/gin" "io/ioutil" "service/bizcommon/util" ) const ( Salt = "6%dkszcU*&lk@#$T#(lknkj.359" ) func CalcSignature(s string) (signature string, err error) { if len([]rune(s)) <= 0 { return } if len([]rune(s)) <= 20 { err = errors.New(fmt.Sprintf("to short s: %s", s)) return } payload := []rune(s + Salt) l := len(payload) a1 := string(payload[:10]) a2 := string(payload[10 : l-10]) a3 := string(payload[l-10:]) signature = util.StringToMd5(a1 + a3 + a2) return } func CheckSignature(ctx *gin.Context) bool { signature := ctx.Query("signature") if len(signature) <= 0 { return false } if signature == "wishpalgogogo" { return true } bs, _ := ioutil.ReadAll(ctx.Request.Body) calcSignature, err := CalcSignature(string(bs)) if err != nil { return false } if signature != calcSignature { return false } return true }