weimobapi.CallbackMsg中添加MsgBody
This commit is contained in:
@@ -34,6 +34,19 @@ const (
|
|||||||
ChannelTypeOffline = 7
|
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 {
|
type CallbackMsg struct {
|
||||||
IsFake bool `json:"isFake"` // 是否自己生成的假消息
|
IsFake bool `json:"isFake"` // 是否自己生成的假消息
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
@@ -41,12 +54,17 @@ type CallbackMsg struct {
|
|||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
PublicAccountID string `json:"public_account_id"`
|
PublicAccountID string `json:"public_account_id"`
|
||||||
BusinessID string `json:"business_id"`
|
BusinessID string `json:"business_id"`
|
||||||
|
Sign string `json:"sign"`
|
||||||
|
MsgSignature string `json:"msgSignature"`
|
||||||
|
|
||||||
StoreID int64 `json:"storeId"`
|
StoreID int64 `json:"storeId"`
|
||||||
RightsID int64 `json:"rightsId"`
|
RightsID int64 `json:"rightsId"`
|
||||||
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"`
|
||||||
|
|
||||||
|
MsgBody map[string]interface{} `json:"msgBody"`
|
||||||
|
MsgBodyStr string `json:"msg_body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorInfo struct {
|
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) {
|
func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
||||||
var (
|
err := utils.UnmarshalUseNumber(body, &msg)
|
||||||
mapMsg, msgBody map[string]interface{}
|
|
||||||
)
|
|
||||||
err := utils.UnmarshalUseNumber(body, &mapMsg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Err2CallbackResponse(err, "")
|
return nil, Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
msgBodyStr := mapMsg["msg_body"].(string)
|
err = utils.UnmarshalUseNumber([]byte(msg.MsgBodyStr), &msg.MsgBody)
|
||||||
err = utils.UnmarshalUseNumber([]byte(msgBodyStr), &msgBody)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Err2CallbackResponse(err, "")
|
return nil, Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
msg = &CallbackMsg{
|
msg.OrderNo = utils.MustInterface2Int64(msg.MsgBody["orderNo"])
|
||||||
ID: utils.Interface2String(mapMsg["id"]),
|
if !a.CheckCallbackValidation(msg.Sign, msg.MsgSignature, msg.ID, msg.MsgBodyStr) {
|
||||||
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) {
|
|
||||||
return nil, Err2CallbackResponse(fmt.Errorf("sign is not match"), "")
|
return nil, Err2CallbackResponse(fmt.Errorf("sign is not match"), "")
|
||||||
}
|
}
|
||||||
if msg.Event == MsgEventCreateOrder {
|
if msg.Event == MsgEventCreateOrder {
|
||||||
msg.StatusTime = utils.Str2Time(strings.Replace(msgBody["createTime"].(string), ": ", ":", -1))
|
msg.StatusTime = utils.Str2Time(strings.Replace(msg.MsgBody["createTime"].(string), ": ", ":", -1))
|
||||||
msg.ChannelType = int(utils.MustInterface2Int64(msgBody["channelType"]))
|
msg.ChannelType = int(utils.MustInterface2Int64(msg.MsgBody["channelType"]))
|
||||||
} else {
|
} else {
|
||||||
msg.StatusTime = time.Now()
|
msg.StatusTime = time.Now()
|
||||||
if msg.Topic == MsgTopicRights {
|
if msg.Topic == MsgTopicRights {
|
||||||
msg.RightsID = utils.MustInterface2Int64(msgBody["rightsId"])
|
msg.RightsID = utils.MustInterface2Int64(msg.MsgBody["rightsId"])
|
||||||
msg.StoreID = utils.MustInterface2Int64(msgBody["storeId"])
|
msg.StoreID = utils.MustInterface2Int64(msg.MsgBody["storeId"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return msg, nil
|
return msg, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user