Files
baseapi/platform/elmapi/callback.go
2018-06-18 11:47:20 +08:00

56 lines
1.2 KiB
Go

package elmapi
import (
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi/platform/common"
)
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 := json.Unmarshal(data, msg)
if err != nil {
return &ELMCallbackResponse{
Message: fmt.Sprintf(common.CBErrMsgUnmarshal, data, err),
}
}
return nil
}
func (e *ELMAPI) GetMsgFromData(data []byte) (msg *ELMCallbackMsg, callbackResponse *ELMCallbackResponse) {
msg = new(ELMCallbackMsg)
callbackResponse = e.unmarshalData(data, msg)
if callbackResponse != nil {
return nil, callbackResponse
}
return msg, nil
}