diff --git a/platformapi/sfps2/callback.go b/platformapi/sfps2/callback.go index 2b599fc1..e8ca9e77 100644 --- a/platformapi/sfps2/callback.go +++ b/platformapi/sfps2/callback.go @@ -136,6 +136,7 @@ func Err2CallbackResponse(err error) *CallbackResponse { func (a *API) GetCallbackUrlIndex(request *http.Request) (map[string]interface{}, *CallbackResponse) { globals.SugarLogger.Debugf("sfsfsf GetCallbackUrlIndex method=%s,url=%s", request.Method, request.URL) data, err := ioutil.ReadAll(request.Body) + globals.SugarLogger.Debugf("=======data=%s", string(data)) if err != nil { return nil, CallbackResponseErr(false) } diff --git a/platformapi/sfps2/sf_test.go b/platformapi/sfps2/sf_test.go index 7a8ddd92..e5e69ae8 100644 --- a/platformapi/sfps2/sf_test.go +++ b/platformapi/sfps2/sf_test.go @@ -1,8 +1,12 @@ package sfps2 import ( + "bufio" + "encoding/json" "fmt" "git.rosy.net.cn/baseapi/utils" + "io/ioutil" + "net/http" "strings" "testing" ) @@ -137,5 +141,103 @@ func TestNew(t *testing.T) { } func TestInterfaceConverse(t *testing.T) { + str := "{\n\t\"operator_name\": \"柳聪\",\n\t\"operator_phone\": \"16541639283\",\n\t\"order_status\": 17,\n\t\"push_time\": 1704868998,\n\t\"receiRpt_type\": 0,\n\t\"rider_lat\": 39.943298,\n\t\"rider_lng\": 116.335075,\n\t\"sf_order_id\": \"JS4154986256839\",\n\t\"sf_ucode\": \"01405784\",\n\t\"shop_id\": 3263670062849,\n\t\"shop_order_id\": \"88442591229822\",\n\t\"status_desc\": \"配送员完成\",\n\t\"url_index\": \"order_complete\"\n}" + var ( + err error + client = http.Client{} + request *http.Request + param = make(map[string]interface{}) + ) + param = changeToRaw(urlIndex, msg) + globals.SugarLogger.Debugf("sfsfsf pushCallbackToGy param=%s", utils.Format4Output(param, false)) + b, _ := json.Marshal(param) + //sign := api.SfPsAPI.SignParam(b) + + switch urlIndex { + case sfps2.UrlIndexRiderException: + request, err = http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/SFPS/SfAbnormal", bufio.NewReader(strings.NewReader(utils.Map2URLValues(param).Encode()))) + default: + //fullUrl := utils.GenerateGetURL("http://callback-jxgy.jxc4.com/SFPS/SfOrder", "", map[string]interface{}{"sign": sign}) + //request, err = http.NewRequest(http.MethodPost, fullUrl, strings.NewReader(string(b))) + request, err = http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/SFPS/SfOrder", strings.NewReader(string(b))) + } + + //检测request数据 + data, err := ioutil.ReadAll(request.Body) + temp := make(map[string]interface{}) + if err = json.Unmarshal(data, &temp); err == nil { + globals.SugarLogger.Debugf("pushCallbackToGy test reqData temp=%s,err=%v", utils.Format4Output(temp, false), err) + } + + if err != nil { + return + } + request.Header.Set("Content-Type", "application/json;charset=UTF-8") + client.Do(request) +} + +func changeToRaw(urlIndex string, msg interface{}) (retVal map[string]interface{}) { + retVal = make(map[string]interface{}) + switch urlIndex { + case UrlIndexRiderStatus: + temp := msg.(RiderStatus) + retVal["shop_id"] = temp.ShopId + retVal["sf_order_id"] = temp.SFOrderID + retVal["shop_order_id"] = temp.ShopOrderID + retVal["url_index"] = temp.UrlIndex + retVal["operator_name"] = temp.OperatorName + retVal["operator_phone"] = temp.OperatorPhone + retVal["rider_lng"] = temp.RiderLng + retVal["rider_lat"] = temp.RiderLat + retVal["order_status"] = temp.OrderStatus + retVal["status_desc"] = temp.StatusDesc + retVal["sf_ucode"] = temp.SFUCode + retVal["push_time"] = temp.PushTime + case UrlIndexRiderRecall: + temp := msg.(RiderRecall) + retVal["order_status"] = temp.OrderStatus + retVal["push_time"] = temp.PushTime + retVal["sf_order_id"] = temp.SFOrderID + retVal["shop_id"] = temp.ShopId + retVal["shop_order_id"] = temp.ShopOrderID + retVal["url_index"] = temp.UrlIndex + retVal["status_desc"] = temp.StatusDesc + case UrlIndexOrderComplete: + temp := msg.(OrderComplete) + retVal["operator_name"] = temp.OperatorName + retVal["operator_phone"] = temp.OperatorPhone + retVal["order_status"] = temp.OrderStatus + retVal["push_time"] = temp.PushTime + retVal["receiRpt_type"] = temp.ReceiRptType + retVal["rider_lat"] = temp.RiderLat + retVal["rider_lng"] = temp.RiderLng + retVal["sf_order_id"] = temp.SfOrderID + retVal["sf_ucode"] = temp.SfUcode + retVal["shop_id"] = temp.ShopId + retVal["shop_order_id"] = temp.ShopOrderID + retVal["status_desc"] = temp.StatusDesc + retVal["url_index"] = temp.UrlIndex + case UrlIndexSFCancel: + temp := msg.(SFCancel) + retVal["cancel_reason"] = temp.CancelReason + retVal["cancel_code"] = temp.CancelCode + retVal["operator_name"] = temp.OperatorName + retVal["operator_phone"] = temp.OperatorPhone + retVal["order_status"] = temp.OrderStatus + retVal["push_time"] = temp.PushTime + retVal["rider_lat"] = temp.RiderLat + retVal["rider_lng"] = temp.RiderLng + retVal["sf_order_id"] = temp.SFOrderID + retVal["sf_ucode"] = temp.SFUCode + retVal["shop_id"] = temp.ShopId + retVal["shop_order_id"] = temp.ShopOrderID + retVal["url_index"] = temp.UrlIndex + retVal["status_desc"] = temp.StatusDesc + } + //签名 + //b, _ := json.Marshal(retVal) + //sign := api.SfPsAPI.SignParam(b) + //retVal["sign"] = sign + return retVal }