From bc9707b8b624f5dcc0ed1e5fc55b76b45c9c6fba Mon Sep 17 00:00:00 2001 From: gazebo Date: Sat, 19 Jan 2019 12:01:09 +0800 Subject: [PATCH] - handle weimob createOrder and orderStatusChange correctly --- platformapi/weimobapi/callback.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/platformapi/weimobapi/callback.go b/platformapi/weimobapi/callback.go index d4c41459..d992cebf 100644 --- a/platformapi/weimobapi/callback.go +++ b/platformapi/weimobapi/callback.go @@ -1,6 +1,7 @@ package weimobapi import ( + "strings" "time" "git.rosy.net.cn/baseapi/utils" @@ -25,7 +26,7 @@ const ( type CallbackMsg struct { ID string `json:"id"` MsgEvent string `json:"msgEvent"` - PublicAccountID int64 `json:"public_account_id"` + PublicAccountID string `json:"public_account_id"` OrderNo int64 `json:"orderNo"` StatusTime time.Time `json:"statusTime"` 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) { - var mapMsg map[string]interface{} + var ( + mapMsg, msgBody map[string]interface{} + ) err := utils.UnmarshalUseNumber(body, &mapMsg) if err != nil { 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{ ID: utils.Interface2String(mapMsg["id"]), MsgEvent: utils.Interface2String(mapMsg["event"]), - PublicAccountID: utils.MustInterface2Int64(mapMsg["public_account_id"]), + PublicAccountID: utils.Interface2String(mapMsg["public_account_id"]), OrderNo: utils.MustInterface2Int64(msgBody["orderNo"]), } - 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"])) } else { msg.StatusTime = time.Now()