package object
import (
"encoding/json"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)
type GetAddressDivisionCodeResponse struct {
RequestId string `json:"RequestId"`
Data string `json:"Data"`
}
type GetAddressDivisionCodeResponseData struct {
Status string `json:"status"`
DivisionInfo DivisionInfo `json:"division_info"`
Timesed TimeUsed `json:"time_used"`
}
type DivisionInfo struct {
DivCode string `json:"divcode"`
DivisionName string `json:"division_name"`
}
type TimeUsed struct {
DivisionInfo TimeUsedRt `json:"division_info"`
Start float64 `json:"start"`
}
type TimeUsedRt struct {
DivisionInfo float64 `json:"division_info"`
Complete float64 `json:"Complete"`
Structure float64 `json:"structure"`
}
var aliyunClient *sdk.Client
func GetAddressDivisionCode(address string) (*GetAddressDivisionCodeResponseData, error) {
request := requests.NewCommonRequest()
request.Method = "POST"
request.Product = "address-purification"
request.Domain = "address-purification.cn-hangzhou.aliyuncs.com"
request.Version = "2019-11-18"
request.ApiName = "GetAddressDivisionCode"
request.QueryParams["AppKey"] = "Axbsaftcmm8r"
request.QueryParams["ServiceCode"] = "addrp"
request.QueryParams["Text"] = address
request.TransToAcsRequest()
if response, err := aliyunClient.ProcessCommonRequest(request); err != nil {
return nil, err
} else {
getAddressDivisionCodeResponse := &GetAddressDivisionCodeResponse{}
if err := json.Unmarshal(response.GetHttpContentBytes(), &getAddressDivisionCodeResponse); err != nil {
return nil, err
}
responseData := &GetAddressDivisionCodeResponseData{}
if err := json.Unmarshal([]byte(getAddressDivisionCodeResponse.Data), &responseData); err != nil {
return nil, err
}
return responseData, nil
}
}
func init() {
if client, err := sdk.NewClientWithAccessKey("cn-hangzhou", config.GetConfig().Aliyun.AccessKeyId, config.GetConfig().Aliyun.AccessKeySecret); err != nil {
util.Logger.Error("aliyunClient", util.Any("error", err))
} else {
aliyunClient = client
}
}
网友评论