master
李光春 1 year ago
parent 535d75c175
commit 2bb6fd0d2e

@ -1,5 +1,5 @@
package go_library
func Version() string {
return "1.0.129"
return "1.0.130"
}

@ -0,0 +1,66 @@
package amap
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type GeocodeGeoResponse struct {
Status string `json:"status"`
Info string `json:"info"`
Infocode string `json:"infocode"`
Count string `json:"count"`
Geocodes []struct {
FormattedAddress string `json:"formatted_address"`
Country string `json:"country"`
Province string `json:"province"`
Citycode string `json:"citycode"`
City string `json:"city"`
District string `json:"district"`
Township []interface{} `json:"township"`
Neighborhood struct {
Name []interface{} `json:"name"`
Type []interface{} `json:"type"`
} `json:"neighborhood"`
Building struct {
Name []interface{} `json:"name"`
Type []interface{} `json:"type"`
} `json:"building"`
Adcode string `json:"adcode"`
Street string `json:"street"`
Number string `json:"number"`
Location string `json:"location"`
Level string `json:"level"`
} `json:"geocodes"`
}
type GeocodeGeoResult struct {
Result GeocodeGeoResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newGeocodeGeoResult(result GeocodeGeoResponse, body []byte, http gorequest.Response) *GeocodeGeoResult {
return &GeocodeGeoResult{Result: result, Body: body, Http: http}
}
// GeocodeGeo 地理编码
// https://lbs.amap.com/api/webservice/guide/api/georegeo
func (c *Client) GeocodeGeo(ctx context.Context, address string, notMustParams ...gorequest.Params) (*GeocodeGeoResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("key", c.GetKey())
params.Set("address", address)
params.Set("output", "JSON")
// 请求
request, err := c.request(ctx, apiUrl+"/geocode/geo", params, http.MethodGet)
if err != nil {
return newGeocodeGeoResult(GeocodeGeoResponse{}, request.ResponseBody, request), err
}
// 定义
var response GeocodeGeoResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newGeocodeGeoResult(response, request.ResponseBody, request), err
}

@ -0,0 +1,113 @@
package amap
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type GeocodeRegeoResponse struct {
Status string `json:"status"`
Regeocode struct {
Roads []struct {
Id string `json:"id"`
Location string `json:"location"`
Direction string `json:"direction"`
Name string `json:"name"`
Distance string `json:"distance"`
} `json:"roads"`
Roadinters []struct {
SecondName string `json:"second_name"`
FirstId string `json:"first_id"`
SecondId string `json:"second_id"`
Location string `json:"location"`
Distance string `json:"distance"`
FirstName string `json:"first_name"`
Direction string `json:"direction"`
} `json:"roadinters"`
FormattedAddress string `json:"formatted_address"`
AddressComponent struct {
City []interface{} `json:"city"`
Province string `json:"province"`
Adcode string `json:"adcode"`
District string `json:"district"`
Towncode string `json:"towncode"`
StreetNumber struct {
Number string `json:"number"`
Location string `json:"location"`
Direction string `json:"direction"`
Distance string `json:"distance"`
Street string `json:"street"`
} `json:"streetNumber"`
Country string `json:"country"`
Township string `json:"township"`
BusinessAreas []struct {
Location string `json:"location"`
Name string `json:"name"`
Id string `json:"id"`
} `json:"businessAreas"`
Building struct {
Name string `json:"name"`
Type string `json:"type"`
} `json:"building"`
Neighborhood struct {
Name string `json:"name"`
Type string `json:"type"`
} `json:"neighborhood"`
Citycode string `json:"citycode"`
} `json:"addressComponent"`
Aois []struct {
Area string `json:"area"`
Type string `json:"type"`
Id string `json:"id"`
Location string `json:"location"`
Adcode string `json:"adcode"`
Name string `json:"name"`
Distance string `json:"distance"`
} `json:"aois"`
Pois []struct {
Id string `json:"id"`
Direction string `json:"direction"`
Businessarea string `json:"businessarea"`
Address string `json:"address"`
Poiweight string `json:"poiweight"`
Name string `json:"name"`
Location string `json:"location"`
Distance string `json:"distance"`
Tel interface{} `json:"tel"`
Type string `json:"type"`
} `json:"pois"`
} `json:"regeocode"`
Info string `json:"info"`
Infocode string `json:"infocode"`
}
type GeocodeRegeoResult struct {
Result GeocodeRegeoResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newGeocodeRegeoResult(result GeocodeRegeoResponse, body []byte, http gorequest.Response) *GeocodeRegeoResult {
return &GeocodeRegeoResult{Result: result, Body: body, Http: http}
}
// GeocodeRegeo 逆地理编码
// https://lbs.amap.com/api/webservice/guide/api/georegeo
func (c *Client) GeocodeRegeo(ctx context.Context, location string, notMustParams ...gorequest.Params) (*GeocodeRegeoResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("key", c.GetKey())
params.Set("location", location)
params.Set("output", "JSON")
// 请求
request, err := c.request(ctx, apiUrl+"/geocode/regeo", params, http.MethodGet)
if err != nil {
return newGeocodeRegeoResult(GeocodeRegeoResponse{}, request.ResponseBody, request), err
}
// 定义
var response GeocodeRegeoResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newGeocodeRegeoResult(response, request.ResponseBody, request), err
}

@ -0,0 +1,51 @@
package baidu
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type GeocodingResponse struct {
Status int `json:"status"`
Result struct {
Location struct {
Lng float64 `json:"lng"`
Lat float64 `json:"lat"`
} `json:"location"`
Precise int `json:"precise"`
Confidence int `json:"confidence"`
Comprehension int `json:"comprehension"`
Level string `json:"level"`
} `json:"result"`
}
type GeocodingResult struct {
Result GeocodingResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newGeocodingResult(result GeocodingResponse, body []byte, http gorequest.Response) *GeocodingResult {
return &GeocodingResult{Result: result, Body: body, Http: http}
}
// Geocoding 地理编码服务
// https://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding
func (c *Client) Geocoding(ctx context.Context, address string, notMustParams ...gorequest.Params) (*GeocodingResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("ak", c.GetAk())
params.Set("address", address)
params.Set("output", "json")
// 请求
request, err := c.request(ctx, apiUrl+"/geocoding/v3/", params, http.MethodGet)
if err != nil {
return newGeocodingResult(GeocodingResponse{}, request.ResponseBody, request), err
}
// 定义
var response GeocodingResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newGeocodingResult(response, request.ResponseBody, request), err
}

@ -0,0 +1,71 @@
package baidu
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type ReverseGeocodingResponse struct {
Status int `json:"status"`
Result struct {
Location struct {
Lng float64 `json:"lng"`
Lat float64 `json:"lat"`
} `json:"location"`
FormattedAddress string `json:"formatted_address"`
Business string `json:"business"`
AddressComponent struct {
Country string `json:"country"`
CountryCode int `json:"country_code"`
CountryCodeIso string `json:"country_code_iso"`
CountryCodeIso2 string `json:"country_code_iso2"`
Province string `json:"province"`
City string `json:"city"`
CityLevel int `json:"city_level"`
District string `json:"district"`
Town string `json:"town"`
TownCode string `json:"town_code"`
Distance string `json:"distance"`
Direction string `json:"direction"`
Adcode string `json:"adcode"`
Street string `json:"street"`
StreetNumber string `json:"street_number"`
} `json:"addressComponent"`
Pois []interface{} `json:"pois"`
Roads []interface{} `json:"roads"`
PoiRegions []interface{} `json:"poiRegions"`
SematicDescription string `json:"sematic_description"`
CityCode int `json:"cityCode"`
} `json:"result"`
}
type ReverseGeocodingResult struct {
Result ReverseGeocodingResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newReverseGeocodingResult(result ReverseGeocodingResponse, body []byte, http gorequest.Response) *ReverseGeocodingResult {
return &ReverseGeocodingResult{Result: result, Body: body, Http: http}
}
// ReverseGeocoding 全球逆地理编码服务
// https://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding-abroad
func (c *Client) ReverseGeocoding(ctx context.Context, location string, notMustParams ...gorequest.Params) (*ReverseGeocodingResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("ak", c.GetAk())
params.Set("location", location)
params.Set("output", "json")
// 请求
request, err := c.request(ctx, apiUrl+"/reverse_geocoding/v3/", params, http.MethodGet)
if err != nil {
return newReverseGeocodingResult(ReverseGeocodingResponse{}, request.ResponseBody, request), err
}
// 定义
var response ReverseGeocodingResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newReverseGeocodingResult(response, request.ResponseBody, request), err
}

@ -223,7 +223,7 @@ func newDailyResult(result DailyResponse, body []byte, http gorequest.Response)
// Daily 天级别预报
// https://docs.caiyunapp.com/docs/daily
func (c *Client) Daily(ctx context.Context, locationLatitude, locationLongitude string, notMustParams ...gorequest.Params) (*DailyResult, error) {
func (c *Client) Daily(ctx context.Context, locationLongitude, locationLatitude string, notMustParams ...gorequest.Params) (*DailyResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求

@ -95,7 +95,7 @@ func newHourlyResult(result HourlyResponse, body []byte, http gorequest.Response
// Hourly 小时级别预报
// https://docs.caiyunapp.com/docs/hourly
func (c *Client) Hourly(ctx context.Context, locationLatitude, locationLongitude string, notMustParams ...gorequest.Params) (*HourlyResult, error) {
func (c *Client) Hourly(ctx context.Context, locationLongitude, locationLatitude string, notMustParams ...gorequest.Params) (*HourlyResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求

@ -44,7 +44,7 @@ func newMinutelyResult(result MinutelyResponse, body []byte, http gorequest.Resp
// Minutely 分钟级预报
// https://docs.caiyunapp.com/docs/minutely
func (c *Client) Minutely(ctx context.Context, locationLatitude, locationLongitude string, notMustParams ...gorequest.Params) (*MinutelyResult, error) {
func (c *Client) Minutely(ctx context.Context, locationLongitude, locationLatitude string, notMustParams ...gorequest.Params) (*MinutelyResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求

@ -88,7 +88,7 @@ func newRealtimeResult(result RealtimeResponse, body []byte, http gorequest.Resp
// Realtime 实况
// https://docs.caiyunapp.com/docs/realtime
func (c *Client) Realtime(ctx context.Context, locationLatitude, locationLongitude string, notMustParams ...gorequest.Params) (*RealtimeResult, error) {
func (c *Client) Realtime(ctx context.Context, locationLongitude, locationLatitude string, notMustParams ...gorequest.Params) (*RealtimeResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求

@ -46,7 +46,7 @@ func newWeatherResult(result WeatherResponse, body []byte, http gorequest.Respon
// Weather 综合
// https://docs.caiyunapp.com/docs/weather
func (c *Client) Weather(ctx context.Context, locationLatitude, locationLongitude string, notMustParams ...gorequest.Params) (*WeatherResult, error) {
func (c *Client) Weather(ctx context.Context, locationLongitude, locationLatitude string, notMustParams ...gorequest.Params) (*WeatherResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求

@ -0,0 +1,63 @@
package qq
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type GeocoderAddressResponse struct {
Status int `json:"status"`
Message string `json:"message"`
Result struct {
Title string `json:"title"`
Location struct {
Lng float64 `json:"lng"`
Lat float64 `json:"lat"`
} `json:"location"`
AdInfo struct {
Adcode string `json:"adcode"`
} `json:"ad_info"`
AddressComponents struct {
Province string `json:"province"`
City string `json:"city"`
District string `json:"district"`
Street string `json:"street"`
StreetNumber string `json:"street_number"`
} `json:"address_components"`
Similarity float64 `json:"similarity"`
Deviation int `json:"deviation"`
Reliability int `json:"reliability"`
Level int `json:"level"`
} `json:"result"`
}
type GeocoderAddressResult struct {
Result GeocoderAddressResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newGeocoderAddressResult(result GeocoderAddressResponse, body []byte, http gorequest.Response) *GeocoderAddressResult {
return &GeocoderAddressResult{Result: result, Body: body, Http: http}
}
// GeocoderAddress 地址解析(地址转坐标)
// https://lbs.qq.com/service/webService/webServiceGuide/webServiceGeocoder
func (c *Client) GeocoderAddress(ctx context.Context, address string, notMustParams ...gorequest.Params) (*GeocoderAddressResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("key", c.GetKey())
params.Set("address", address)
params.Set("output", "JSON")
// 请求
request, err := c.request(ctx, apiUrl+"/ws/geocoder/v1/", params, http.MethodGet)
if err != nil {
return newGeocoderAddressResult(GeocoderAddressResponse{}, request.ResponseBody, request), err
}
// 定义
var response GeocoderAddressResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newGeocoderAddressResult(response, request.ResponseBody, request), err
}

@ -0,0 +1,168 @@
package qq
import (
"context"
"github.com/dtapps/go-library/utils/gojson"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type GeocoderLocationResponse struct {
Status int `json:"status"`
Message string `json:"message"`
RequestId string `json:"request_id"`
Result struct {
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Address string `json:"address"`
FormattedAddresses struct {
Recommend string `json:"recommend"`
Rough string `json:"rough"`
} `json:"formatted_addresses"`
AddressComponent struct {
Nation string `json:"nation"`
Province string `json:"province"`
City string `json:"city"`
District string `json:"district"`
Street string `json:"street"`
StreetNumber string `json:"street_number"`
} `json:"address_component"`
AdInfo struct {
NationCode string `json:"nation_code"`
Adcode string `json:"adcode"`
PhoneAreaCode string `json:"phone_area_code"`
CityCode string `json:"city_code"`
Name string `json:"name"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Nation string `json:"nation"`
Province string `json:"province"`
City string `json:"city"`
District string `json:"district"`
} `json:"ad_info"`
AddressReference struct {
BusinessArea struct {
Id string `json:"id"`
Title string `json:"title"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Distance int `json:"_distance"`
DirDesc string `json:"_dir_desc"`
} `json:"business_area"`
FamousArea struct {
Id string `json:"id"`
Title string `json:"title"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Distance int `json:"_distance"`
DirDesc string `json:"_dir_desc"`
} `json:"famous_area"`
Crossroad struct {
Id string `json:"id"`
Title string `json:"title"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Distance float64 `json:"_distance"`
DirDesc string `json:"_dir_desc"`
} `json:"crossroad"`
Town struct {
Id string `json:"id"`
Title string `json:"title"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Distance int `json:"_distance"`
DirDesc string `json:"_dir_desc"`
} `json:"town"`
StreetNumber struct {
Id string `json:"id"`
Title string `json:"title"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Distance float64 `json:"_distance"`
DirDesc string `json:"_dir_desc"`
} `json:"street_number"`
Street struct {
Id string `json:"id"`
Title string `json:"title"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Distance float64 `json:"_distance"`
DirDesc string `json:"_dir_desc"`
} `json:"street"`
LandmarkL2 struct {
Id string `json:"id"`
Title string `json:"title"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
Distance int `json:"_distance"`
DirDesc string `json:"_dir_desc"`
} `json:"landmark_l2"`
} `json:"address_reference"`
PoiCount int `json:"poi_count"`
Pois []struct {
Id string `json:"id"`
Title string `json:"title"`
Address string `json:"address"`
Category string `json:"category"`
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
AdInfo struct {
Adcode string `json:"adcode"`
Province string `json:"province"`
City string `json:"city"`
District string `json:"district"`
} `json:"ad_info"`
Distance float64 `json:"_distance"`
DirDesc string `json:"_dir_desc,omitempty"`
} `json:"pois"`
} `json:"result"`
}
type GeocoderLocationResult struct {
Result GeocoderLocationResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newGeocoderLocationResult(result GeocoderLocationResponse, body []byte, http gorequest.Response) *GeocoderLocationResult {
return &GeocoderLocationResult{Result: result, Body: body, Http: http}
}
// GeocoderLocation 逆地址解析(坐标位置描述)
// https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
func (c *Client) GeocoderLocation(ctx context.Context, location string, notMustParams ...gorequest.Params) (*GeocoderLocationResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("key", c.GetKey())
params.Set("location", location)
params.Set("output", "JSON")
// 请求
request, err := c.request(ctx, apiUrl+"/ws/geocoder/v1/", params, http.MethodGet)
if err != nil {
return newGeocoderLocationResult(GeocoderLocationResponse{}, request.ResponseBody, request), err
}
// 定义
var response GeocoderLocationResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newGeocoderLocationResult(response, request.ResponseBody, request), err
}
Loading…
Cancel
Save