- weimob callback msg format
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package weimobapi
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -24,12 +26,15 @@ const (
|
||||
)
|
||||
|
||||
type CallbackMsg struct {
|
||||
ID string `json:"id"`
|
||||
MsgEvent string `json:"msgEvent"`
|
||||
PublicAccountID string `json:"public_account_id"`
|
||||
OrderNo int64 `json:"orderNo"`
|
||||
StatusTime time.Time `json:"statusTime"`
|
||||
ChannelType int `json:"channelType"`
|
||||
IsFake bool `json:"isFake"` // 是否自己生成的假消息
|
||||
ID string `json:"id"`
|
||||
MsgEvent string `json:"msgEvent"`
|
||||
PublicAccountID string `json:"public_account_id"`
|
||||
BusinessID string `json:"business_id"`
|
||||
|
||||
OrderNo int64 `json:"orderNo"`
|
||||
StatusTime time.Time `json:"statusTime"`
|
||||
ChannelType int `json:"channelType"`
|
||||
}
|
||||
|
||||
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) {
|
||||
var (
|
||||
mapMsg, msgBody map[string]interface{}
|
||||
@@ -71,7 +87,8 @@ func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *C
|
||||
if err != nil {
|
||||
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 {
|
||||
return nil, Err2CallbackResponse(err, "")
|
||||
}
|
||||
@@ -79,13 +96,19 @@ func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *C
|
||||
ID: utils.Interface2String(mapMsg["id"]),
|
||||
MsgEvent: 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"), "")
|
||||
}
|
||||
if msg.MsgEvent == MsgEventCreateOrder {
|
||||
msg.StatusTime = utils.Str2Time(strings.Replace(msgBody["createTime"].(string), ": ", ":", -1))
|
||||
msg.ChannelType = int(utils.MustInterface2Int64(msgBody["channelType"]))
|
||||
} else {
|
||||
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
|
||||
)
|
||||
|
||||
const (
|
||||
OrderStatusWait4Pay = 0 // 待支付
|
||||
OrderStatusPayed = 1 // 已付款,待发货
|
||||
OrderStatusDelivering = 2 // 已发货
|
||||
OrderStatusFinished = 3 // 已完成
|
||||
OrderStatusCanceled = 4 // 已取消
|
||||
)
|
||||
|
||||
type PendingSaveB2CGoodsVo struct {
|
||||
FreightTemplateId int64 `json:"freightTemplateId"`
|
||||
DeliveryTypeIdList []int64 `json:"deliveryTypeIdList"`
|
||||
@@ -70,11 +62,18 @@ type DeliveryType struct {
|
||||
Selected bool `json:"selected"`
|
||||
}
|
||||
|
||||
func (a *API) QueryGoodsList(pageNum, pageSize int) (retVal []map[string]interface{}, totalCount int, err error) {
|
||||
result, err := a.AccessAPI("goods/queryGoodsList", map[string]interface{}{
|
||||
func (a *API) QueryGoodsList(pageNum, pageSize int, orderBy []map[string]interface{}, queryParameter map[string]interface{}) (retVal []map[string]interface{}, totalCount int, err error) {
|
||||
apiParams := map[string]interface{}{
|
||||
"pageNum": pageNum,
|
||||
"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 pageList, ok := result.(map[string]interface{})["pageList"].([]interface{}); ok {
|
||||
retVal = utils.Slice2MapSlice(pageList)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestQueryGoodsList(t *testing.T) {
|
||||
result, totalCount, err := api.QueryGoodsList(1, 20)
|
||||
result, totalCount, err := api.QueryGoodsList(1, 20, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,14 @@ import (
|
||||
"github.com/fatih/structs"
|
||||
)
|
||||
|
||||
const (
|
||||
OrderStatusWait4Pay = 0 // 待支付
|
||||
OrderStatusPayed = 1 // 已付款,待发货
|
||||
OrderStatusDelivering = 2 // 已发货
|
||||
OrderStatusFinished = 3 // 已完成
|
||||
OrderStatusCanceled = 4 // 已取消
|
||||
)
|
||||
|
||||
type DeliveryOrderItem struct {
|
||||
ItemId int64 `json:"itemId"`
|
||||
SkuId int64 `json:"skuId"`
|
||||
|
||||
@@ -38,6 +38,15 @@ const (
|
||||
KeyEditStockNum = "editStockNum"
|
||||
KeyB2cSku = "b2cSku"
|
||||
KeySkuAttrMap = "skuAttrMap"
|
||||
|
||||
KeyField = "field"
|
||||
KeySort = "sort"
|
||||
|
||||
KeyGoodsClassifyId = "goodsClassifyId"
|
||||
KeySearch = "search"
|
||||
KeyGoodsStatus = "goodsStatus"
|
||||
KeyUpdateStartTime = "updateStartTime"
|
||||
KeyUpdateEndTime = "updateEndTime"
|
||||
)
|
||||
|
||||
type TokenInfo struct {
|
||||
|
||||
Reference in New Issue
Block a user