修改回调

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 {
AppId string `json:"app_id"`
Signature string `json:"signature"`
Timestamp string `json:"timestamp"`
BusinessData interface{} `json:"business_data"`
AppId string `json:"app_id"`
Signature string `json:"signature"`
Timestamp string `json:"timestamp"`
BusinessData string `json:"business_data"`
}
// 门店状态回调
@@ -61,8 +61,8 @@ type ChainstoreParam struct {
// 订单状态
type OrderStatusNottify struct {
CallbackBusinessType string `json:"callback_business_type"`
Param *OrderCallbackParam `json:"param"`
CallbackBusinessType string `json:"callback_business_type"`
Param map[string]interface{} `json:"param"`
}
// 订单状态回调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) {
data, err := ioutil.ReadAll(request.Body)
if err != nil {
baseapi.SugarLogger.Debugf("FN GetChainOrderStatusNotify failed with No result msg err:%v", err)
callbackResponse = &CallbackResponse{Code: -1}
return nil, callbackResponse
//data, err := ioutil.ReadAll(request.Body)
//if err != nil {
// baseapi.SugarLogger.Debugf("FN GetChainOrderStatusNotify failed with No result msg err:%v", err)
// callbackResponse = &CallbackResponse{Code: -1}
// 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))
storeNotify := make(map[string]interface{}, 4)
if err = json.Unmarshal(data, &storeNotify); err != nil {
baseapi.SugarLogger.Debugf("FN GetShopStatusCallbackMsg failed with err:%v", err)
callbackResponse = &CallbackResponse{Code: -1}
return nil, callbackResponse
}
fmt.Println("======================", storeNotify)
fmt.Println("string==================", resultData.BusinessData)
//if err := json.Unmarshal([]byte(resultData.BusinessData), &storeNotify); err != nil {
// baseapi.SugarLogger.Debugf("FN GetShopStatusCallbackMsg failed with err:%v", err)
// callbackResponse = &CallbackResponse{Code: -1}
// return nil, callbackResponse
//}
//
//fmt.Println("======================", storeNotify)
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)
callbackResponse = &CallbackResponse{Code: -1}
return nil, callbackResponse
}
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.CallbackBusinessType)

View File

@@ -1,6 +1,7 @@
package fnpsapi
import (
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi"
"go.uber.org/zap"
@@ -174,3 +175,17 @@ func TestGetOrder(t *testing.T) {
fmt.Println(deliveryFee)
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)
}