修改返回值

This commit is contained in:
邹宗楠
2022-04-02 09:19:53 +08:00
parent afddb82ecd
commit 7bc1b718a0
2 changed files with 24 additions and 30 deletions

View File

@@ -1,7 +1,6 @@
package fnpsapi
import (
"bytes"
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi"
@@ -46,11 +45,6 @@ type ShortStatus struct {
//#region 订单
type OrderErr struct {
CallbackBusinessType string `json:"callback_business_type"`
Param *OrderStatusNottify `json:"param"`
}
// 订单状态
type OrderStatusNottify struct {
CallbackBusinessType string `json:"callback_business_type"`
@@ -160,27 +154,21 @@ func (a *API) GetChainOrderStatusNotify(request *http.Request) (shopStatusMsg *O
//if true { // 第二次平台分配骑手
fmt.Println("==============", string(data))
fmt.Println("==============2222", bytes.NewBuffer(data).String())
result := &OrderStatusNottify{}
result := &ShortStatus{}
if err := json.Unmarshal(data, &result); err != nil {
callbackResponse = &CallbackResponse{Code: -1}
return nil, callbackResponse
}
fmt.Println("data=======", result.Param)
fmt.Println("data=======", result.Param.OrderId)
fmt.Println("data=======", result.Param.PartnerOrderCode)
//} else { // 第一次,平台确认收取订单
// result := &OrderErr{}
// if err := json.Unmarshal(data, &result); err != nil {
// callbackResponse = &CallbackResponse{Code: -1}
// return nil, callbackResponse
// }
// fmt.Println("data=======", result.Param)
// fmt.Println("data=======", result.Param.Param.OrderId)
// fmt.Println("data=======", result.Param.Param.PartnerOrderCode)
//}
return result, SuccessResponse
orderResult := &OrderStatusNottify{}
if err := json.Unmarshal([]byte(result.BusinessData), orderResult); err != nil {
callbackResponse = &CallbackResponse{Code: -1}
return nil, callbackResponse
}
fmt.Println("==============orderResult", orderResult)
fmt.Println("==============orderResult", orderResult.Param)
fmt.Println("==============orderResult", orderResult.Param.PartnerOrderCode)
return orderResult, SuccessResponse
}
// 异常配送

View File

@@ -177,15 +177,21 @@ func TestGetOrder(t *testing.T) {
}
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 {
data := `{"signature":"5a4270c8fb3c4a3a641d2f5f66990c503c7248ecd51248b020e0b44db75a6761","app_id":"6705486294797503379","timestamp":"1648861445686","business_data":"{\"callback_business_type\":\"orderStatusNotify\",\"param\":{\"app_id\":\"6705486294797503379\",\"carrier_driver_name\":\"\",\"carrier_driver_phone\":\"\",\"order_id\":300000388333833530,\"order_status\":1,\"partner_order_code\":\"88386523916938\",\"push_time\":1648861445686,\"transfer\":0}}"}`
fnNotify := &ShortStatus{}
if err := json.Unmarshal([]byte(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)
fmt.Println("data", fnNotify.BusinessData)
fmt.Println("data", fnNotify.AppId)
fmt.Println("data", fnNotify.Signature)
retsult := &OrderStatusNottify{}
err := json.Unmarshal([]byte(fnNotify.BusinessData), retsult)
fmt.Println("err1======", err)
fmt.Println("retsult", retsult)
fmt.Println("retsult", retsult.Param)
fmt.Println("retsult", retsult.CallbackBusinessType)
fmt.Println("retsult", retsult.Param.PartnerOrderCode)
}