- handle weimob createOrder and orderStatusChange correctly
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package weimobapi
|
package weimobapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -25,7 +26,7 @@ const (
|
|||||||
type CallbackMsg struct {
|
type CallbackMsg struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
MsgEvent string `json:"msgEvent"`
|
MsgEvent string `json:"msgEvent"`
|
||||||
PublicAccountID int64 `json:"public_account_id"`
|
PublicAccountID string `json:"public_account_id"`
|
||||||
OrderNo int64 `json:"orderNo"`
|
OrderNo int64 `json:"orderNo"`
|
||||||
StatusTime time.Time `json:"statusTime"`
|
StatusTime time.Time `json:"statusTime"`
|
||||||
ChannelType int `json:"channelType"`
|
ChannelType int `json:"channelType"`
|
||||||
@@ -63,21 +64,25 @@ func Err2CallbackResponse(err error, data string) *CallbackResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
||||||
var mapMsg map[string]interface{}
|
var (
|
||||||
|
mapMsg, msgBody map[string]interface{}
|
||||||
|
)
|
||||||
err := utils.UnmarshalUseNumber(body, &mapMsg)
|
err := utils.UnmarshalUseNumber(body, &mapMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Err2CallbackResponse(err, "")
|
return nil, Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
msgBody := mapMsg["msg_body"].(map[string]interface{})
|
err = utils.UnmarshalUseNumber([]byte(mapMsg["msg_body"].(string)), &msgBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, Err2CallbackResponse(err, "")
|
||||||
|
}
|
||||||
msg = &CallbackMsg{
|
msg = &CallbackMsg{
|
||||||
ID: utils.Interface2String(mapMsg["id"]),
|
ID: utils.Interface2String(mapMsg["id"]),
|
||||||
MsgEvent: utils.Interface2String(mapMsg["event"]),
|
MsgEvent: utils.Interface2String(mapMsg["event"]),
|
||||||
PublicAccountID: utils.MustInterface2Int64(mapMsg["public_account_id"]),
|
PublicAccountID: utils.Interface2String(mapMsg["public_account_id"]),
|
||||||
OrderNo: utils.MustInterface2Int64(msgBody["orderNo"]),
|
OrderNo: utils.MustInterface2Int64(msgBody["orderNo"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.MsgEvent == MsgEventCreateOrder {
|
if msg.MsgEvent == MsgEventCreateOrder {
|
||||||
// msg.StatusTime = msgBody["createTime"]
|
msg.StatusTime = utils.Str2Time(strings.Replace(msgBody["createTime"].(string), ": ", ":", -1))
|
||||||
msg.ChannelType = int(utils.MustInterface2Int64(msgBody["channelType"]))
|
msg.ChannelType = int(utils.MustInterface2Int64(msgBody["channelType"]))
|
||||||
} else {
|
} else {
|
||||||
msg.StatusTime = time.Now()
|
msg.StatusTime = time.Now()
|
||||||
|
|||||||
Reference in New Issue
Block a user