package elmapi import ( "fmt" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platform/common" "git.rosy.net.cn/baseapi/utils" "github.com/fatih/structs" ) const ( OrderValid = 10 MerchantValid = 12 OrderCanceled = 14 MerchantInvalid = 15 OrderForceInvalid = 17 OrderFinished = 18 ) type ELMCallbackResponse struct { Message string `json:"message"` } type ELMCallbackMsg struct { 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 ( SuccessResponse = &ELMCallbackResponse{"ok"} ) func (e *ELMAPI) unmarshalData(data []byte, msg interface{}) (callbackResponse *ELMCallbackResponse) { err := utils.UnmarshalUseNumber(data, msg) if err != nil { return &ELMCallbackResponse{ Message: fmt.Sprintf(common.CBErrMsgUnmarshal, data, err), } } return nil } func (e *ELMAPI) CheckCallbackValidation(mapData map[string]interface{}) (callbackResponse *ELMCallbackResponse) { sign := e.signParamsMap(mapData, "") 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) GetCallbackMsg(data []byte) (msg *ELMCallbackMsg, callbackResponse *ELMCallbackResponse) { msg = new(ELMCallbackMsg) if callbackResponse = e.unmarshalData(data, msg); callbackResponse != nil { return nil, callbackResponse } mapData := structs.Map(msg) callbackResponse = e.CheckCallbackValidation(mapData) return msg, callbackResponse }