- weimob callback msg format
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package weimobapi
|
package weimobapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,12 +26,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CallbackMsg struct {
|
type CallbackMsg struct {
|
||||||
ID string `json:"id"`
|
IsFake bool `json:"isFake"` // 是否自己生成的假消息
|
||||||
MsgEvent string `json:"msgEvent"`
|
ID string `json:"id"`
|
||||||
PublicAccountID string `json:"public_account_id"`
|
MsgEvent string `json:"msgEvent"`
|
||||||
OrderNo int64 `json:"orderNo"`
|
PublicAccountID string `json:"public_account_id"`
|
||||||
StatusTime time.Time `json:"statusTime"`
|
BusinessID string `json:"business_id"`
|
||||||
ChannelType int `json:"channelType"`
|
|
||||||
|
OrderNo int64 `json:"orderNo"`
|
||||||
|
StatusTime time.Time `json:"statusTime"`
|
||||||
|
ChannelType int `json:"channelType"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorInfo struct {
|
type ErrorInfo struct {
|
||||||
@@ -63,6 +68,17 @@ func Err2CallbackResponse(err error, data string) *CallbackResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) CheckCallbackValidation(sign, msgSignature, id, msgBody string) bool {
|
||||||
|
localSign := fmt.Sprintf("%x", md5.Sum([]byte(a.appID+id+a.appSecret)))
|
||||||
|
// baseapi.SugarLogger.Debug(sign, ":", localSign)
|
||||||
|
if localSign == sign {
|
||||||
|
localSign := fmt.Sprintf("%x", md5.Sum([]byte(a.appID+id+msgBody+a.appSecret)))
|
||||||
|
// baseapi.SugarLogger.Debug(msgSignature, ":", localSign)
|
||||||
|
return localSign == msgSignature
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
||||||
var (
|
var (
|
||||||
mapMsg, msgBody map[string]interface{}
|
mapMsg, msgBody map[string]interface{}
|
||||||
@@ -71,7 +87,8 @@ func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Err2CallbackResponse(err, "")
|
return nil, Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
err = utils.UnmarshalUseNumber([]byte(mapMsg["msg_body"].(string)), &msgBody)
|
msgBodyStr := mapMsg["msg_body"].(string)
|
||||||
|
err = utils.UnmarshalUseNumber([]byte(msgBodyStr), &msgBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Err2CallbackResponse(err, "")
|
return nil, Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
@@ -79,13 +96,19 @@ func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *C
|
|||||||
ID: utils.Interface2String(mapMsg["id"]),
|
ID: utils.Interface2String(mapMsg["id"]),
|
||||||
MsgEvent: utils.Interface2String(mapMsg["event"]),
|
MsgEvent: utils.Interface2String(mapMsg["event"]),
|
||||||
PublicAccountID: utils.Interface2String(mapMsg["public_account_id"]),
|
PublicAccountID: utils.Interface2String(mapMsg["public_account_id"]),
|
||||||
|
BusinessID: utils.Interface2String(mapMsg["business_id"]),
|
||||||
OrderNo: utils.MustInterface2Int64(msgBody["orderNo"]),
|
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"), "")
|
||||||
|
}
|
||||||
if msg.MsgEvent == MsgEventCreateOrder {
|
if msg.MsgEvent == MsgEventCreateOrder {
|
||||||
msg.StatusTime = utils.Str2Time(strings.Replace(msgBody["createTime"].(string), ": ", ":", -1))
|
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()
|
||||||
}
|
}
|
||||||
return nil, SuccessResponse
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|||||||
30
platformapi/weimobapi/callback_test.go
Normal file
30
platformapi/weimobapi/callback_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package weimobapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetCallbackMsg(t *testing.T) {
|
||||||
|
rawMsg := `
|
||||||
|
{
|
||||||
|
"id": "91bae15f-2f8f-4eca-9f4d-793de40c74cf",
|
||||||
|
"topic": "ec_order",
|
||||||
|
"event": "createOrder",
|
||||||
|
"version": 1,
|
||||||
|
"sign": "e46b607913c93bd4c31a6e483785ef52",
|
||||||
|
"msgSignature": "b7a975d07a7b0b507ab01f862c4f7fec",
|
||||||
|
"test": false,
|
||||||
|
"business_id": "1224609670",
|
||||||
|
"public_account_id": "100000386048",
|
||||||
|
"msg_body": "{\"createTime\":\"2019-01-19 15:23:59\",\"channelType\":1,\"orderNo\":5330003015048}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
msg, response := api.GetCallbackMsg([]byte(rawMsg))
|
||||||
|
if response != nil {
|
||||||
|
t.Fatal("GetCallbackMsg failed")
|
||||||
|
}
|
||||||
|
baseapi.SugarLogger.Debug(utils.Format4Output(msg, false))
|
||||||
|
}
|
||||||
@@ -19,14 +19,6 @@ const (
|
|||||||
GoodsTypeOversea = 1
|
GoodsTypeOversea = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
OrderStatusWait4Pay = 0 // 待支付
|
|
||||||
OrderStatusPayed = 1 // 已付款,待发货
|
|
||||||
OrderStatusDelivering = 2 // 已发货
|
|
||||||
OrderStatusFinished = 3 // 已完成
|
|
||||||
OrderStatusCanceled = 4 // 已取消
|
|
||||||
)
|
|
||||||
|
|
||||||
type PendingSaveB2CGoodsVo struct {
|
type PendingSaveB2CGoodsVo struct {
|
||||||
FreightTemplateId int64 `json:"freightTemplateId"`
|
FreightTemplateId int64 `json:"freightTemplateId"`
|
||||||
DeliveryTypeIdList []int64 `json:"deliveryTypeIdList"`
|
DeliveryTypeIdList []int64 `json:"deliveryTypeIdList"`
|
||||||
@@ -70,11 +62,18 @@ type DeliveryType struct {
|
|||||||
Selected bool `json:"selected"`
|
Selected bool `json:"selected"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) QueryGoodsList(pageNum, pageSize int) (retVal []map[string]interface{}, totalCount int, err error) {
|
func (a *API) QueryGoodsList(pageNum, pageSize int, orderBy []map[string]interface{}, queryParameter map[string]interface{}) (retVal []map[string]interface{}, totalCount int, err error) {
|
||||||
result, err := a.AccessAPI("goods/queryGoodsList", map[string]interface{}{
|
apiParams := map[string]interface{}{
|
||||||
"pageNum": pageNum,
|
"pageNum": pageNum,
|
||||||
"pageSize": pageSize,
|
"pageSize": pageSize,
|
||||||
})
|
}
|
||||||
|
if orderBy != nil {
|
||||||
|
apiParams["orderBy"] = orderBy
|
||||||
|
}
|
||||||
|
if queryParameter != nil {
|
||||||
|
apiParams["queryParameter"] = queryParameter
|
||||||
|
}
|
||||||
|
result, err := a.AccessAPI("goods/queryGoodsList", apiParams)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if pageList, ok := result.(map[string]interface{})["pageList"].([]interface{}); ok {
|
if pageList, ok := result.(map[string]interface{})["pageList"].([]interface{}); ok {
|
||||||
retVal = utils.Slice2MapSlice(pageList)
|
retVal = utils.Slice2MapSlice(pageList)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestQueryGoodsList(t *testing.T) {
|
func TestQueryGoodsList(t *testing.T) {
|
||||||
result, totalCount, err := api.QueryGoodsList(1, 20)
|
result, totalCount, err := api.QueryGoodsList(1, 20, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,14 @@ import (
|
|||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrderStatusWait4Pay = 0 // 待支付
|
||||||
|
OrderStatusPayed = 1 // 已付款,待发货
|
||||||
|
OrderStatusDelivering = 2 // 已发货
|
||||||
|
OrderStatusFinished = 3 // 已完成
|
||||||
|
OrderStatusCanceled = 4 // 已取消
|
||||||
|
)
|
||||||
|
|
||||||
type DeliveryOrderItem struct {
|
type DeliveryOrderItem struct {
|
||||||
ItemId int64 `json:"itemId"`
|
ItemId int64 `json:"itemId"`
|
||||||
SkuId int64 `json:"skuId"`
|
SkuId int64 `json:"skuId"`
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ const (
|
|||||||
KeyEditStockNum = "editStockNum"
|
KeyEditStockNum = "editStockNum"
|
||||||
KeyB2cSku = "b2cSku"
|
KeyB2cSku = "b2cSku"
|
||||||
KeySkuAttrMap = "skuAttrMap"
|
KeySkuAttrMap = "skuAttrMap"
|
||||||
|
|
||||||
|
KeyField = "field"
|
||||||
|
KeySort = "sort"
|
||||||
|
|
||||||
|
KeyGoodsClassifyId = "goodsClassifyId"
|
||||||
|
KeySearch = "search"
|
||||||
|
KeyGoodsStatus = "goodsStatus"
|
||||||
|
KeyUpdateStartTime = "updateStartTime"
|
||||||
|
KeyUpdateEndTime = "updateEndTime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TokenInfo struct {
|
type TokenInfo struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user