diff --git a/platformapi/autonavi/autonavi.go b/platformapi/autonavi/autonavi.go index 1e10ae66..bcc1a42d 100644 --- a/platformapi/autonavi/autonavi.go +++ b/platformapi/autonavi/autonavi.go @@ -119,6 +119,10 @@ type API struct { key string } +func (a *API) SetKey(key string) { + a.key = key +} + type BuildingOrNeighborInfo struct { Name string `json:"name"` Type string `json:"type"` @@ -278,6 +282,35 @@ func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal Re return retVal, err } +func (a *API) AccessAPI3(apiStr string, params map[string]interface{}) (retVal ResponseResult, err error) { + err = platformapi.AccessPlatformAPIWithRetry(a.client, + func() *http.Request { + request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(BaseUrl, apiStr, params), nil) + return request + }, + a.config, + func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) { + if jsonResult1 == nil { + return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil") + } + status := jsonResult1["status"].(string) + if status == StatusCodeSuccess { + retVal = jsonResult1 + return platformapi.ErrLevelSuccess, nil + } + infoCode := jsonResult1["infocode"].(string) + newErr := utils.NewErrorCode(jsonResult1["info"].(string), infoCode) + if _, ok := exceedLimitCodes[infoCode]; ok { + return platformapi.ErrLevelExceedLimit, newErr + } else if _, ok := canRetryCodes[infoCode]; ok { + return platformapi.ErrLevelRecoverableErr, newErr + } else { + return platformapi.ErrLevelCodeIsNotOK, newErr + } + }) + return retVal, err +} + func (a *API) BatchAccessAPI(apiList []*tBatchAPIParams) (retVal []*tBatchAPIResponse, err error) { if len(apiList) == 0 { return nil, nil diff --git a/platformapi/autonavi/gaode_api.go b/platformapi/autonavi/gaode_api.go new file mode 100644 index 00000000..35331147 --- /dev/null +++ b/platformapi/autonavi/gaode_api.go @@ -0,0 +1,47 @@ +package autonavi + +import ( + "fmt" + "git.rosy.net.cn/baseapi/utils" + "strings" +) + +// GetCyclingPlan 获取骑手的骑行计划 +func (a *API) GetCyclingPlan(origin, destination string) ([]string, int64, int64, error) { + param := map[string]interface{}{ + "key": a.key, + "origin": origin, + "destination": destination, + "show_fields": "polyline", + } + result, err := a.AccessAPI3("direction/electrobike", param) + if err != nil { + return nil, 0, 0, err + } + var data *CyclingPlan + if err := utils.Map2StructByJson(result, &data, false); err != nil { + return nil, 0, 0, err + } + + if data.Status != "1" && data.Info != "ok" { + return nil, 0, 0, fmt.Errorf(data.Infocode) + } + + polyLineList := make([]string, 0, 0) // 坐标 + var distance int64 = 0 // 距离 4329 + var duration int64 = 0 // 时间 978 + for _, v := range data.Route.Paths { + for _, v2 := range v.Steps { + if v2.Polyline != "" { + polyLine := strings.Split(v2.Polyline, ";") + if polyLine != nil { + polyLineList = append(polyLineList, polyLine...) + } + } + } + distance = utils.Str2Int64(v.Distance) + duration = utils.Str2Int64(v.Duration) + 300 + } + + return polyLineList, distance, duration, nil +} diff --git a/platformapi/autonavi/gaode_const.go b/platformapi/autonavi/gaode_const.go new file mode 100644 index 00000000..ee02fb40 --- /dev/null +++ b/platformapi/autonavi/gaode_const.go @@ -0,0 +1,22 @@ +package autonavi + +// 高德骑行计划账号配置 +const ( + AMAPCyclingPlanKey1 = "cb4ea3516f88c0fd8fed73f92aeddffa" // 高德地图 成都京西到家网络科技有限公司 18080188338 Rosy201507 + AMAPCyclingPlanKey2 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 成都若溪科技有限公司 18048531223 Rosy201507 + AMAPCyclingPlanKey3 = "9805128688b11d011219e76e960e0feb" // 高德地图 冲天猴儿(成都)科技有限公司 19802843833 Rosy201507 + AMAPCyclingPlanKey4 = "727130840c0466c5a79494eca9b7cf98" // 高德地图 京西(成都)科技有限公司 18884789801 Rosy201507 + AMAPCyclingPlanKey5 = "962667fb03713cf9bcfce849b4c2ece1" // 高德地图 京西菜市(北京)科技有限公司 17723303721 Rosy201507 +) + +// 错误码 +const ( + DAILYQUERYOVERLIMIT = "10003" // 访问已超出日访问量 +) + +// BaseUrl 基础访问链接 +const BaseUrl = "https://restapi.amap.com/v5" + +// 白名单 +//148.70.158.63 +//132.232.12.131 diff --git a/platformapi/autonavi/gaode_model.go b/platformapi/autonavi/gaode_model.go new file mode 100644 index 00000000..0735f962 --- /dev/null +++ b/platformapi/autonavi/gaode_model.go @@ -0,0 +1,29 @@ +package autonavi + +type CyclingPlan struct { + Status string `json:"status"` // 本次状态 1-成功 0-失败 + Info string `json:"info"` // 成功ok 失败错误码 + Infocode string `json:"infocode"` // 返回状态说明 + Count string `json:"count"` // 路径规划方案 + Route Route `json:"route"` // 方案列表 +} + +type Route struct { + Origin string `json:"origin"` // 起点经纬度 + Destination string `json:"destination"` // 终点经纬度 + Paths []Paths `json:"paths"` // 方案详情 +} + +type Paths struct { + Distance string `json:"distance"` // 距离:米 + Duration string `json:"duration"` // 线路耗时,包括方案总耗时及分段step中的耗时 + Steps []Steps `json:"steps"` // 路线分段 +} + +type Steps struct { + Instruction string `json:"instruction"` // 骑行指示 + Orientation string `json:"orientation"` // 进入道路方向 + RoadName string `json:"road_name"` // 分段道路名称 + StepDistance int `json:"step_distance"` // 分段距离信息 + Polyline string `json:"polyline"` // 设置后可返回分路段坐标点串,两点间用“,”分隔 +} diff --git a/platformapi/autonavi/gaode_test.go b/platformapi/autonavi/gaode_test.go new file mode 100644 index 00000000..7ae6bb40 --- /dev/null +++ b/platformapi/autonavi/gaode_test.go @@ -0,0 +1,21 @@ +package autonavi + +import ( + "fmt" + "testing" +) + +func TestGetCyclingPlan(t *testing.T) { + key := "cb4ea3516f88c0fd8fed73f92aeddffa" + a := New(key) + data1, dada2, dada3, err := a.GetCyclingPlan("104.045460,30.693001", "104.045474,30.693344") + fmt.Println(data1) + fmt.Println(dada2) + fmt.Println(dada3) + fmt.Println(err) +} + +func TestLng(t *testing.T) { + origin := fmt.Sprintf("%f,%f", 113.854912, 22.601450) + fmt.Println(origin) +} diff --git a/platformapi/baidunavi/baidunavi_test.go b/platformapi/baidunavi/baidunavi_test.go index 63d6b889..3e432a3e 100644 --- a/platformapi/baidunavi/baidunavi_test.go +++ b/platformapi/baidunavi/baidunavi_test.go @@ -58,3 +58,10 @@ func TestDirectionLiteRide(t *testing.T) { fmt.Println(result) } + +func TestName(t *testing.T) { + syncStatus := 1 + syncStatus |= 32 + fmt.Println(syncStatus) + +} diff --git a/platformapi/ebaiapi/order_test.go b/platformapi/ebaiapi/order_test.go index 1d3d8d02..8e7a4593 100644 --- a/platformapi/ebaiapi/order_test.go +++ b/platformapi/ebaiapi/order_test.go @@ -167,7 +167,7 @@ func TestOrderPrivateInfo(t *testing.T) { } func TestOrderDeliveryGet(t *testing.T) { - result, err := api.OrderDeliveryGet("4033300102969791105") + result, err := api.OrderDeliveryGet("4053750050397193755") if err != nil { t.Fatal(err) } diff --git a/platformapi/mtwmapi/mtwmapi_test.go b/platformapi/mtwmapi/mtwmapi_test.go index dd79b6fb..0dba98c5 100644 --- a/platformapi/mtwmapi/mtwmapi_test.go +++ b/platformapi/mtwmapi/mtwmapi_test.go @@ -26,6 +26,7 @@ func init() { //api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "") //商超 + //api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_izAHEkoEl4lV-w4JdJFNww") //token_n4TwqCntWWuvQwAawzxC0w //api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_r36FEse6_ywebQI65FNNWA") //token_n4TwqCntWWuvQwAawzxC0w cookieStr := ` acctId=57396785; token=0bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*; wmPoiId=-1; diff --git a/platformapi/mtwmapi/order.go b/platformapi/mtwmapi/order.go index ec1ae22b..8aabe9cd 100644 --- a/platformapi/mtwmapi/order.go +++ b/platformapi/mtwmapi/order.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/globals" "time" ) @@ -359,6 +358,17 @@ type RiderRealPhoneNumberInfo struct { RiderRealPhoneNumber string `json:"rider_real_phone_number"` // 骑手真实手机号 } +// GetRiderDeliveryPath 获取骑手坐标 +type GetRiderDeliveryPath struct { + //Code int64 `json:"code"` + //Msg string `json:"msg"` + //Data []struct { + Longitude int `json:"longitude"` + Latitude int `json:"latitude"` + Time int64 `json:"time"` + //} `json:"data"` +} + func (a *API) OrderReceived(orderID int64) (err error) { _, err = a.AccessAPI("order/poi_received", true, map[string]interface{}{ KeyOrderID: orderID, @@ -555,16 +565,41 @@ func (a *API) OrderLogisticsCancel(orderID int64, reason string) (err error) { } // OrderLogisticsStatus 获取订单状态 -func (a *API) OrderLogisticsStatus(orderID int64) (status int64, err error) { +func (a *API) OrderLogisticsStatus(orderID int64) (status *utils.RiderInfo, err error) { result, err := a.AccessAPI("order/logistics/status", true, map[string]interface{}{ KeyOrderID: orderID, }) if err != nil { - return 0, err + return nil, err } + logistics := &utils.RiderInfo{} data := result.(map[string]interface{}) - return utils.Interface2Int64WithDefault(data["logistics_status"], 0), err + logistics.LogisticsStatus = int(utils.Interface2Int64WithDefault(data["logistics_status"], 0)) + logistics.CourierName = utils.Interface2String(data["dispatcher_name"]) + logistics.CourierPhone = utils.Interface2String(data["dispatcher_mobile"]) + return logistics, err +} + +func (a *API) GetDeliveryPath(orderId int64, appPoiCode string) (lng, lat int, err error) { + result, err := a.AccessAPI("order/getDeliveryPath", true, map[string]interface{}{ + KeyOrderID: orderId, + KeyAppPoiCode: appPoiCode, + }) + if err != nil { + return 0, 0, err + } + + if result == nil { + return 0, 0, nil + } + + path, _ := json.Marshal(result) + riderPath := make([]*GetRiderDeliveryPath, 0, 0) + if err := json.Unmarshal(path, &riderPath); err != nil { + return 0, 0, err + } + return riderPath[len(riderPath)-1].Longitude, riderPath[len(riderPath)-1].Latitude, nil } // OrderLogisticsFee 获取订单配送费 @@ -572,7 +607,6 @@ func (a *API) OrderLogisticsFee(orderID int64) (payFee float64, err error) { result, err := a.AccessAPI("order/logistics/status", true, map[string]interface{}{ KeyOrderID: orderID, }) - globals.SugarLogger.Debugf("=resutl := %s", utils.Format4Output(result, false)) if err != nil { return 0, err } diff --git a/platformapi/mtwmapi/order_test.go b/platformapi/mtwmapi/order_test.go index 99a41e75..b00c793e 100644 --- a/platformapi/mtwmapi/order_test.go +++ b/platformapi/mtwmapi/order_test.go @@ -77,18 +77,22 @@ func TestOrderApplyPartRefund(t *testing.T) { } func TestOrderLogisticsStatus(t *testing.T) { - result, err := api.OrderLogisticsStatus(1100687990339131759) + result, err := api.OrderLogisticsStatus(1100710754248464487) if err != nil { t.Fatal(err) } - if result == 0 { + if result == nil { t.Fatal("result should have value") } t.Log(utils.Format4Output(result, false)) } +func TestGetDeliveryPath(t *testing.T) { + api.GetDeliveryPath(1000713330160837459, "7821254") +} + func TestOrderLogisticsFee(t *testing.T) { - result, err := api.OrderLogisticsFee(900699454211738469) + result, err := api.OrderLogisticsFee(1100709560902354698) if err != nil { t.Fatal(err) } diff --git a/platformapi/tonglianpayapi/tonglianpayapi.go b/platformapi/tonglianpayapi/tonglianpayapi.go index 2f4c9554..6d194fcc 100644 --- a/platformapi/tonglianpayapi/tonglianpayapi.go +++ b/platformapi/tonglianpayapi/tonglianpayapi.go @@ -3,7 +3,6 @@ package tonglianpayapi import ( "crypto/md5" "fmt" - "git.rosy.net.cn/jx-callback/globals" "net/http" "sort" "strings" @@ -193,8 +192,6 @@ func (a *API) CreateUnitorderOrder(param *CreateUnitorderOrderParam) (result *Cr params["paytype"] = param.PayType params["sub_appid"] = param.SubAppID retVal, err := a.AccessAPI(sepcAction, params) - globals.SugarLogger.Debugf("===========err := %s", utils.Format4Output(retVal, false)) - globals.SugarLogger.Debugf("===========err := %s", utils.Format4Output(err, false)) if err == nil { utils.Map2StructByJson(retVal, &result, false) } diff --git a/platformapi/weixinapi/cgibin.go b/platformapi/weixinapi/cgibin.go index b47fcb45..d548e919 100644 --- a/platformapi/weixinapi/cgibin.go +++ b/platformapi/weixinapi/cgibin.go @@ -1,6 +1,8 @@ package weixinapi -import "git.rosy.net.cn/baseapi/utils" +import ( + "git.rosy.net.cn/baseapi/utils" +) const ( MaxRemarkByteCount = 30 @@ -90,6 +92,7 @@ func (a *API) CBMessageTemplateSend(userOpenID, templateID, downloadURL string, if miniProgram != nil { bodyJson["miniprogram"] = miniProgram } + _, err = a.AccessAPI("cgi-bin/message/template/send", nil, string(utils.MustMarshal(bodyJson))) return err } diff --git a/platformapi/weixinapi/cgibin_test.go b/platformapi/weixinapi/cgibin_test.go index c0f70aba..e7dc6da8 100644 --- a/platformapi/weixinapi/cgibin_test.go +++ b/platformapi/weixinapi/cgibin_test.go @@ -23,7 +23,7 @@ func TestCBMessageTemplateSend(t *testing.T) { // "oYN_usk0AeGc_C6VEZfmFQP5VHMQ": 1, // 周小扬 // "oYN_ust9hXKEvEv0X6Mq6nlAWs_E": 1, // me // "oYN_usvnObzrPweIgHTad9-uMf78": 1, // 老赵 - err := api.CBMessageTemplateSend("oYN_uskWlggFxGNZtagNh-cqfTQs", "b8-tLyWwAmK-1tEU1eGqp_YAAqQtSzoVDZkHuyUe9lk", "", map[string]interface{}{ + err := api.CBMessageTemplateSend("oYN_usjzxL9LBzh_hjf0-E_LGmvs", "b8-tLyWwAmK-1tEU1eGqp_YAAqQtSzoVDZkHuyUe9lk", "", map[string]interface{}{ "appid": "wx4b5930c13f8b1170", //"pagepath": "pages/order-manager/main", }, map[string]interface{}{ diff --git a/platformapi/mtpsapi/riderInfo.go b/utils/riderInfo.go similarity index 95% rename from platformapi/mtpsapi/riderInfo.go rename to utils/riderInfo.go index d9ed7be2..ca6267c4 100644 --- a/platformapi/mtpsapi/riderInfo.go +++ b/utils/riderInfo.go @@ -1,4 +1,4 @@ -package mtpsapi +package utils const ( DaDaCode = "10002" // 达达配送 @@ -10,6 +10,7 @@ const ( MyselfPsCode = "10015" // 自送 ) +// RiderInfo 三方配送骑手状态,兼容平台配送骑手状态 type RiderInfo struct { OrderId string `json:"order_id"` // 发单平台订单id(美团,京西,京,京东) ThirdCarrierOrderId string `json:"third_carrier_order_id"` // 京西平台id(运单id)