weimobapi.CallbackMsg中添加MsgBody

This commit is contained in:
gazebo
2019-10-31 15:05:22 +08:00
parent d4dc1d3fbb
commit 3cbfb7bde7

View File

@@ -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