回调修改
This commit is contained in:
@@ -2,11 +2,8 @@ package fnpsapi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
)
|
)
|
||||||
@@ -48,7 +45,7 @@ type ShortStatus struct {
|
|||||||
// 门店状态回调
|
// 门店状态回调
|
||||||
type ChainstoreStatusNotify struct {
|
type ChainstoreStatusNotify struct {
|
||||||
CallbackBusinessType string `json:"callback_business_type"`
|
CallbackBusinessType string `json:"callback_business_type"`
|
||||||
Param string `json:"param"`
|
Param *ChainstoreParam `json:"param"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 门店状态回调paramter
|
// 门店状态回调paramter
|
||||||
@@ -58,7 +55,13 @@ type ChainstoreParam struct {
|
|||||||
OutShopCode string `json:"out_shop_code"` // 外部门店编码
|
OutShopCode string `json:"out_shop_code"` // 外部门店编码
|
||||||
Status string `json:"status"` // 门店认证状态
|
Status string `json:"status"` // 门店认证状态
|
||||||
ModifyStatus string `json:"modify_status"` // 门店修改状态
|
ModifyStatus string `json:"modify_status"` // 门店修改状态
|
||||||
Remark string `json:"remark "` // 门店认证、修改等驳回时返回原因
|
Remark string `json:"remark"` // 门店认证、修改等驳回时返回原因
|
||||||
|
}
|
||||||
|
|
||||||
|
// 订单状态
|
||||||
|
type OrderStatusNottify struct {
|
||||||
|
CallbackBusinessType string `json:"callback_business_type"`
|
||||||
|
Param *OrderCallbackParam `json:"param"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订单状态回调paramter
|
// 订单状态回调paramter
|
||||||
@@ -90,6 +93,12 @@ type CookingFinishNotify struct {
|
|||||||
CookingFinishTime int64 `json:"cooking_finish_time"` // 状态推送时间 (毫秒)
|
CookingFinishTime int64 `json:"cooking_finish_time"` // 状态推送时间 (毫秒)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 异常状态回掉
|
||||||
|
type AbnormalStatusNotify struct {
|
||||||
|
CallbackBusinessType string `json:"callback_business_type"`
|
||||||
|
Param *AbnormalReportNotify `json:"param"`
|
||||||
|
}
|
||||||
|
|
||||||
// 异常状态回调
|
// 异常状态回调
|
||||||
type AbnormalReportNotify struct {
|
type AbnormalReportNotify struct {
|
||||||
OrderId int64 `json:"order_id"` // 订单号
|
OrderId int64 `json:"order_id"` // 订单号
|
||||||
@@ -105,7 +114,7 @@ type AbnormalReportNotify struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取门店状态回调消息
|
// 获取门店状态回调消息
|
||||||
func (a *API) GetChainstoreStatusNotify(request *http.Request) (shopStatusMsg map[string]interface{}, callbackResponse *CallbackResponse) {
|
func (a *API) GetChainstoreStatusNotify(request *http.Request) (shopStatusMsg *ChainstoreStatusNotify, callbackResponse *CallbackResponse) {
|
||||||
storeNotify := ShortStatus{}
|
storeNotify := ShortStatus{}
|
||||||
err := utils.Map2StructByJson(utils.URLValues2Map(request.PostForm), &storeNotify, true)
|
err := utils.Map2StructByJson(utils.URLValues2Map(request.PostForm), &storeNotify, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -121,98 +130,87 @@ func (a *API) GetChainstoreStatusNotify(request *http.Request) (shopStatusMsg ma
|
|||||||
return nil, callbackResponse
|
return nil, callbackResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析蜂鸟返回值
|
return fnNotify, SuccessResponse
|
||||||
shopStatusMsg, err = FnCallbackAnalysis(fnNotify)
|
}
|
||||||
|
|
||||||
|
// 获取订单状态回调消息
|
||||||
|
func (a *API) GetChainOrderStatusNotify(request *http.Request) (shopStatusMsg *OrderStatusNottify, callbackResponse *CallbackResponse) {
|
||||||
|
storeNotify := ShortStatus{}
|
||||||
|
err := utils.Map2StructByJson(utils.URLValues2Map(request.PostForm), &storeNotify, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &CallbackResponse{Code: -1}
|
baseapi.SugarLogger.Debugf("FN GetShopStatusCallbackMsg failed with err:%v", err)
|
||||||
|
callbackResponse = &CallbackResponse{Code: -1}
|
||||||
|
return nil, callbackResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
return shopStatusMsg, SuccessResponse
|
fnNotify := &OrderStatusNottify{}
|
||||||
|
if err := json.Unmarshal([]byte(storeNotify.BusinessData), fnNotify); err != nil {
|
||||||
|
baseapi.SugarLogger.Debugf("FN callback string to ChainstoreStatusNotify failed with err:%v", err)
|
||||||
|
callbackResponse = &CallbackResponse{Code: -1}
|
||||||
|
return nil, callbackResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
return fnNotify, SuccessResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
// 异常配送
|
||||||
|
func (a *API) GetChainAbnormaltatusNotify(request *http.Request) (shopStatusMsg *AbnormalStatusNotify, callbackResponse *CallbackResponse) {
|
||||||
|
storeNotify := ShortStatus{}
|
||||||
|
err := utils.Map2StructByJson(utils.URLValues2Map(request.PostForm), &storeNotify, true)
|
||||||
|
if err != nil {
|
||||||
|
baseapi.SugarLogger.Debugf("FN GetShopStatusCallbackMsg failed with err:%v", err)
|
||||||
|
callbackResponse = &CallbackResponse{Code: -1}
|
||||||
|
return nil, callbackResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
fnNotify := &AbnormalStatusNotify{}
|
||||||
|
if err := json.Unmarshal([]byte(storeNotify.BusinessData), fnNotify); err != nil {
|
||||||
|
baseapi.SugarLogger.Debugf("FN callback string to ChainstoreStatusNotify failed with err:%v", err)
|
||||||
|
callbackResponse = &CallbackResponse{Code: -1}
|
||||||
|
return nil, callbackResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
return fnNotify, SuccessResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
// 蜂鸟返回值解析
|
// 蜂鸟返回值解析
|
||||||
func FnCallbackAnalysis(notify *ChainstoreStatusNotify) (result map[string]interface{}, err error) {
|
//func FnCallbackAnalysis(notify *ChainstoreStatusNotify) (result map[string]interface{}, err error) {
|
||||||
switch notify.CallbackBusinessType {
|
// switch notify.CallbackBusinessType {
|
||||||
case OrderStatus: // 订单回调
|
// case OrderStatus: // 订单回调
|
||||||
orderRes := &OrderCallbackParam{}
|
// orderRes := &OrderCallbackParam{}
|
||||||
if err := json.Unmarshal([]byte(notify.Param), orderRes); err != nil {
|
// if err := json.Unmarshal([]byte(notify.Param), orderRes); err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
notifyObj := utils.Struct2FlatMap(orderRes)
|
// notifyObj := utils.Struct2FlatMap(orderRes)
|
||||||
notifyObj["orderStatusNotify"] = ChainstoreStatus
|
// notifyObj["orderStatusNotify"] = ChainstoreStatus
|
||||||
return notifyObj, nil
|
// return notifyObj, nil
|
||||||
case AbnormalStatus: // 异常报备回调
|
// case AbnormalStatus: // 异常报备回调
|
||||||
return nil, nil
|
// return nil, nil
|
||||||
case CookingFinishStatus: // 商户出餐回调
|
// case CookingFinishStatus: // 商户出餐回调
|
||||||
//cokking := &CookingFinishNotify{}
|
// //cokking := &CookingFinishNotify{}
|
||||||
//if err := json.Unmarshal([]byte(notify.Param), cokking); err != nil {
|
// //if err := json.Unmarshal([]byte(notify.Param), cokking); err != nil {
|
||||||
// return nil, err
|
// // return nil, err
|
||||||
//}
|
// //}
|
||||||
//notifyObj := utils.Struct2FlatMap(cokking)
|
// //notifyObj := utils.Struct2FlatMap(cokking)
|
||||||
//notifyObj["cookingFinishNotify"] = ChainstoreStatus
|
// //notifyObj["cookingFinishNotify"] = ChainstoreStatus
|
||||||
//return notifyObj, nil
|
// //return notifyObj, nil
|
||||||
return nil, nil
|
// return nil, nil
|
||||||
case ChainstoreStatus: // 门店状态变更回调
|
// case ChainstoreStatus: // 门店状态变更回调
|
||||||
storeRes := &ChainstoreParam{}
|
// storeRes := &ChainstoreParam{}
|
||||||
if err := json.Unmarshal([]byte(notify.Param), storeRes); err != nil {
|
// if err := json.Unmarshal([]byte(notify.Param), storeRes); err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
notifyObj := utils.Struct2FlatMap(storeRes)
|
// notifyObj := utils.Struct2FlatMap(storeRes)
|
||||||
notifyObj["notifyUel"] = ChainstoreStatus
|
// notifyObj["notifyUel"] = ChainstoreStatus
|
||||||
return notifyObj, nil
|
// return notifyObj, nil
|
||||||
case ChainstoreServiceStatus: // 门店采购服务变更回调
|
// case ChainstoreServiceStatus: // 门店采购服务变更回调
|
||||||
return nil, nil
|
// return nil, nil
|
||||||
case NoServiceStatus: // 城市屏蔽区域调整回调通知
|
// case NoServiceStatus: // 城市屏蔽区域调整回调通知
|
||||||
return nil, nil
|
// return nil, nil
|
||||||
default:
|
// default:
|
||||||
return nil, errors.New("回调函数,回调路径错误")
|
// return nil, errors.New("回调函数,回调路径错误")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
globals.SugarLogger.Warnf("Fn callback url func err:=[%s],dont's exits", "notify.CallbackBusinessType")
|
// globals.SugarLogger.Warnf("Fn callback url func err:=[%s],dont's exits", "notify.CallbackBusinessType")
|
||||||
return nil, errors.New("回调函数,回调路径错误")
|
// return nil, errors.New("回调函数,回调路径错误")
|
||||||
}
|
//}
|
||||||
|
|
||||||
type CallBackInfo struct {
|
|
||||||
AppID string `json:"app_id"`
|
|
||||||
Data string `json:"data"`
|
|
||||||
Salt int `json:"salt"`
|
|
||||||
Signature string `json:"signature"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type WayBillInfo struct {
|
|
||||||
PartnerOrderCode string `json:"partner_order_code"`
|
|
||||||
OrderStatus int `json:"order_status"`
|
|
||||||
PushTime int64 `json:"push_time"`
|
|
||||||
CarrierDriverName string `json:"carrier_driver_name"`
|
|
||||||
CarrierDriverPhone string `json:"carrier_driver_phone"`
|
|
||||||
OpenOrderCode int64 `json:"open_order_code"`
|
|
||||||
PlatformCode string `json:"platform_code"`
|
|
||||||
ErrorScene string `json:"error_scene"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
ErrorCode string `json:"error_code"`
|
|
||||||
DetailDescription string `json:"detail_description"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *API) GetOrderCallbackMsg(data []byte) (orderMsg *WayBillInfo) {
|
|
||||||
callbackInfo := &CallBackInfo{}
|
|
||||||
err := utils.UnmarshalUseNumber(data, callbackInfo)
|
|
||||||
if err != nil {
|
|
||||||
globals.SugarLogger.Debugf("fn msg faild %v, err : %v", string(data), err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
if str, err := url.QueryUnescape(callbackInfo.Data); err == nil {
|
|
||||||
orderMsg = &WayBillInfo{}
|
|
||||||
if err := utils.UnmarshalUseNumber([]byte(str), orderMsg); err == nil {
|
|
||||||
return orderMsg
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Debugf("fn msg faild3 %v", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Debugf("fn msg faild2 %v", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return orderMsg
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user