|
@@ -7,11 +7,9 @@ import (
|
|
|
"eta/eta_hub/utils"
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/server/web"
|
|
|
- "github.com/shopspring/decimal"
|
|
|
"github.com/sirupsen/logrus"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
- "reflect"
|
|
|
)
|
|
|
|
|
|
type BaseAuthController struct {
|
|
@@ -24,105 +22,54 @@ func (this *BaseAuthController) Prepare() {
|
|
|
uri := this.Ctx.Input.URI()
|
|
|
fmt.Println("Url:", uri)
|
|
|
if method != "HEAD" {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ nonce := this.Ctx.Input.Header("nonce")
|
|
|
+ timestamp := this.Ctx.Input.Header("timestamp")
|
|
|
+ appid := this.Ctx.Input.Header("appid")
|
|
|
+ signature := this.Ctx.Input.Header("signature")
|
|
|
+
|
|
|
+ if nonce == "" {
|
|
|
+ errMsg := "随机字符串不能为空"
|
|
|
+ this.JSON(models.BaseResponse{Ret: 400, Msg: "", ErrMsg: errMsg}, false, false)
|
|
|
+ this.StopRun()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if timestamp == "" {
|
|
|
+ errMsg := "时间戳不能为空"
|
|
|
+ this.JSON(models.BaseResponse{Ret: 400, Msg: "", ErrMsg: errMsg}, false, false)
|
|
|
+ this.StopRun()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if appid != utils.AppId {
|
|
|
+ errMsg := "商家AppId错误,请核查"
|
|
|
+ this.JSON(models.BaseResponse{Ret: 400, Msg: "", ErrMsg: errMsg}, false, false)
|
|
|
+ this.StopRun()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ checkSign := utils.GetSign(nonce, timestamp)
|
|
|
+ if signature != checkSign {
|
|
|
+ errMsg := "签名错误"
|
|
|
+ this.JSON(models.BaseResponse{Ret: 401, Msg: "", ErrMsg: errMsg}, false, false)
|
|
|
+ this.StopRun()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if method != "GET" && method != "POST" {
|
|
|
+ errMsg := "无效的请求方式"
|
|
|
+ this.JSON(models.BaseResponse{Ret: 501, Msg: "", ErrMsg: errMsg}, false, false)
|
|
|
+ this.StopRun()
|
|
|
+ return
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.JSON(models.BaseResponse{Ret: 408, Msg: "请求异常,请联系客服!", ErrMsg: "method:" + method}, false, false)
|
|
|
+ this.JSON(models.BaseResponse{Ret: 500, Msg: "系统异常,请联系客服!", ErrMsg: "method:" + method}, false, false)
|
|
|
this.StopRun()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
func (c *BaseAuthController) ServeJSON(encoding ...bool) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
var (
|
|
|
hasIndent = false
|
|
@@ -186,47 +133,6 @@ func (c *BaseAuthController) JSON(data interface{}, hasIndent bool, coding bool)
|
|
|
return c.Ctx.Output.Body(content)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func convertParam(params map[string][]string) (signData map[string]string) {
|
|
|
- signData = make(map[string]string)
|
|
|
- for key := range params {
|
|
|
- signData[key] = params[key][0]
|
|
|
- }
|
|
|
- return signData
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func convertParamInterface(params map[string]interface{}) (signData map[string]string) {
|
|
|
- signData = make(map[string]string)
|
|
|
- for key := range params {
|
|
|
- val := ``
|
|
|
-
|
|
|
-
|
|
|
- tmpVal := params[key]
|
|
|
- switch reflect.TypeOf(tmpVal).Kind() {
|
|
|
- case reflect.String:
|
|
|
- val = fmt.Sprint(tmpVal)
|
|
|
- case reflect.Int, reflect.Int16, reflect.Int64, reflect.Int32, reflect.Int8:
|
|
|
- val = fmt.Sprint(tmpVal)
|
|
|
- case reflect.Uint, reflect.Uint32, reflect.Uint16, reflect.Uint8, reflect.Uint64:
|
|
|
- val = fmt.Sprint(tmpVal)
|
|
|
- case reflect.Bool:
|
|
|
- val = fmt.Sprint(tmpVal)
|
|
|
- case reflect.Float64:
|
|
|
- decimalNum := decimal.NewFromFloat(tmpVal.(float64))
|
|
|
- val = decimalNum.String()
|
|
|
-
|
|
|
- case reflect.Float32:
|
|
|
- decimalNum := decimal.NewFromFloat32(tmpVal.(float32))
|
|
|
- val = decimalNum.String()
|
|
|
- }
|
|
|
- signData[key] = val
|
|
|
- }
|
|
|
- return signData
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
func (c *BaseAuthController) logUri(data interface{}, requestBody, ip string) {
|
|
|
var reqData interface{}
|
|
|
err := json.Unmarshal([]byte(requestBody), &reqData)
|