Compare commits
114 Commits
Author | SHA1 | Date |
---|---|---|
李光春 | 7e7d891e9d | 9 months ago |
李光春 | b3963e6e92 | 9 months ago |
李光春 | 36b3f3e8df | 9 months ago |
李光春 | 7547e8251c | 9 months ago |
李光春 | 894d5f3b85 | 9 months ago |
李光春 | a2f67b40aa | 9 months ago |
李光春 | 81a73cf248 | 9 months ago |
李光春 | ecd418c96c | 9 months ago |
李光春 | 9a7764a98b | 9 months ago |
李光春 | 37af6411fd | 9 months ago |
李光春 | 0bf72b945e | 9 months ago |
李光春 | b612eab3d8 | 9 months ago |
李光春 | 624394f6d4 | 9 months ago |
李光春 | 3d3c2109ae | 9 months ago |
李光春 | 7d30f4f791 | 9 months ago |
李光春 | 32895c815d | 9 months ago |
李光春 | 315d1a7c0b | 9 months ago |
李光春 | efda705822 | 9 months ago |
李光春 | 9d1ad9e708 | 9 months ago |
李光春 | afad52b41f | 9 months ago |
李光春 | c4c56d63d5 | 9 months ago |
李光春 | d3ebd06eda | 10 months ago |
李光春 | ff052e838e | 10 months ago |
李光春 | 1099e35ff9 | 10 months ago |
李光春 | 0e505abfd7 | 10 months ago |
李光春 | 1ee569b43a | 10 months ago |
李光春 | c22e2ce46e | 10 months ago |
李光春 | 4f086f2626 | 11 months ago |
李光春 | dc3bc54468 | 11 months ago |
李光春 | 6e49867d6f | 11 months ago |
李光春 | f3654bb868 | 11 months ago |
李光春 | 6c9c05afa2 | 11 months ago |
李光春 | f947bad45d | 11 months ago |
李光春 | 0eb1f6a62b | 11 months ago |
李光春 | b28923b086 | 1 year ago |
李光春 | 3250e2402f | 1 year ago |
李光春 | b2ee634db1 | 1 year ago |
李光春 | 1d7ef4fb34 | 1 year ago |
李光春 | 49df014426 | 1 year ago |
李光春 | 19b44285e3 | 1 year ago |
李光春 | eb28bb82ec | 1 year ago |
李光春 | 8f236f4832 | 1 year ago |
李光春 | 6137f53c38 | 1 year ago |
李光春 | 003f87b4d7 | 1 year ago |
李光春 | f415a8ef19 | 1 year ago |
李光春 | f762653c62 | 1 year ago |
李光春 | ae848ac95d | 1 year ago |
李光春 | af516e8040 | 1 year ago |
李光春 | a5294551f0 | 1 year ago |
李光春 | 2486eeba26 | 1 year ago |
李光春 | e440a5dccb | 1 year ago |
李光春 | abcb9cdce0 | 1 year ago |
李光春 | 470f5dba37 | 1 year ago |
李光春 | c238ba648a | 1 year ago |
李光春 | 4f4201a9ca | 1 year ago |
李光春 | b40a8afea0 | 1 year ago |
李光春 | 61d1c2f975 | 1 year ago |
李光春 | f4c498a916 | 1 year ago |
李光春 | e97ef679f5 | 1 year ago |
李光春 | c4d4e3a29a | 1 year ago |
李光春 | 6286960982 | 1 year ago |
李光春 | 6443d8b05b | 1 year ago |
李光春 | e16702fcb6 | 1 year ago |
李光春 | 96cd1fc326 | 1 year ago |
李光春 | 50011b492a | 1 year ago |
李光春 | 4094a91645 | 1 year ago |
李光春 | 03adb53e41 | 1 year ago |
李光春 | b9ced960c0 | 1 year ago |
李光春 | 9d5d1efff1 | 1 year ago |
李光春 | fa2a2e15ab | 1 year ago |
李光春 | 50d5b3216c | 1 year ago |
李光春 | fdd6dfbc63 | 1 year ago |
李光春 | 5ac7b3ef0a | 1 year ago |
李光春 | b9d5e40fe1 | 1 year ago |
李光春 | 41f01c0dd6 | 1 year ago |
李光春 | 4585d3f4a2 | 1 year ago |
李光春 | b141867b87 | 1 year ago |
李光春 | eee9be019c | 1 year ago |
李光春 | 2bb6fd0d2e | 1 year ago |
李光春 | 535d75c175 | 1 year ago |
李光春 | bf3c02d004 | 1 year ago |
李光春 | 7cac7a8f72 | 1 year ago |
李光春 | 733ac2012b | 1 year ago |
李光春 | fcdd3f0c6f | 1 year ago |
李光春 | 69e6bc38d7 | 1 year ago |
李光春 | 68c4d59d03 | 1 year ago |
李光春 | 7329a8c2d1 | 1 year ago |
李光春 | d7d720df1b | 1 year ago |
李光春 | ee837eb351 | 1 year ago |
李光春 | 6da1aa5772 | 1 year ago |
李光春 | ab6661281d | 1 year ago |
李光春 | 873be7b05c | 1 year ago |
李光春 | af820fe08c | 1 year ago |
李光春 | efdef3152a | 1 year ago |
李光春 | b7ee53add0 | 1 year ago |
李光春 | 9669639225 | 1 year ago |
李光春 | 07f8e4e1e4 | 1 year ago |
李光春 | 75239c0ad6 | 1 year ago |
李光春 | 831266f9fb | 1 year ago |
李光春 | a0c4903cd4 | 1 year ago |
李光春 | 45207efad1 | 1 year ago |
李光春 | 7c1c532c8f | 1 year ago |
李光春 | a0e6bcb331 | 1 year ago |
李光春 | 0e39809c43 | 1 year ago |
李光春 | 278e19fb40 | 1 year ago |
李光春 | 634db15adf | 1 year ago |
李光春 | b81beb300b | 1 year ago |
李光春 | b3896afd96 | 1 year ago |
李光春 | 2a2a8e151c | 1 year ago |
李光春 | b8bf6d7288 | 1 year ago |
李光春 | 85200de579 | 1 year ago |
李光春 | 88d7de18cb | 1 year ago |
李光春 | 52e43d730b | 1 year ago |
李光春 | 70e338cdd6 | 1 year ago |
@ -1,5 +1,5 @@
|
|||||||
package go_library
|
package go_library
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return "1.0.108"
|
return "1.0.169"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package alipayopen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) Get(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, c.newParamsWithType(_method, params))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package amap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dtapps/go-library/utils/golog"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClientConfig 实例配置
|
||||||
|
type ClientConfig struct {
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client 实例
|
||||||
|
type Client struct {
|
||||||
|
requestClient *gorequest.App // 请求服务
|
||||||
|
config struct {
|
||||||
|
key string
|
||||||
|
}
|
||||||
|
slog struct {
|
||||||
|
status bool // 状态
|
||||||
|
client *golog.ApiSLog // 日志服务
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient 创建实例化
|
||||||
|
func NewClient(config *ClientConfig) (*Client, error) {
|
||||||
|
|
||||||
|
c := &Client{}
|
||||||
|
|
||||||
|
c.config.key = config.Key
|
||||||
|
|
||||||
|
c.requestClient = gorequest.NewHttp()
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package amap
|
||||||
|
|
||||||
|
import "github.com/dtapps/go-library/utils/golog"
|
||||||
|
|
||||||
|
// ConfigSLogClientFun 日志配置
|
||||||
|
func (c *Client) ConfigSLogClientFun(apiSLogFun golog.ApiSLogFun) {
|
||||||
|
apiSLog := apiSLogFun()
|
||||||
|
if apiSLog != nil {
|
||||||
|
c.slog.client = apiSLog
|
||||||
|
c.slog.status = true
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package amap
|
||||||
|
|
||||||
|
const (
|
||||||
|
apiUrl = "https://restapi.amap.com/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LogTable = "amap"
|
||||||
|
)
|
@ -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,5 @@
|
|||||||
|
package amap
|
||||||
|
|
||||||
|
func (c *Client) GetKey() string {
|
||||||
|
return c.config.key
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package amap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
|
||||||
|
|
||||||
|
// 创建请求
|
||||||
|
client := c.requestClient
|
||||||
|
|
||||||
|
// 设置请求地址
|
||||||
|
client.SetUri(url)
|
||||||
|
|
||||||
|
// 设置方式
|
||||||
|
client.SetMethod(method)
|
||||||
|
|
||||||
|
// 设置格式
|
||||||
|
client.SetContentTypeJson()
|
||||||
|
|
||||||
|
// 设置参数
|
||||||
|
client.SetParams(params)
|
||||||
|
|
||||||
|
// 发起请求
|
||||||
|
request, err := client.Request(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return gorequest.Response{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录日志
|
||||||
|
if c.slog.status {
|
||||||
|
go c.slog.client.Middleware(ctx, request)
|
||||||
|
}
|
||||||
|
|
||||||
|
return request, err
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package baidu
|
||||||
|
|
||||||
|
import "github.com/dtapps/go-library/utils/golog"
|
||||||
|
|
||||||
|
// ConfigSLogClientFun 日志配置
|
||||||
|
func (c *Client) ConfigSLogClientFun(apiSLogFun golog.ApiSLogFun) {
|
||||||
|
apiSLog := apiSLogFun()
|
||||||
|
if apiSLog != nil {
|
||||||
|
c.slog.client = apiSLog
|
||||||
|
c.slog.status = true
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
package baidu
|
package baidu
|
||||||
|
|
||||||
const (
|
const (
|
||||||
logTable = "baidu"
|
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,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,5 @@
|
|||||||
|
package baidu
|
||||||
|
|
||||||
|
func (c *Client) GetAk() string {
|
||||||
|
return c.config.ak
|
||||||
|
}
|
@ -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,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
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
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"` // 区县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"` // 风向描述
|
||||||
|
Prec1h float64 `json:"prec_1h"` // 1小时累计降水量(mm)
|
||||||
|
Clouds int `json:"clouds"` // 云量(%)
|
||||||
|
Vis int `json:"vis"` // 能见度(m)
|
||||||
|
Aqi int `json:"aqi"` // 空气质量指数数值
|
||||||
|
Pm25 int `json:"pm25"` // pm2.5浓度(μg/m3)
|
||||||
|
Pm10 int `json:"pm10"` // pm10浓度(μg/m3)
|
||||||
|
No2 int `json:"no2"` // 二氧化氮浓度(μg/m3)
|
||||||
|
So2 int `json:"so2"` // 二氧化硫浓度(μg/m3)
|
||||||
|
O3 int `json:"o3"` // 臭氧浓度(μg/m3)
|
||||||
|
Co float64 `json:"co"` // 一氧化碳浓度(mg/m3)
|
||||||
|
Uptime string `json:"uptime"` // 数据更新时间,北京时间
|
||||||
|
} `json:"now"` // 实况数据
|
||||||
|
Alert []struct {
|
||||||
|
Type string `json:"type"` // 预警事件类型
|
||||||
|
Level string `json:"level"` // 预警事件等级
|
||||||
|
Title string `json:"title"` // 预警标题
|
||||||
|
Desc string `json:"desc"` // 预警详细提示信息
|
||||||
|
} `json:"alert"` // 气象预警数据
|
||||||
|
Indexes []struct {
|
||||||
|
Name string `json:"name"` // 生活指数中文名称
|
||||||
|
Brief string `json:"brief"` // 生活指数概要说明
|
||||||
|
Detail string `json:"detail"` // 生活指数详细说明
|
||||||
|
} `json:"indexes"` // 生活指数数据
|
||||||
|
Forecasts []struct {
|
||||||
|
Date string `json:"date"` // 日期,北京时区
|
||||||
|
Week string `json:"week"` // 星期,北京时区
|
||||||
|
High int `json:"high"` // 最高温度(℃)
|
||||||
|
Low int `json:"low"` // 最低温度(℃)
|
||||||
|
WcDay string `json:"wc_day"` // 白天风力
|
||||||
|
WcNight string `json:"wc_night"` // 晚上风力
|
||||||
|
WdDay string `json:"wd_day"` // 白天风向
|
||||||
|
WdNight string `json:"wd_night"` // 晚上风向
|
||||||
|
TextDay string `json:"text_day"` // 白天天气现象
|
||||||
|
TextNight string `json:"text_night"` // 晚上天气现象
|
||||||
|
} `json:"forecasts"` // 预报数据
|
||||||
|
ForecastHours []struct {
|
||||||
|
Text string `json:"text"` // 天气现象
|
||||||
|
TempFc int `json:"temp_fc"` // 温度(℃)
|
||||||
|
WindClass string `json:"wind_class"` // 风力等级
|
||||||
|
WindDir string `json:"wind_dir"` // 风向描述
|
||||||
|
Rh int `json:"rh"` // 相对湿度
|
||||||
|
Prec1h float64 `json:"prec_1h"` // 1小时累计降水量(mm)
|
||||||
|
Clouds int `json:"clouds"` // 云量(%)
|
||||||
|
DataTime string `json:"data_time"` // 数据时间
|
||||||
|
} `json:"forecast_hours"` // 未来24小时逐小时预报
|
||||||
|
} `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,77 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
func GetCodeType(code string) string {
|
||||||
|
firsTwo := code[:2]
|
||||||
|
switch firsTwo {
|
||||||
|
case "01":
|
||||||
|
return "台风"
|
||||||
|
case "02":
|
||||||
|
return "暴雨"
|
||||||
|
case "03":
|
||||||
|
return "暴雪"
|
||||||
|
case "04":
|
||||||
|
return "寒潮"
|
||||||
|
case "05":
|
||||||
|
return "大风"
|
||||||
|
case "06":
|
||||||
|
return "沙尘暴"
|
||||||
|
case "07":
|
||||||
|
return "高温"
|
||||||
|
case "08":
|
||||||
|
return "干旱"
|
||||||
|
case "09":
|
||||||
|
return "雷电"
|
||||||
|
case "10":
|
||||||
|
return "冰雹"
|
||||||
|
case "11":
|
||||||
|
return "霜冻"
|
||||||
|
case "12":
|
||||||
|
return "大雾"
|
||||||
|
case "13":
|
||||||
|
return "霾"
|
||||||
|
case "14":
|
||||||
|
return "道路结冰"
|
||||||
|
case "15":
|
||||||
|
return "森林火险"
|
||||||
|
case "16":
|
||||||
|
return "雷雨大风"
|
||||||
|
case "17":
|
||||||
|
return "春季沙尘天气趋势预警"
|
||||||
|
case "18":
|
||||||
|
return "沙尘"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
func GetCodeId(code string) string {
|
||||||
|
lastTwo := code[len(code)-2 : 0]
|
||||||
|
switch lastTwo {
|
||||||
|
case "00":
|
||||||
|
return "白色"
|
||||||
|
case "01":
|
||||||
|
return "蓝色"
|
||||||
|
case "02":
|
||||||
|
return "黄色"
|
||||||
|
case "03":
|
||||||
|
return "橙色"
|
||||||
|
case "04":
|
||||||
|
return "红色"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCodeIdColor(code string) string {
|
||||||
|
lastTwo := code[len(code)-2 : 0]
|
||||||
|
switch lastTwo {
|
||||||
|
case "00":
|
||||||
|
return "white"
|
||||||
|
case "01":
|
||||||
|
return "blue"
|
||||||
|
case "02":
|
||||||
|
return "yellow"
|
||||||
|
case "03":
|
||||||
|
return "orange"
|
||||||
|
case "04":
|
||||||
|
return "red"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
// GetAqi 空气污染
|
||||||
|
// https://docs.caiyunapp.com/docs/tables/aqi
|
||||||
|
// https://www.mee.gov.cn/ywgz/fgbz/bz/bzwb/jcffbz/201203/W020120410332725219541.pdf
|
||||||
|
func GetAqi(aqi float64) string {
|
||||||
|
if aqi <= 50 {
|
||||||
|
return "优"
|
||||||
|
} else if aqi <= 100 {
|
||||||
|
return "良"
|
||||||
|
} else if aqi <= 150 {
|
||||||
|
return "轻度污染"
|
||||||
|
} else if aqi <= 200 {
|
||||||
|
return "中度污染"
|
||||||
|
} else if aqi <= 300 {
|
||||||
|
return "重度污染"
|
||||||
|
} else if aqi > 300 {
|
||||||
|
return "严重污染"
|
||||||
|
}
|
||||||
|
return "缺数据"
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAqiColor 空气污染
|
||||||
|
// https://docs.caiyunapp.com/docs/tables/aqi
|
||||||
|
// https://www.mee.gov.cn/ywgz/fgbz/bz/bzwb/jcffbz/201203/W020120410332725219541.pdf
|
||||||
|
func GetAqiColor(aqi float64) string {
|
||||||
|
if aqi <= 50 {
|
||||||
|
return "green"
|
||||||
|
} else if aqi <= 100 {
|
||||||
|
return "yellow"
|
||||||
|
} else if aqi <= 150 {
|
||||||
|
return "orange"
|
||||||
|
} else if aqi <= 200 {
|
||||||
|
return "red"
|
||||||
|
} else if aqi <= 300 {
|
||||||
|
return "purple"
|
||||||
|
} else if aqi > 300 {
|
||||||
|
return "maroon"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
// GetCarWashingDesc 洗车指数 https://docs.caiyunapp.com/docs/tables/lifeindex
|
||||||
|
func GetCarWashingDesc(carWashing float64) string {
|
||||||
|
if carWashing <= 1 {
|
||||||
|
return "适宜"
|
||||||
|
} else if carWashing <= 2 {
|
||||||
|
return "较适宜"
|
||||||
|
} else if carWashing <= 3 {
|
||||||
|
return "较不适宜"
|
||||||
|
} else if carWashing <= 4 {
|
||||||
|
return "不适应"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dtapps/go-library/utils/golog"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClientConfig 实例配置
|
||||||
|
type ClientConfig struct {
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client 实例
|
||||||
|
type Client struct {
|
||||||
|
requestClient *gorequest.App // 请求服务
|
||||||
|
config struct {
|
||||||
|
token string
|
||||||
|
}
|
||||||
|
slog struct {
|
||||||
|
status bool // 状态
|
||||||
|
client *golog.ApiSLog // 日志服务
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient 创建实例化
|
||||||
|
func NewClient(config *ClientConfig) (*Client, error) {
|
||||||
|
|
||||||
|
c := &Client{}
|
||||||
|
|
||||||
|
c.config.token = config.Token
|
||||||
|
|
||||||
|
c.requestClient = gorequest.NewHttp()
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
// GetColdRiskDesc 感冒指数 https://docs.caiyunapp.com/docs/tables/lifeindex
|
||||||
|
func GetColdRiskDesc(coldRisk float64) string {
|
||||||
|
if coldRisk <= 1 {
|
||||||
|
return "少发"
|
||||||
|
} else if coldRisk <= 2 {
|
||||||
|
return "较易发"
|
||||||
|
} else if coldRisk <= 3 {
|
||||||
|
return "易发"
|
||||||
|
} else if coldRisk <= 4 {
|
||||||
|
return "极易发"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
// GetComfortDesc 舒适度指数 https://docs.caiyunapp.com/docs/tables/lifeindex
|
||||||
|
func GetComfortDesc(comfort float64) string {
|
||||||
|
if comfort <= 0 {
|
||||||
|
return "闷热"
|
||||||
|
} else if comfort <= 1 {
|
||||||
|
return "酷热"
|
||||||
|
} else if comfort <= 2 {
|
||||||
|
return "很热"
|
||||||
|
} else if comfort <= 3 {
|
||||||
|
return "热"
|
||||||
|
} else if comfort <= 4 {
|
||||||
|
return "温暖"
|
||||||
|
} else if comfort <= 5 {
|
||||||
|
return "舒适"
|
||||||
|
} else if comfort <= 6 {
|
||||||
|
return "凉爽"
|
||||||
|
} else if comfort <= 7 {
|
||||||
|
return "冷"
|
||||||
|
} else if comfort <= 8 {
|
||||||
|
return "很冷"
|
||||||
|
} else if comfort <= 9 {
|
||||||
|
return "寒冷"
|
||||||
|
} else if comfort <= 10 {
|
||||||
|
return "极冷"
|
||||||
|
} else if comfort <= 11 {
|
||||||
|
return "刺骨的冷"
|
||||||
|
} else if comfort <= 12 {
|
||||||
|
return "湿冷"
|
||||||
|
} else if comfort <= 13 {
|
||||||
|
return "干冷"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
import "github.com/dtapps/go-library/utils/golog"
|
||||||
|
|
||||||
|
// ConfigSLogClientFun 日志配置
|
||||||
|
func (c *Client) ConfigSLogClientFun(apiSLogFun golog.ApiSLogFun) {
|
||||||
|
apiSLog := apiSLogFun()
|
||||||
|
if apiSLog != nil {
|
||||||
|
c.slog.client = apiSLog
|
||||||
|
c.slog.status = true
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
const (
|
||||||
|
apiUrl = "https://api.caiyunapp.com/v2.6"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LogTable = "caiyunapp"
|
||||||
|
)
|
@ -0,0 +1,25 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
// GetDressingDesc 穿衣指数 https://docs.caiyunapp.com/docs/tables/lifeindex
|
||||||
|
func GetDressingDesc(dressing float64) string {
|
||||||
|
if dressing <= 0 {
|
||||||
|
return "极热"
|
||||||
|
} else if dressing <= 1 {
|
||||||
|
return "极热"
|
||||||
|
} else if dressing <= 2 {
|
||||||
|
return "很热"
|
||||||
|
} else if dressing <= 3 {
|
||||||
|
return "热"
|
||||||
|
} else if dressing <= 4 {
|
||||||
|
return "温暖"
|
||||||
|
} else if dressing <= 5 {
|
||||||
|
return "凉爽"
|
||||||
|
} else if dressing <= 6 {
|
||||||
|
return "冷"
|
||||||
|
} else if dressing <= 7 {
|
||||||
|
return "寒冷"
|
||||||
|
} else if dressing <= 8 {
|
||||||
|
return "极冷"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
func (c *Client) GetToken() string {
|
||||||
|
return c.config.token
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getApiUrl() string {
|
||||||
|
return apiUrl + "/" + c.config.token
|
||||||
|
}
|
@ -0,0 +1,134 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dtapps/go-library/utils/gojson"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HourlyResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
ApiVersion string `json:"api_version"`
|
||||||
|
ApiStatus string `json:"api_status"`
|
||||||
|
Lang string `json:"lang"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
Tzshift int `json:"tzshift"`
|
||||||
|
Timezone string `json:"timezone"`
|
||||||
|
ServerTime int `json:"server_time"`
|
||||||
|
Location []float64 `json:"location"`
|
||||||
|
Result struct {
|
||||||
|
Alert struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Content []struct {
|
||||||
|
Pubtimestamp int `json:"pubtimestamp"` // 发布时间,单位是 Unix 时间戳
|
||||||
|
AlertID string `json:"alertId"` // 预警 ID
|
||||||
|
Status string `json:"status"` // 预警信息的状态
|
||||||
|
Adcode string `json:"adcode"` // 区域代码
|
||||||
|
Location string `json:"location"` // 位置
|
||||||
|
Province string `json:"province"` // 省
|
||||||
|
City string `json:"city"` // 市
|
||||||
|
County string `json:"county"` // 县
|
||||||
|
Code string `json:"code"` // 预警代码
|
||||||
|
Source string `json:"source"` // 发布单位
|
||||||
|
Title string `json:"title"` // 标题
|
||||||
|
Description string `json:"description"` // 描述
|
||||||
|
RegionID string `json:"regionId"`
|
||||||
|
Latlon []float64 `json:"latlon"`
|
||||||
|
RequestStatus string `json:"request_status"`
|
||||||
|
} `json:"content"`
|
||||||
|
Adcodes []struct {
|
||||||
|
Adcode int `json:"adcode"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"adcodes"` // 行政区划层级信息
|
||||||
|
} `json:"alert"` // 预警数据
|
||||||
|
Hourly struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Precipitation []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"`
|
||||||
|
Probability float64 `json:"probability"`
|
||||||
|
} `json:"precipitation"`
|
||||||
|
Temperature []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"` // 地表 2 米气温
|
||||||
|
} `json:"temperature"`
|
||||||
|
ApparentTemperature []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"` // 体感温度
|
||||||
|
} `json:"apparent_temperature"`
|
||||||
|
Wind []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Speed float64 `json:"speed"`
|
||||||
|
Direction float64 `json:"direction"`
|
||||||
|
} `json:"wind"`
|
||||||
|
Humidity []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"` // 地表 2 米相对湿度(%)
|
||||||
|
} `json:"humidity"`
|
||||||
|
Cloudrate []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"`
|
||||||
|
} `json:"cloudrate"`
|
||||||
|
Skycon []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
} `json:"skycon"`
|
||||||
|
Pressure []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"` // 地面气压
|
||||||
|
} `json:"pressure"`
|
||||||
|
Visibility []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"`
|
||||||
|
} `json:"visibility"`
|
||||||
|
Dswrf []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"`
|
||||||
|
} `json:"dswrf"`
|
||||||
|
AirQuality struct {
|
||||||
|
Aqi []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value struct {
|
||||||
|
Chn float64 `json:"chn"`
|
||||||
|
Usa float64 `json:"usa"`
|
||||||
|
} `json:"value"`
|
||||||
|
} `json:"aqi"`
|
||||||
|
Pm25 []struct {
|
||||||
|
Datetime string `json:"datetime"`
|
||||||
|
Value float64 `json:"value"`
|
||||||
|
} `json:"pm25"`
|
||||||
|
} `json:"air_quality"`
|
||||||
|
} `json:"hourly"` // 小时级别预报
|
||||||
|
Primary float64 `json:"primary"`
|
||||||
|
ForecastKeypoint string `json:"forecast_keypoint"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HourlyResult struct {
|
||||||
|
Result HourlyResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Http gorequest.Response // 请求
|
||||||
|
}
|
||||||
|
|
||||||
|
func newHourlyResult(result HourlyResponse, body []byte, http gorequest.Response) *HourlyResult {
|
||||||
|
return &HourlyResult{Result: result, Body: body, Http: http}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hourly 小时级别预报
|
||||||
|
// https://docs.caiyunapp.com/docs/hourly
|
||||||
|
func (c *Client) Hourly(ctx context.Context, location string, notMustParams ...gorequest.Params) (*HourlyResult, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, c.getApiUrl()+fmt.Sprintf("/%s/hourly", location), params, http.MethodGet)
|
||||||
|
if err != nil {
|
||||||
|
return newHourlyResult(HourlyResponse{}, request.ResponseBody, request), err
|
||||||
|
}
|
||||||
|
// 定义
|
||||||
|
var response HourlyResponse
|
||||||
|
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||||
|
return newHourlyResult(response, request.ResponseBody, request), err
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dtapps/go-library/utils/gojson"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MinutelyResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
ApiVersion string `json:"api_version"`
|
||||||
|
ApiStatus string `json:"api_status"`
|
||||||
|
Lang string `json:"lang"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
Tzshift float64 `json:"tzshift"`
|
||||||
|
Timezone string `json:"timezone"`
|
||||||
|
ServerTime float64 `json:"server_time"`
|
||||||
|
Location []float64 `json:"location"`
|
||||||
|
Result struct {
|
||||||
|
Alert struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Content []struct {
|
||||||
|
Pubtimestamp int `json:"pubtimestamp"` // 发布时间,单位是 Unix 时间戳
|
||||||
|
AlertID string `json:"alertId"` // 预警 ID
|
||||||
|
Status string `json:"status"` // 预警信息的状态
|
||||||
|
Adcode string `json:"adcode"` // 区域代码
|
||||||
|
Location string `json:"location"` // 位置
|
||||||
|
Province string `json:"province"` // 省
|
||||||
|
City string `json:"city"` // 市
|
||||||
|
County string `json:"county"` // 县
|
||||||
|
Code string `json:"code"` // 预警代码
|
||||||
|
Source string `json:"source"` // 发布单位
|
||||||
|
Title string `json:"title"` // 标题
|
||||||
|
Description string `json:"description"` // 描述
|
||||||
|
RegionID string `json:"regionId"`
|
||||||
|
Latlon []float64 `json:"latlon"`
|
||||||
|
RequestStatus string `json:"request_status"`
|
||||||
|
} `json:"content"`
|
||||||
|
Adcodes []struct {
|
||||||
|
Adcode int `json:"adcode"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"adcodes"` // 行政区划层级信息
|
||||||
|
} `json:"alert"` // 预警数据
|
||||||
|
Minutely struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Datasource string `json:"datasource"`
|
||||||
|
Precipitation2H []float64 `json:"precipitation_2h"`
|
||||||
|
Precipitation []float64 `json:"precipitation"`
|
||||||
|
Probability []float64 `json:"probability"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
} `json:"minutely"` // 分钟级预报
|
||||||
|
Primary float64 `json:"primary"`
|
||||||
|
ForecastKeypoint string `json:"forecast_keypoint"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MinutelyResult struct {
|
||||||
|
Result MinutelyResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Http gorequest.Response // 请求
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMinutelyResult(result MinutelyResponse, body []byte, http gorequest.Response) *MinutelyResult {
|
||||||
|
return &MinutelyResult{Result: result, Body: body, Http: http}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minutely 分钟级预报
|
||||||
|
// https://docs.caiyunapp.com/docs/minutely
|
||||||
|
func (c *Client) Minutely(ctx context.Context, location string, notMustParams ...gorequest.Params) (*MinutelyResult, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, c.getApiUrl()+fmt.Sprintf("/%s/minutely", location), params, http.MethodGet)
|
||||||
|
if err != nil {
|
||||||
|
return newMinutelyResult(MinutelyResponse{}, request.ResponseBody, request), err
|
||||||
|
}
|
||||||
|
// 定义
|
||||||
|
var response MinutelyResponse
|
||||||
|
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||||
|
return newMinutelyResult(response, request.ResponseBody, request), err
|
||||||
|
}
|
@ -0,0 +1,127 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dtapps/go-library/utils/gojson"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RealtimeResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
ApiVersion string `json:"api_version"`
|
||||||
|
ApiStatus string `json:"api_status"`
|
||||||
|
Lang string `json:"lang"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
Tzshift float64 `json:"tzshift"`
|
||||||
|
Timezone string `json:"timezone"`
|
||||||
|
ServerTime float64 `json:"server_time"`
|
||||||
|
Location []float64 `json:"location"`
|
||||||
|
Result struct {
|
||||||
|
Alert struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Content []struct {
|
||||||
|
Pubtimestamp int `json:"pubtimestamp"` // 发布时间,单位是 Unix 时间戳
|
||||||
|
AlertID string `json:"alertId"` // 预警 ID
|
||||||
|
Status string `json:"status"` // 预警信息的状态
|
||||||
|
Adcode string `json:"adcode"` // 区域代码
|
||||||
|
Location string `json:"location"` // 位置
|
||||||
|
Province string `json:"province"` // 省
|
||||||
|
City string `json:"city"` // 市
|
||||||
|
County string `json:"county"` // 县
|
||||||
|
Code string `json:"code"` // 预警代码
|
||||||
|
Source string `json:"source"` // 发布单位
|
||||||
|
Title string `json:"title"` // 标题
|
||||||
|
Description string `json:"description"` // 描述
|
||||||
|
RegionID string `json:"regionId"`
|
||||||
|
Latlon []float64 `json:"latlon"`
|
||||||
|
RequestStatus string `json:"request_status"`
|
||||||
|
} `json:"content"`
|
||||||
|
Adcodes []struct {
|
||||||
|
Adcode int `json:"adcode"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"adcodes"` // 行政区划层级信息
|
||||||
|
} `json:"alert"` // 预警数据
|
||||||
|
Realtime struct {
|
||||||
|
Temperature float64 `json:"temperature"` // 地表2米气温
|
||||||
|
Humidity float64 `json:"humidity"` // 地表2米湿度相对湿度(%)
|
||||||
|
Cloudrate float64 `json:"cloudrate"` // 总云量(0.0-1.0)
|
||||||
|
Skycon string `json:"skycon"` // 天气现象
|
||||||
|
SkyconDesc string `json:"skycon_desc"` // 天气现象
|
||||||
|
Visibility float64 `json:"visibility"` // 地表水平能见度
|
||||||
|
Dswrf float64 `json:"dswrf"` // 向下短波辐射通量(W/M2)
|
||||||
|
Wind struct {
|
||||||
|
Speed float64 `json:"speed"` // 地表 10 米风速
|
||||||
|
Direction float64 `json:"direction"` // 地表 10 米风向
|
||||||
|
} `json:"wind"`
|
||||||
|
Pressure float64 `json:"pressure"` // 地面气压
|
||||||
|
ApparentTemperature float64 `json:"apparent_temperature"` // 体感温度
|
||||||
|
Precipitation struct {
|
||||||
|
Local struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Datasource string `json:"datasource"` // 本地降水带与本地的距离
|
||||||
|
Intensity float64 `json:"intensity"` // 本地降水处的降水强度
|
||||||
|
} `json:"local"` // 本地降水强度
|
||||||
|
Nearest struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Distance float64 `json:"distance"` // 最近降水带与本地的距离
|
||||||
|
Intensity float64 `json:"intensity"` // 最近降水处的降水强度
|
||||||
|
} `json:"nearest"` // 最近降水强度
|
||||||
|
} `json:"precipitation"`
|
||||||
|
AirQuality struct {
|
||||||
|
Pm25 float64 `json:"pm25"` // PM25 浓度(μg/m3)
|
||||||
|
Pm10 float64 `json:"pm10"` // PM10 浓度(μg/m3)
|
||||||
|
O3 float64 `json:"o3"` // 臭氧浓度(μg/m3)
|
||||||
|
So2 float64 `json:"so2"` // 二氧化氮浓度(μg/m3)
|
||||||
|
No2 float64 `json:"no2"` // 二氧化硫浓度(μg/m3)
|
||||||
|
Co float64 `json:"co"` // 一氧化碳浓度(mg/m3)
|
||||||
|
Aqi struct {
|
||||||
|
Chn float64 `json:"chn"` // 国标 AQI
|
||||||
|
Usa float64 `json:"usa"`
|
||||||
|
} `json:"aqi"`
|
||||||
|
Description struct {
|
||||||
|
Chn string `json:"chn"`
|
||||||
|
Usa string `json:"usa"`
|
||||||
|
} `json:"description"`
|
||||||
|
} `json:"air_quality"`
|
||||||
|
LifeIndex struct {
|
||||||
|
Ultraviolet struct {
|
||||||
|
Index float64 `json:"index"`
|
||||||
|
Desc string `json:"desc"` // 生活指数
|
||||||
|
} `json:"ultraviolet"`
|
||||||
|
Comfort struct {
|
||||||
|
Index float64 `json:"index"`
|
||||||
|
Desc string `json:"desc"` // 生活指数
|
||||||
|
} `json:"comfort"`
|
||||||
|
} `json:"life_index"`
|
||||||
|
} `json:"realtime"` // 实况
|
||||||
|
Primary float64 `json:"primary"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RealtimeResult struct {
|
||||||
|
Result RealtimeResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Http gorequest.Response // 请求
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRealtimeResult(result RealtimeResponse, body []byte, http gorequest.Response) *RealtimeResult {
|
||||||
|
return &RealtimeResult{Result: result, Body: body, Http: http}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Realtime 实况
|
||||||
|
// https://docs.caiyunapp.com/docs/realtime
|
||||||
|
func (c *Client) Realtime(ctx context.Context, location string, notMustParams ...gorequest.Params) (*RealtimeResult, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, c.getApiUrl()+fmt.Sprintf("/%s/realtime", location), params, http.MethodGet)
|
||||||
|
if err != nil {
|
||||||
|
return newRealtimeResult(RealtimeResponse{}, request.ResponseBody, request), err
|
||||||
|
}
|
||||||
|
// 定义
|
||||||
|
var response RealtimeResponse
|
||||||
|
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||||
|
return newRealtimeResult(response, request.ResponseBody, request), err
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
|
||||||
|
|
||||||
|
// 创建请求
|
||||||
|
client := c.requestClient
|
||||||
|
|
||||||
|
// 设置请求地址
|
||||||
|
client.SetUri(url)
|
||||||
|
|
||||||
|
// 设置方式
|
||||||
|
client.SetMethod(method)
|
||||||
|
|
||||||
|
// 设置格式
|
||||||
|
client.SetContentTypeJson()
|
||||||
|
|
||||||
|
// 设置参数
|
||||||
|
client.SetParams(params)
|
||||||
|
|
||||||
|
// 发起请求
|
||||||
|
request, err := client.Request(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return gorequest.Response{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录日志
|
||||||
|
if c.slog.status {
|
||||||
|
go c.slog.client.Middleware(ctx, request)
|
||||||
|
}
|
||||||
|
|
||||||
|
return request, err
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
// GetSkyCon https://docs.caiyunapp.com/docs/tables/skycon
|
||||||
|
func GetSkyCon(skycon string) string {
|
||||||
|
switch skycon {
|
||||||
|
case "CLEAR_DAY":
|
||||||
|
return "晴(白天)"
|
||||||
|
case "CLEAR_NIGHT":
|
||||||
|
return "晴(夜间)"
|
||||||
|
case "PARTLY_CLOUDY_DAY":
|
||||||
|
return "多云(白天)"
|
||||||
|
case "PARTLY_CLOUDY_NIGHT":
|
||||||
|
return "多云(夜间)"
|
||||||
|
case "CLOUDY":
|
||||||
|
return "阴"
|
||||||
|
case "LIGHT_HAZE":
|
||||||
|
return "轻度雾霾"
|
||||||
|
case "MODERATE_HAZE":
|
||||||
|
return "中度雾霾"
|
||||||
|
case "HEAVY_HAZE":
|
||||||
|
return "重度雾霾"
|
||||||
|
case "LIGHT_RAIN":
|
||||||
|
return "小雨"
|
||||||
|
case "MODERATE_RAIN":
|
||||||
|
return "中雨"
|
||||||
|
case "HEAVY_RAIN":
|
||||||
|
return "大雨"
|
||||||
|
case "STORM_RAIN":
|
||||||
|
return "暴雨"
|
||||||
|
case "FOG":
|
||||||
|
return "雾"
|
||||||
|
case "LIGHT_SNOW":
|
||||||
|
return "小雪"
|
||||||
|
case "MODERATE_SNOW":
|
||||||
|
return "中雪"
|
||||||
|
case "HEAVY_SNOW":
|
||||||
|
return "大雪"
|
||||||
|
case "STORM_SNOW":
|
||||||
|
return "暴雪"
|
||||||
|
case "DUST":
|
||||||
|
return "浮尘"
|
||||||
|
case "SAND":
|
||||||
|
return "沙尘"
|
||||||
|
case "WIND":
|
||||||
|
return "大风"
|
||||||
|
}
|
||||||
|
return skycon
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
// GetRealtimeUltravioletDesc 紫外线 https://docs.caiyunapp.com/docs/tables/lifeindex
|
||||||
|
func GetRealtimeUltravioletDesc(ultraviolet float64) string {
|
||||||
|
if ultraviolet <= 0 {
|
||||||
|
return "无"
|
||||||
|
} else if ultraviolet <= 1 {
|
||||||
|
return "很弱"
|
||||||
|
} else if ultraviolet <= 2 {
|
||||||
|
return "很弱"
|
||||||
|
} else if ultraviolet <= 3 {
|
||||||
|
return "弱"
|
||||||
|
} else if ultraviolet <= 4 {
|
||||||
|
return "弱"
|
||||||
|
} else if ultraviolet <= 5 {
|
||||||
|
return "中等"
|
||||||
|
} else if ultraviolet <= 6 {
|
||||||
|
return "中等"
|
||||||
|
} else if ultraviolet <= 7 {
|
||||||
|
return "强"
|
||||||
|
} else if ultraviolet <= 8 {
|
||||||
|
return "强"
|
||||||
|
} else if ultraviolet <= 9 {
|
||||||
|
return "强"
|
||||||
|
} else if ultraviolet <= 10 {
|
||||||
|
return "很强"
|
||||||
|
} else if ultraviolet <= 11 {
|
||||||
|
return "极强"
|
||||||
|
}
|
||||||
|
return "无"
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDailyUltravioletDesc 紫外线 https://docs.caiyunapp.com/docs/tables/lifeindex
|
||||||
|
func GetDailyUltravioletDesc(ultraviolet string) string {
|
||||||
|
if ultraviolet <= "1" {
|
||||||
|
return "最弱"
|
||||||
|
} else if ultraviolet <= "2" {
|
||||||
|
return "弱"
|
||||||
|
} else if ultraviolet <= "3" {
|
||||||
|
return "中等"
|
||||||
|
} else if ultraviolet <= "4" {
|
||||||
|
return "强"
|
||||||
|
} else if ultraviolet <= "5" {
|
||||||
|
return "很强"
|
||||||
|
}
|
||||||
|
return "无"
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
package caiyunapp
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// GetWindSpeed https://docs.caiyunapp.com/docs/tables/wind
|
||||||
|
func GetWindSpeed(speed float64) string {
|
||||||
|
if speed <= 0 {
|
||||||
|
return "0级"
|
||||||
|
} else if speed <= 5 {
|
||||||
|
return "1级"
|
||||||
|
} else if speed <= 11 {
|
||||||
|
return "2级"
|
||||||
|
} else if speed <= 19 {
|
||||||
|
return "3级"
|
||||||
|
} else if speed <= 28 {
|
||||||
|
return "4级"
|
||||||
|
} else if speed <= 38 {
|
||||||
|
return "5级"
|
||||||
|
} else if speed <= 49 {
|
||||||
|
return "6级"
|
||||||
|
} else if speed <= 61 {
|
||||||
|
return "7级"
|
||||||
|
} else if speed <= 74 {
|
||||||
|
return "8级"
|
||||||
|
} else if speed <= 88 {
|
||||||
|
return "9级"
|
||||||
|
} else if speed <= 102 {
|
||||||
|
return "10级"
|
||||||
|
} else if speed <= 117 {
|
||||||
|
return "11级"
|
||||||
|
} else if speed <= 133 {
|
||||||
|
return "12级"
|
||||||
|
} else if speed <= 149 {
|
||||||
|
return "13级"
|
||||||
|
} else if speed <= 166 {
|
||||||
|
return "14级"
|
||||||
|
} else if speed <= 183 {
|
||||||
|
return "15级"
|
||||||
|
} else if speed <= 201 {
|
||||||
|
return "16级"
|
||||||
|
} else if speed <= 220 {
|
||||||
|
return "17级"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%v", speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetWindSpeedDesc https://docs.caiyunapp.com/docs/tables/wind
|
||||||
|
func GetWindSpeedDesc(speed float64) string {
|
||||||
|
if speed <= 0 {
|
||||||
|
return "无风"
|
||||||
|
} else if speed <= 5 {
|
||||||
|
return "微风徐徐"
|
||||||
|
} else if speed <= 11 {
|
||||||
|
return "清风"
|
||||||
|
} else if speed <= 19 {
|
||||||
|
return "树叶摇摆"
|
||||||
|
} else if speed <= 28 {
|
||||||
|
return "树枝摇动"
|
||||||
|
} else if speed <= 38 {
|
||||||
|
return "风力强劲"
|
||||||
|
} else if speed <= 49 {
|
||||||
|
return "风力强劲"
|
||||||
|
} else if speed <= 61 {
|
||||||
|
return "风力超强"
|
||||||
|
} else if speed <= 74 {
|
||||||
|
return "狂风大作"
|
||||||
|
} else if speed <= 88 {
|
||||||
|
return "狂风呼啸"
|
||||||
|
} else if speed <= 102 {
|
||||||
|
return "暴风毁树"
|
||||||
|
} else if speed <= 117 {
|
||||||
|
return "暴风毁树"
|
||||||
|
} else if speed <= 133 {
|
||||||
|
return "飓风"
|
||||||
|
} else if speed <= 149 {
|
||||||
|
return "台风"
|
||||||
|
} else if speed <= 166 {
|
||||||
|
return "强台风"
|
||||||
|
} else if speed <= 183 {
|
||||||
|
return "强台风"
|
||||||
|
} else if speed <= 201 {
|
||||||
|
return "超强台风"
|
||||||
|
} else if speed <= 220 {
|
||||||
|
return "超强台风"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%v", speed)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetWindDirectionDesc https://docs.caiyunapp.com/docs/tables/wind
|
||||||
|
func GetWindDirectionDesc(direction float64) string {
|
||||||
|
if direction <= 11.26 {
|
||||||
|
return "北"
|
||||||
|
} else if direction <= 33.75 {
|
||||||
|
return "北东北"
|
||||||
|
} else if direction <= 56.25 {
|
||||||
|
return "东北"
|
||||||
|
} else if direction <= 78.75 {
|
||||||
|
return "东东北"
|
||||||
|
} else if direction <= 101.25 {
|
||||||
|
return "东"
|
||||||
|
} else if direction <= 123.75 {
|
||||||
|
return "东东南"
|
||||||
|
} else if direction <= 146.25 {
|
||||||
|
return "东南"
|
||||||
|
} else if direction <= 168.75 {
|
||||||
|
return "南东南"
|
||||||
|
} else if direction <= 191.25 {
|
||||||
|
return "南"
|
||||||
|
} else if direction <= 213.75 {
|
||||||
|
return "南西南"
|
||||||
|
} else if direction <= 236.25 {
|
||||||
|
return "西南"
|
||||||
|
} else if direction <= 258.75 {
|
||||||
|
return "西西南"
|
||||||
|
} else if direction <= 281.25 {
|
||||||
|
return "西"
|
||||||
|
} else if direction <= 303.75 {
|
||||||
|
return "西西北"
|
||||||
|
} else if direction <= 326.25 {
|
||||||
|
return "西北"
|
||||||
|
} else if direction <= 348.75 {
|
||||||
|
return "北西北"
|
||||||
|
}
|
||||||
|
return "北"
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package dingdanxia
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) Get(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodGet)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Post(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package dingtalk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) Get(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodGet)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Post(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package eastiot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) Get(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodGet)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Post(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package ejiaofei
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) Get(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodGet)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Post(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package feishu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/dtapps/go-library/utils/gorequest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) Post(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := gorequest.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, apiUrl+_method, params)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Client) Post(ctx context.Context, _method string, notMustParams ...Params) ([]byte, error) {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType(_method, notMustParams...)
|
||||||
|
// 请求
|
||||||
|
request, err := c.request(ctx, params)
|
||||||
|
// 定义
|
||||||
|
return request.ResponseBody, err
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue