This commit is contained in:
邹宗楠
2023-09-06 13:50:39 +08:00
parent c207268323
commit 56588c5738
13 changed files with 177 additions and 11 deletions

View File

@@ -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

View File

@@ -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) + 600
}
return polyLineList, distance, duration, nil
}

View File

@@ -0,0 +1,22 @@
package autonavi
// 高德骑行计划账号配置
const (
AMAPCyclingPlanKey1 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 成都若溪科技有限公司 18048531223 Rosy201507
AMAPCyclingPlanKey2 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 成都京西到家网络科技有限公司 18080188338 Rosy201507
AMAPCyclingPlanKey3 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 冲天猴儿(成都)科技有限公司 19802843833 Rosy201507
AMAPCyclingPlanKey4 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 京西(成都)科技有限公司 18884789801 Rosy201507
AMAPCyclingPlanKey5 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 京西菜市(北京)科技有限公司 17723303721 Rosy201507
)
// 错误码
const (
DAILYQUERYOVERLIMIT = "10003" // 访问已超出日访问量
)
// BaseUrl 基础访问链接
const BaseUrl = "https://restapi.amap.com/v5"
// 白名单
//148.70.158.63
//132.232.12.131

View File

@@ -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"` // 设置后可返回分路段坐标点串,两点间用“,”分隔
}

View File

@@ -0,0 +1,17 @@
package autonavi
import (
"fmt"
"testing"
)
func TestGetCyclingPlan(t *testing.T) {
key := "e44ae2850c0ac930b65c9652d2db0321"
a := New(key)
a.GetCyclingPlan("113.854912,22.601450", "113.846355,22.625570")
}
func TestLng(t *testing.T) {
origin := fmt.Sprintf("%f,%f", 113.854912, 22.601450)
fmt.Println(origin)
}

View File

@@ -58,3 +58,10 @@ func TestDirectionLiteRide(t *testing.T) {
fmt.Println(result)
}
func TestName(t *testing.T) {
syncStatus := 1
syncStatus |= 32
fmt.Println(syncStatus)
}

View File

@@ -26,7 +26,7 @@ func init() {
//api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
//商超
api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_r36FEse6_ywebQI65FNNWA") //token_n4TwqCntWWuvQwAawzxC0w
api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_n_YVCkjFuV_0-76UFfNKCg") //token_n4TwqCntWWuvQwAawzxC0w
cookieStr := `
acctId=57396785; token=0bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*; wmPoiId=-1;
`

View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
"time"
)
@@ -555,16 +554,20 @@ 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
}
// OrderLogisticsFee 获取订单配送费
@@ -572,7 +575,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
}

View File

@@ -81,14 +81,14 @@ func TestOrderLogisticsStatus(t *testing.T) {
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 TestOrderLogisticsFee(t *testing.T) {
result, err := api.OrderLogisticsFee(900699454211738469)
result, err := api.OrderLogisticsFee(1100709560902354698)
if err != nil {
t.Fatal(err)
}

View File

@@ -1,6 +1,9 @@
package weixinapi
import "git.rosy.net.cn/baseapi/utils"
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
)
const (
MaxRemarkByteCount = 30
@@ -90,6 +93,8 @@ func (a *API) CBMessageTemplateSend(userOpenID, templateID, downloadURL string,
if miniProgram != nil {
bodyJson["miniprogram"] = miniProgram
}
globals.SugarLogger.Debugf("cgi-bin/message/template/send======================= : %s", utils.Format4Output(bodyJson, false))
_, err = a.AccessAPI("cgi-bin/message/template/send", nil, string(utils.MustMarshal(bodyJson)))
return err
}

View File

@@ -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{}{

View File

@@ -3,6 +3,7 @@ package weixinapi
import (
"bytes"
"fmt"
"git.rosy.net.cn/jx-callback/globals"
"math/rand"
"mime/multipart"
"net/http"
@@ -92,6 +93,8 @@ func (a *API) AccessAPI(action string, params map[string]interface{}, body strin
params2["access_token"] = accessToken
}
globals.SugarLogger.Debugf("AccessAPI====================== :%s", utils.Format4Output(params2, false))
fullURL := utils.GenerateGetURL(prodURL, action, params2)
// baseapi.SugarLogger.Debug(fullURL)

View File

@@ -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)