Merge branch 'master' of e.coding.net:rosydev/baseapi

This commit is contained in:
邹宗楠
2023-02-06 16:00:06 +08:00

View File

@@ -1,10 +1,11 @@
package uuptapi
import (
"bytes"
"encoding/json"
"errors"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
"io/ioutil"
"net/http"
)
@@ -40,37 +41,20 @@ func (a *API) WaybillCallback(request *http.Request) (*WaybillCallbackParam, *Ca
//if callbackResponse := a.CheckCallbackValidation(request); callbackResponse != nil {
// return nil, callbackResponse
//}
buf, err := ioutil.ReadAll(request.Body)
if err != nil {
globals.SugarLogger.Debugf("========buf err %v", err)
return nil, &CallbackResponse{
ReturnCode: "2065",
ReturnMsg: "错误",
}
retVal := WaybillCallbackParam{}
data := request.PostForm.Get("data")
b := bytes.NewBufferString(data)
decoder := json.NewDecoder(b)
if err := decoder.Decode(&retVal); err != nil {
return nil, Err2CallbackResponse(errors.New("uu跑腿回调参数解析错误,请检查"))
}
retVal := &WaybillCallbackParam{}
if err := json.Unmarshal(buf, retVal); err != nil {
globals.SugarLogger.Debugf("========buf err %v", err)
return nil, &CallbackResponse{
ReturnCode: "20625",
ReturnMsg: "错误2",
}
globals.SugarLogger.Debugf("uupt WaybillCallback retVal======%s", utils.Format4Output(retVal, false))
con := retVal != WaybillCallbackParam{}
if con {
return &retVal, Err2CallbackResponse(nil)
} else {
return nil, Err2CallbackResponse(errors.New("UU跑腿运单回调信息为空"))
}
globals.SugarLogger.Debugf("====retVal := %s", utils.Format4Output(retVal, false))
//retVal := WaybillCallbackParam{}
//if err := utils.Map2StructByJson(utils.URLValues2Map(request.PostForm), &retVal, true); err != nil {
// return nil, Err2CallbackResponse(err)
//}
globals.SugarLogger.Debugf("retval======%s", utils.Format4Output(retVal, false))
//con := retVal != WaybillCallbackParam{}
//if con {
// return &retVal, Err2CallbackResponse(nil)
//} else {
// return nil, Err2CallbackResponse(fmt.Errorf("UU跑腿运单回调信息为空"))
//}
return retVal, Err2CallbackResponse(nil)
}
func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *CallbackResponse) {