- dadaapi added.
- refactor.
This commit is contained in:
@@ -23,14 +23,14 @@ type ELMCallbackResponse struct {
|
||||
}
|
||||
|
||||
type ELMCallbackMsg struct {
|
||||
AppId int `json:"appId" structs:"appId"`
|
||||
RequestId string `json:"requestId" structs:"requestId"`
|
||||
Type int `json:"type" structs:"type"`
|
||||
Message string `json:"message" structs:"message"`
|
||||
ShopId int `json:"shopId" structs:"shopId"`
|
||||
Timestamp int64 `json:"timestamp" structs:"timestamp"`
|
||||
UserId int64 `json:"userId" structs:"userId"`
|
||||
Signature string `json:"signature" structs:"signature"`
|
||||
AppId int `json:"appId"`
|
||||
RequestId string `json:"requestId"`
|
||||
Type int `json:"type"`
|
||||
Message string `json:"message"`
|
||||
ShopId int `json:"shopId"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
UserId int64 `json:"userId"`
|
||||
Signature string `json:"signature"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -47,23 +47,22 @@ func (e *ELMAPI) unmarshalData(data []byte, msg interface{}) (callbackResponse *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *ELMAPI) CheckRequestValidation(mapData map[string]interface{}) (callbackResponse *ELMCallbackResponse) {
|
||||
func (e *ELMAPI) CheckCallbackValidation(mapData map[string]interface{}) (callbackResponse *ELMCallbackResponse) {
|
||||
sign := e.signParamsMap(mapData, "")
|
||||
if remoteSign, ok := mapData[signKey].(string); ok && sign != remoteSign {
|
||||
if remoteSign, _ := mapData[signKey].(string); sign != remoteSign {
|
||||
baseapi.SugarLogger.Infof("Signature is not ok, mine:%v, get:%v", sign, remoteSign)
|
||||
return &ELMCallbackResponse{Message: "signature is invalid"}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *ELMAPI) GetMsgFromData(data []byte) (msg *ELMCallbackMsg, callbackResponse *ELMCallbackResponse) {
|
||||
func (e *ELMAPI) GetCallbackMsg(data []byte) (msg *ELMCallbackMsg, callbackResponse *ELMCallbackResponse) {
|
||||
msg = new(ELMCallbackMsg)
|
||||
callbackResponse = e.unmarshalData(data, msg)
|
||||
if callbackResponse != nil {
|
||||
if callbackResponse = e.unmarshalData(data, msg); callbackResponse != nil {
|
||||
return nil, callbackResponse
|
||||
}
|
||||
|
||||
mapData := structs.Map(msg)
|
||||
callbackResponse = e.CheckRequestValidation(mapData)
|
||||
callbackResponse = e.CheckCallbackValidation(mapData)
|
||||
return msg, callbackResponse
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user