From 3cbfb7bde7e3571a275d3f7e503afb64d05d2c5f Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 15:05:22 +0800 Subject: [PATCH] =?UTF-8?q?weimobapi.CallbackMsg=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0MsgBody?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/weimobapi/callback.go | 47 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/platformapi/weimobapi/callback.go b/platformapi/weimobapi/callback.go index 7070c359..4d09d1eb 100644 --- a/platformapi/weimobapi/callback.go +++ b/platformapi/weimobapi/callback.go @@ -34,6 +34,19 @@ const ( ChannelTypeOffline = 7 ) +const ( + MsgOrderStatusWait4Pay = 0 // 未支付 + MsgOrderStatusPartPayed = 1 // 部分支付 + MsgOrderStatusPayed = 2 // 已支付 + MsgOrderStatusCanDeliver = 3 // 可发货 + MsgOrderStatusPartDelivering = 4 // 部分发货 + MsgOrderStatusDelivering = 5 // 已发货 + MsgOrderStatusPartDelivered = 6 // 部分确认收货 + MsgOrderStatusDelivered = 7 // 确认收货 + MsgOrderStatusFinished = 8 // 完成(不能再申请售后) + MsgOrderStatusCancled = 9 // 取消 +) + type CallbackMsg struct { IsFake bool `json:"isFake"` // 是否自己生成的假消息 ID string `json:"id"` @@ -41,12 +54,17 @@ type CallbackMsg struct { Event string `json:"event"` PublicAccountID string `json:"public_account_id"` BusinessID string `json:"business_id"` + Sign string `json:"sign"` + MsgSignature string `json:"msgSignature"` StoreID int64 `json:"storeId"` RightsID int64 `json:"rightsId"` OrderNo int64 `json:"orderNo"` StatusTime time.Time `json:"statusTime"` ChannelType int `json:"channelType"` + + MsgBody map[string]interface{} `json:"msgBody"` + MsgBodyStr string `json:"msg_body"` } type ErrorInfo struct { @@ -92,39 +110,26 @@ func (a *API) CheckCallbackValidation(sign, msgSignature, id, msgBody string) bo } func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *CallbackResponse) { - var ( - mapMsg, msgBody map[string]interface{} - ) - err := utils.UnmarshalUseNumber(body, &mapMsg) + err := utils.UnmarshalUseNumber(body, &msg) if err != nil { return nil, Err2CallbackResponse(err, "") } - msgBodyStr := mapMsg["msg_body"].(string) - err = utils.UnmarshalUseNumber([]byte(msgBodyStr), &msgBody) + err = utils.UnmarshalUseNumber([]byte(msg.MsgBodyStr), &msg.MsgBody) if err != nil { return nil, Err2CallbackResponse(err, "") } - msg = &CallbackMsg{ - ID: utils.Interface2String(mapMsg["id"]), - Topic: utils.Interface2String(mapMsg["topic"]), - Event: utils.Interface2String(mapMsg["event"]), - PublicAccountID: utils.Interface2String(mapMsg["public_account_id"]), - BusinessID: utils.Interface2String(mapMsg["business_id"]), - OrderNo: utils.MustInterface2Int64(msgBody["orderNo"]), - } - sign := utils.Interface2String(mapMsg["sign"]) - msgSignature := utils.Interface2String(mapMsg["msgSignature"]) - if !a.CheckCallbackValidation(sign, msgSignature, msg.ID, msgBodyStr) { + msg.OrderNo = utils.MustInterface2Int64(msg.MsgBody["orderNo"]) + if !a.CheckCallbackValidation(msg.Sign, msg.MsgSignature, msg.ID, msg.MsgBodyStr) { return nil, Err2CallbackResponse(fmt.Errorf("sign is not match"), "") } if msg.Event == MsgEventCreateOrder { - msg.StatusTime = utils.Str2Time(strings.Replace(msgBody["createTime"].(string), ": ", ":", -1)) - msg.ChannelType = int(utils.MustInterface2Int64(msgBody["channelType"])) + msg.StatusTime = utils.Str2Time(strings.Replace(msg.MsgBody["createTime"].(string), ": ", ":", -1)) + msg.ChannelType = int(utils.MustInterface2Int64(msg.MsgBody["channelType"])) } else { msg.StatusTime = time.Now() if msg.Topic == MsgTopicRights { - msg.RightsID = utils.MustInterface2Int64(msgBody["rightsId"]) - msg.StoreID = utils.MustInterface2Int64(msgBody["storeId"]) + msg.RightsID = utils.MustInterface2Int64(msg.MsgBody["rightsId"]) + msg.StoreID = utils.MustInterface2Int64(msg.MsgBody["storeId"]) } } return msg, nil