1
This commit is contained in:
@@ -2,16 +2,16 @@ package baidunavi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi"
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -201,63 +201,73 @@ func (a *API) BatchCoordinateConvert(coords []*Coordinate, fromCoordSys, toCoord
|
|||||||
for _, v := range coords {
|
for _, v := range coords {
|
||||||
coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat))
|
coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat))
|
||||||
}
|
}
|
||||||
params := map[string]interface{}{
|
|
||||||
"coords": strings.Join(coordsStrList, ";"),
|
params := url.Values{
|
||||||
"from": fromCoordSys,
|
"coords": []string{strings.Join(coordsStrList, ";")},
|
||||||
"to": toCoordSys,
|
"from": []string{utils.Int2Str(fromCoordSys)},
|
||||||
|
"to": []string{utils.Int2Str(toCoordSys)},
|
||||||
}
|
}
|
||||||
result, err := a.AccessAPI("geoconv/v1", params)
|
|
||||||
|
result, err := a.AccessAPI2("geoconv/v1/", params)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = utils.Map2StructByJson(result, &outCoords, false)
|
err = utils.Map2StructByJson(result, &outCoords, false)
|
||||||
}
|
}
|
||||||
return outCoords, err
|
return outCoords, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DirectionLiteRide 骑行路线规划
|
|
||||||
func (a *API) DirectionLiteRide(coords []*Coordinate) (retVal interface{}, err error) {
|
func (a *API) DirectionLiteRide(coords []*Coordinate) (retVal interface{}, err error) {
|
||||||
var (
|
var (
|
||||||
sCoords string
|
sCoords string
|
||||||
uCoords string
|
uCoords string
|
||||||
timestamp = time.Now().Unix()
|
|
||||||
apiStr = "directionlite/v1/riding"
|
apiStr = "directionlite/v1/riding"
|
||||||
)
|
)
|
||||||
sCoords = utils.Float64ToStr(coords[0].Lat) + "," + utils.Float64ToStr(coords[0].Lng)
|
sCoords = utils.Float64ToStr(coords[0].Lat) + "," + utils.Float64ToStr(coords[0].Lng)
|
||||||
uCoords = utils.Float64ToStr(coords[1].Lat) + "," + utils.Float64ToStr(coords[1].Lng)
|
uCoords = utils.Float64ToStr(coords[1].Lat) + "," + utils.Float64ToStr(coords[1].Lng)
|
||||||
|
|
||||||
param := map[string]interface{}{
|
param := url.Values{
|
||||||
"origin": sCoords,
|
|
||||||
"destination": uCoords,
|
|
||||||
"timestamp": timestamp,
|
|
||||||
//"steps_info": 2,
|
|
||||||
}
|
|
||||||
//生成签名
|
|
||||||
params2 := utils.MergeMaps(utils.Params2Map("ak", a.ak, "output", "json"), param)
|
|
||||||
sn := a.signParams(apiStr, params2)
|
|
||||||
|
|
||||||
params := url.Values{
|
|
||||||
"origin": []string{sCoords},
|
"origin": []string{sCoords},
|
||||||
"destination": []string{uCoords},
|
"destination": []string{uCoords},
|
||||||
"ak": []string{a.ak},
|
|
||||||
"sn": []string{sn},
|
|
||||||
"timestamp": []string{utils.Int64ToStr(timestamp)},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp, err := a.AccessAPI2(apiStr, param)
|
||||||
|
if err == nil {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) AccessAPI2(apiStr string, param url.Values) (retVal interface{}, err error) {
|
||||||
|
|
||||||
|
for _, v := range BaidunaviAKList {
|
||||||
|
param.Add("ak", v)
|
||||||
|
param.Add("output", "json")
|
||||||
|
params2 := map[string]interface{}{}
|
||||||
|
|
||||||
|
for i, j := range param {
|
||||||
|
params2[i] = j
|
||||||
|
}
|
||||||
|
params2[signKey] = a.signParams(apiStr, params2)
|
||||||
|
|
||||||
|
param.Add("timestamp", utils.Int64ToStr(time.Now().Unix()))
|
||||||
|
|
||||||
// 发起请求
|
// 发起请求
|
||||||
request, err := url.Parse(prodURL2 + "/" + apiStr + "?" + params.Encode())
|
request, err := url.Parse(prodURL2 + "/" + apiStr + "?" + param.Encode())
|
||||||
if nil != err {
|
if err != nil {
|
||||||
return nil, err
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err1 := http.Get(request.String())
|
resp, err1 := http.Get(request.String())
|
||||||
defer resp.Body.Close()
|
//err1 = errors.New("测试退出退出")
|
||||||
if err1 != nil {
|
//defer resp.Body.Close()
|
||||||
return nil, err1
|
|
||||||
}
|
|
||||||
body, err2 := ioutil.ReadAll(resp.Body)
|
body, err2 := ioutil.ReadAll(resp.Body)
|
||||||
if err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
return nil, err2
|
continue
|
||||||
}
|
}
|
||||||
result := string(body)
|
result := string(body)
|
||||||
|
if err == nil {
|
||||||
return result, nil
|
return result, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errors.New("所有百度应用额度均用完")
|
||||||
}
|
}
|
||||||
|
|||||||
12
platformapi/baidunavi/baidunavi_const.go
Normal file
12
platformapi/baidunavi/baidunavi_const.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package baidunavi
|
||||||
|
|
||||||
|
const (
|
||||||
|
BaiduAK1 = "wW2AwzPS0hdaPy5QLalzso7ARX5uYZtZ" //京西菜市
|
||||||
|
BaiduAK2 = "LdvYnRCGsu2m2ZG2CeWR2nCG9NDPhR3G" //京西到家
|
||||||
|
BaiduAK3 = "vISH1MiDm67sb95sNUrdWPgjOmQMGFw3" //京西菜市成都
|
||||||
|
BaiduAK4 = "PGGAGMpF2dksZo37QhPlEmB8U78Qo5SG" //京西菜市北京
|
||||||
|
BaiduAK5 = "uOcPyMnToC5VFbosVhb2zimPRbizd72k" //冲天猴
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
var BaidunaviAKList = []string{BaiduAK1, BaiduAK2, BaiduAK3, BaiduAK4, BaiduAK5}
|
||||||
@@ -21,7 +21,8 @@ func init() {
|
|||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
|
|
||||||
//api = New("eL94zToVOdGDTkNQxV8dnEQ1ZRcB2UKb", "ZG0OOpOsOVURUwAkkmoHQFKRCbzn0zGb")
|
//api = New("eL94zToVOdGDTkNQxV8dnEQ1ZRcB2UKb", "ZG0OOpOsOVURUwAkkmoHQFKRCbzn0zGb")
|
||||||
api = New("wW2AwzPS0hdaPy5QLalzso7ARX5uYZtZ", "ZG0OOpOsOVURUwAkkmoHQFKRCbzn0zGb")
|
//api = New("wW2AwzPS0hdaPy5QLalzso7ARX5uYZtZ", "ZG0OOpOsOVURUwAkkmoHQFKRCbzn0zGb")
|
||||||
|
api = New("wW2AwzPS0hdaPy5QLalzso7ARX5uYZtZ", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBatchCoordinateConvert(t *testing.T) {
|
func TestBatchCoordinateConvert(t *testing.T) {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func TestFullDiscountBatchSave(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFullDiscountList(t *testing.T) {
|
func TestFullDiscountList(t *testing.T) {
|
||||||
result, err := api.FullDiscountList("17626555", ActTypeStoreFullDiscount)
|
result, err := api.FullDiscountList("9846711", ActTypeStoreFullDiscount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ func TestRetailDiscountBatchSave(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRetailDiscountList(t *testing.T) { //56 1001
|
func TestRetailDiscountList(t *testing.T) { //56 1001
|
||||||
result, err := api.RetailDiscountList("17626555", 1001)
|
result, err := api.RetailDiscountList("9846711", 1001)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ func init() {
|
|||||||
//api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
|
//api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
|
||||||
|
|
||||||
// 果园
|
// 果园
|
||||||
//api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
|
api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
|
||||||
|
|
||||||
//商超
|
//商超
|
||||||
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_nngsVP37s-HXY86xe85H7Q") //token_n4TwqCntWWuvQwAawzxC0w
|
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_nngsVP37s-HXY86xe85H7Q") //token_n4TwqCntWWuvQwAawzxC0w
|
||||||
api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_rfAD6OxSVxkTeCO1XmNCZg") //token_n4TwqCntWWuvQwAawzxC0w
|
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_rfAD6OxSVxkTeCO1XmNCZg") //token_n4TwqCntWWuvQwAawzxC0w
|
||||||
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_r36FEse6_ywebQI65FNNWA") //token_n4TwqCntWWuvQwAawzxC0w
|
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_r36FEse6_ywebQI65FNNWA") //token_n4TwqCntWWuvQwAawzxC0w
|
||||||
cookieStr := `
|
cookieStr := `
|
||||||
acctId=57396785; token=0bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*; wmPoiId=-1;
|
acctId=57396785; token=0bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*; wmPoiId=-1;
|
||||||
|
|||||||
@@ -50,10 +50,14 @@ func TestGetWaybillPrice(t *testing.T) {
|
|||||||
ToAddress: "嘉华酒店",
|
ToAddress: "嘉华酒店",
|
||||||
CityName: "成都市",
|
CityName: "成都市",
|
||||||
SendType: "0",
|
SendType: "0",
|
||||||
ToLat: "30.691134",
|
ToLat: "29.604639",
|
||||||
ToLng: "104.042307",
|
ToLng: "103.743532",
|
||||||
FromLat: "30.693001",
|
FromLat: "29.608636",
|
||||||
FromLng: "104.04546",
|
FromLng: "103.728641",
|
||||||
|
//ToLat: "29.598951",
|
||||||
|
//ToLng: "103.736961",
|
||||||
|
//FromLat: "29.602826",
|
||||||
|
//FromLng: "103.722107",
|
||||||
}
|
}
|
||||||
price := utils.Struct2Map(param, "", false)
|
price := utils.Struct2Map(param, "", false)
|
||||||
resp, err := api.GetOrderPrice(price)
|
resp, err := api.GetOrderPrice(price)
|
||||||
|
|||||||
Reference in New Issue
Block a user