From 6c91abb68b3749fef7635313d7395f005ca6ca62 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 10 Jan 2024 10:04:06 +0800 Subject: [PATCH 1/7] 1 --- platformapi/mtwmapi/mtwmapi.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 0f394525..ae6b76c0 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -5,7 +5,6 @@ import ( "crypto/md5" "fmt" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/globals" "mime/multipart" "net/http" "net/url" @@ -146,7 +145,7 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ } signURL := a.genURL(cmd) + "?" params[signKey] = a.signParams(signURL, params) - globals.SugarLogger.Debugf("test mtCancelAct cmd=%s sig=%s", cmd, utils.Format4Output(params, false)) + //globals.SugarLogger.Debugf("test mtCancelAct cmd=%s sig=%s", cmd, utils.Format4Output(params, false)) err = platformapi.AccessPlatformAPIWithRetry(a.client, func() *http.Request { var request *http.Request From 8685d2b39dfcc39e19c862c41fcdda8e022fe4dd Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 10 Jan 2024 10:31:32 +0800 Subject: [PATCH 2/7] 1 --- platformapi/sfps2/sfpsapi.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformapi/sfps2/sfpsapi.go b/platformapi/sfps2/sfpsapi.go index f82e1b0c..f235eb19 100644 --- a/platformapi/sfps2/sfpsapi.go +++ b/platformapi/sfps2/sfpsapi.go @@ -40,7 +40,7 @@ func New(devId int, devKey string, config ...*platformapi.APIConfig) *API { } } -func (a *API) signParam(params []byte) (sig string) { +func (a *API) SignParam(params []byte) (sig string) { sign := fmt.Sprintf("%s&%d&%s", string(params), a.devId, a.devKey) md2sign := md5.Sum([]byte(sign)) return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%x", md2sign))) @@ -58,7 +58,7 @@ func (a *API) HttpPostJson(url string, data interface{}) *Response { return &result } //签名 - sign := a.signParam(b) + sign := a.SignParam(b) fullUrl := utils.GenerateGetURL(BaseURL, url, map[string]interface{}{"sign": sign}) //fullUrl := utils.GenerateGetURL(BaseCatchUrl, url, map[string]interface{}{"sign": sign}) From 7d6de7aba5edb83a29ab43bd5284435ceabb182d Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 10 Jan 2024 11:00:30 +0800 Subject: [PATCH 3/7] 1 --- platformapi/sfps2/sf_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformapi/sfps2/sf_test.go b/platformapi/sfps2/sf_test.go index 5bc40a29..7a8ddd92 100644 --- a/platformapi/sfps2/sf_test.go +++ b/platformapi/sfps2/sf_test.go @@ -65,7 +65,7 @@ func TestCreateOrder(t *testing.T) { DevId: AppID, ShopId: TestSFStoreID, ShopType: 1, - ShopOrderId: "20240109", + ShopOrderId: "20240110", OrderSequence: "测试", OrderSource: OrderSourceELM, OrderTime: 1694168441, From 8f715a2af684424430e9c23810c32cdd710f50e1 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 10 Jan 2024 11:27:28 +0800 Subject: [PATCH 4/7] 1 --- platformapi/sfps2/order.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/platformapi/sfps2/order.go b/platformapi/sfps2/order.go index 9dc95ab4..a2ccf6e0 100644 --- a/platformapi/sfps2/order.go +++ b/platformapi/sfps2/order.go @@ -26,13 +26,7 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er temp := resp.BaseRetVal.Result.(map[string]interface{}) temp1 := temp["charge_price_list"].(map[string]interface{}) return temp1["shop_pay_price"].(float64), nil - //retVal := PreCreateOrderResp{} - //s, _ := json.Marshal(resp.BaseRetVal.Result) - //if err = json.Unmarshal(s, &retVal); err == nil { - // return retVal.ChargePriceList.ShopPayPrice, nil - //} else { - // return 0, err - //} + } // CreateOrder 创建订单(店铺) From 603559750a06546763c51a57676ffdf64a739975 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 10 Jan 2024 14:16:25 +0800 Subject: [PATCH 5/7] 1 --- platformapi/sfps2/callback.go | 1 + 1 file changed, 1 insertion(+) diff --git a/platformapi/sfps2/callback.go b/platformapi/sfps2/callback.go index 70ec9230..2b599fc1 100644 --- a/platformapi/sfps2/callback.go +++ b/platformapi/sfps2/callback.go @@ -134,6 +134,7 @@ func Err2CallbackResponse(err error) *CallbackResponse { // GetCallbackUrlIndex 配送状态更改回调 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) if err != nil { return nil, CallbackResponseErr(false) From 5b1c9c78c3e4c095adf20ca9adc885f3b698948c Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 10 Jan 2024 15:29:31 +0800 Subject: [PATCH 6/7] 1 --- platformapi/sfps2/callback.go | 1 + platformapi/sfps2/sf_test.go | 102 ++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) 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 } From ea9b048e282a983dfd8353967d42da5cd75da1f9 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 10 Jan 2024 16:26:18 +0800 Subject: [PATCH 7/7] 1 --- platformapi/sfps2/callback.go | 3 - platformapi/sfps2/sf_test.go | 106 ---------------------------------- 2 files changed, 109 deletions(-) diff --git a/platformapi/sfps2/callback.go b/platformapi/sfps2/callback.go index e8ca9e77..eee2c8d5 100644 --- a/platformapi/sfps2/callback.go +++ b/platformapi/sfps2/callback.go @@ -134,9 +134,7 @@ func Err2CallbackResponse(err error) *CallbackResponse { // GetCallbackUrlIndex 配送状态更改回调 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) } @@ -148,7 +146,6 @@ func (a *API) GetCallbackUrlIndex(request *http.Request) (map[string]interface{} if err = json.Unmarshal(data, &temp); err == nil { urlIndex = temp["url_index"].(string) } - globals.SugarLogger.Debugf("sfsfsf test data=%s,urlIndex=%s", utils.Format4Output(temp, false), urlIndex) result := make(map[string]interface{}, 0) switch urlIndex { case UrlIndexRiderStatus: diff --git a/platformapi/sfps2/sf_test.go b/platformapi/sfps2/sf_test.go index e5e69ae8..696e351f 100644 --- a/platformapi/sfps2/sf_test.go +++ b/platformapi/sfps2/sf_test.go @@ -1,12 +1,8 @@ package sfps2 import ( - "bufio" - "encoding/json" "fmt" "git.rosy.net.cn/baseapi/utils" - "io/ioutil" - "net/http" "strings" "testing" ) @@ -139,105 +135,3 @@ func TestNew(t *testing.T) { fmt.Println(lng, lat) } } - -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 -}