- refactor platform apis.

This commit is contained in:
gazebo
2018-06-18 11:47:20 +08:00
parent db287fb025
commit 03574f0f9d
7 changed files with 220 additions and 42 deletions

View File

@@ -1,5 +1,12 @@
package elmapi
import (
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi/platform/common"
)
const (
OrderValid = 10
MerchantValid = 12
@@ -25,5 +32,24 @@ type ELMCallbackMsg struct {
}
var (
ELMResponseOK = &ELMCallbackResponse{"ok"}
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
}