parent
fcdd3f0c6f
commit
733ac2012b
@ -1,5 +1,5 @@
|
||||
package go_library
|
||||
|
||||
func Version() string {
|
||||
return "1.0.125"
|
||||
return "1.0.126"
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package amap
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package baidu
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package baidu
|
||||
|
||||
const (
|
||||
apiUrl = "https://api.map.baidu.com"
|
||||
)
|
||||
|
||||
const (
|
||||
logTable = "baidu"
|
||||
)
|
||||
|
@ -1,33 +0,0 @@
|
||||
package baidu
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ExpressResponse struct{}
|
||||
|
||||
type ExpressResult struct {
|
||||
Result ExpressResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newExpressResult(result ExpressResponse, body []byte, http gorequest.Response, err error) *ExpressResult {
|
||||
return &ExpressResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// Express ipv1
|
||||
// https://www.cloudflare.com/ips-v4
|
||||
func (c *Client) Express() *ExpressResult {
|
||||
// 参数
|
||||
params := gorequest.NewParams()
|
||||
// 请求
|
||||
request, err := c.request("https://m.baidu.com/s?word=快递查询&ts={$ts}&t_kt=0&ie=utf-8&rsv_iqid=&rsv_t=&sa=&rsv_pq=&rsv_sug4=&tj=1&inputT={$input}&sugid=&ss=", params, http.MethodPost)
|
||||
// 定义
|
||||
var response ExpressResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newExpressResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package baidu
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetAk() string {
|
||||
return c.config.ak
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package baidu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type LocationIpResponse struct {
|
||||
Address string `json:"address"` // 详细地址信息
|
||||
Content struct {
|
||||
AddressDetail struct {
|
||||
Province string `json:"province"` // 省份
|
||||
City string `json:"city"` // 城市
|
||||
District string `json:"district"`
|
||||
Street string `json:"street"`
|
||||
StreetNumber string `json:"street_number"`
|
||||
CityCode int `json:"city_code"` // 百度城市代码
|
||||
Adcode string `json:"adcode"`
|
||||
} `json:"address_detail"`
|
||||
Address string `json:"address"` // 简要地址信息
|
||||
Point struct {
|
||||
X string `json:"x"` // 当前城市中心点经度
|
||||
Y string `json:"y"` // 当前城市中心点纬度
|
||||
} `json:"point"`
|
||||
} `json:"content"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
type LocationIpResult struct {
|
||||
Result LocationIpResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newLocationIpResult(result LocationIpResponse, body []byte, http gorequest.Response) *LocationIpResult {
|
||||
return &LocationIpResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// LocationIp 普通IP定位
|
||||
// https://lbsyun.baidu.com/index.php?title=webapi/ip-api
|
||||
func (c *Client) LocationIp(ctx context.Context, ip string, notMustParams ...gorequest.Params) (*LocationIpResult, error) {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
params.Set("ak", c.GetAk())
|
||||
params.Set("ip", ip)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/location/ip", params, http.MethodGet)
|
||||
if err != nil {
|
||||
return newLocationIpResult(LocationIpResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response LocationIpResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newLocationIpResult(response, request.ResponseBody, request), err
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package baidu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WeatherResponse struct {
|
||||
Status int `json:"status"`
|
||||
Result struct {
|
||||
Location struct {
|
||||
Country string `json:"country"`
|
||||
Province string `json:"province"`
|
||||
City string `json:"city"`
|
||||
Name string `json:"name"`
|
||||
Id string `json:"id"`
|
||||
} `json:"location"`
|
||||
Now struct {
|
||||
Text string `json:"text"`
|
||||
Temp int `json:"temp"`
|
||||
FeelsLike int `json:"feels_like"`
|
||||
Rh int `json:"rh"`
|
||||
WindClass string `json:"wind_class"`
|
||||
WindDir string `json:"wind_dir"`
|
||||
Uptime string `json:"uptime"`
|
||||
} `json:"now"`
|
||||
Forecasts []struct {
|
||||
TextDay string `json:"text_day"`
|
||||
TextNight string `json:"text_night"`
|
||||
High int `json:"high"`
|
||||
Low int `json:"low"`
|
||||
WcDay string `json:"wc_day"`
|
||||
WdDay string `json:"wd_day"`
|
||||
WcNight string `json:"wc_night"`
|
||||
WdNight string `json:"wd_night"`
|
||||
Date string `json:"date"`
|
||||
Week string `json:"week"`
|
||||
} `json:"forecasts"`
|
||||
} `json:"result"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type WeatherResult struct {
|
||||
Result WeatherResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWeatherResult(result WeatherResponse, body []byte, http gorequest.Response) *WeatherResult {
|
||||
return &WeatherResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// Weather 国内天气查询服务
|
||||
// https://lbsyun.baidu.com/index.php?title=webapi/weather
|
||||
func (c *Client) Weather(ctx context.Context, districtId string, notMustParams ...gorequest.Params) (*WeatherResult, error) {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
params.Set("ak", c.GetAk())
|
||||
params.Set("district_id", districtId)
|
||||
params.Set("output", "json")
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/weather/v1/", params, http.MethodGet)
|
||||
if err != nil {
|
||||
return newWeatherResult(WeatherResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WeatherResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWeatherResult(response, request.ResponseBody, request), err
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package qq
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
Loading…
Reference in new issue