修改回调

This commit is contained in:
邹宗楠
2022-04-01 13:49:07 +08:00
parent 2a75965a36
commit 5eb624afb4
2 changed files with 43 additions and 23 deletions

View File

@@ -37,10 +37,10 @@ func Err2CallbackResponse(err error, data string) *CallbackResponse {
} }
type ShortStatus struct { type ShortStatus struct {
AppId string `json:"app_id"` AppId string `json:"app_id"`
Signature string `json:"signature"` Signature string `json:"signature"`
Timestamp string `json:"timestamp"` Timestamp string `json:"timestamp"`
BusinessData interface{} `json:"business_data"` BusinessData string `json:"business_data"`
} }
// 门店状态回调 // 门店状态回调
@@ -61,8 +61,8 @@ type ChainstoreParam struct {
// 订单状态 // 订单状态
type OrderStatusNottify struct { type OrderStatusNottify struct {
CallbackBusinessType string `json:"callback_business_type"` CallbackBusinessType string `json:"callback_business_type"`
Param *OrderCallbackParam `json:"param"` Param map[string]interface{} `json:"param"`
} }
// 订单状态回调paramter // 订单状态回调paramter
@@ -142,31 +142,36 @@ func (a *API) GetChainstoreStatusNotify(request *http.Request) (shopStatusMsg *C
// 获取订单状态回调消息 // 获取订单状态回调消息
func (a *API) GetChainOrderStatusNotify(request *http.Request) (shopStatusMsg *OrderStatusNottify, callbackResponse *CallbackResponse) { func (a *API) GetChainOrderStatusNotify(request *http.Request) (shopStatusMsg *OrderStatusNottify, callbackResponse *CallbackResponse) {
data, err := ioutil.ReadAll(request.Body) //data, err := ioutil.ReadAll(request.Body)
if err != nil { //if err != nil {
baseapi.SugarLogger.Debugf("FN GetChainOrderStatusNotify failed with No result msg err:%v", err) // baseapi.SugarLogger.Debugf("FN GetChainOrderStatusNotify failed with No result msg err:%v", err)
callbackResponse = &CallbackResponse{Code: -1} // callbackResponse = &CallbackResponse{Code: -1}
return nil, callbackResponse // return nil, callbackResponse
//}
resultData := &ShortStatus{
AppId: request.FormValue("app_id"),
Signature: request.FormValue("signature"),
Timestamp: request.FormValue("timestamp"),
BusinessData: request.FormValue("business_data"),
} }
fmt.Println("string==================", string(data)) fmt.Println("string==================", resultData.BusinessData)
storeNotify := make(map[string]interface{}, 4) //if err := json.Unmarshal([]byte(resultData.BusinessData), &storeNotify); err != nil {
if err = json.Unmarshal(data, &storeNotify); err != nil { // baseapi.SugarLogger.Debugf("FN GetShopStatusCallbackMsg failed with err:%v", err)
baseapi.SugarLogger.Debugf("FN GetShopStatusCallbackMsg failed with err:%v", err) // callbackResponse = &CallbackResponse{Code: -1}
callbackResponse = &CallbackResponse{Code: -1} // return nil, callbackResponse
return nil, callbackResponse //}
} //
//fmt.Println("======================", storeNotify)
fmt.Println("======================", storeNotify)
fnNotify := &OrderStatusNottify{} fnNotify := &OrderStatusNottify{}
if err := json.Unmarshal([]byte(utils.Interface2String(storeNotify["business_data"])), fnNotify); err != nil { if err := json.Unmarshal([]byte(resultData.BusinessData), fnNotify); err != nil {
baseapi.SugarLogger.Debugf("FN callback string to ChainstoreStatusNotify failed with err:%v", err) baseapi.SugarLogger.Debugf("FN callback string to ChainstoreStatusNotify failed with err:%v", err)
callbackResponse = &CallbackResponse{Code: -1} callbackResponse = &CallbackResponse{Code: -1}
return nil, callbackResponse return nil, callbackResponse
} }
fmt.Println("======================business_data", fnNotify.Param) fmt.Println("======================business_data", fnNotify.Param)
fmt.Println("======================business_data", fnNotify.Param.PartnerOrderCode) fmt.Println("======================business_data", fnNotify.Param["orderId"])
fmt.Println("======================business_data", fnNotify.Param.OrderId) fmt.Println("======================business_data", fnNotify.Param["partnerOrderCode"])
fmt.Println("======================business_data", fnNotify.Param) fmt.Println("======================business_data", fnNotify.Param)
fmt.Println("======================business_data", fnNotify.CallbackBusinessType) fmt.Println("======================business_data", fnNotify.CallbackBusinessType)

View File

@@ -1,6 +1,7 @@
package fnpsapi package fnpsapi
import ( import (
"encoding/json"
"fmt" "fmt"
"git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi"
"go.uber.org/zap" "go.uber.org/zap"
@@ -174,3 +175,17 @@ func TestGetOrder(t *testing.T) {
fmt.Println(deliveryFee) fmt.Println(deliveryFee)
fmt.Println(baseDeliveryFee) fmt.Println(baseDeliveryFee)
} }
func TestDataUnmas(t *testing.T) {
business_data := `{"callback_business_type":"orderStatusNotify","param":{"appId":"6705486294797503379","carrierDriverName":"","carrierDriverPhone":"","orderId":300000387828723002,"orderStatus":1,"partnerOrderCode":"88386437227716","pushTime":1648775857873,"transfer":0}}`
fnNotify := &OrderStatusNottify{}
if err := json.Unmarshal([]byte(business_data), fnNotify); err != nil {
baseapi.SugarLogger.Debugf("FN callback string to ChainstoreStatusNotify failed with err:%v", err)
}
fmt.Println("======================business_data", fnNotify.Param)
fmt.Println("======================business_data", fnNotify.Param["appId"])
//fmt.Println("======================business_data", fnNotify.Param.OrderId)
//fmt.Println("======================business_data", fnNotify.Param)
fmt.Println("======================business_data", fnNotify.CallbackBusinessType)
}