- refactor platform apis.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user