aa
This commit is contained in:
@@ -92,6 +92,36 @@ func (a *API) AccessAPI(url string, params map[string]interface{}) (retVal map[s
|
|||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) AccessAPI2(url string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
|
// 签名
|
||||||
|
auth, datetime, _ := calcAuthorization(source, a.secretID, a.secretKey)
|
||||||
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
|
func() *http.Request {
|
||||||
|
request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, "", params), nil)
|
||||||
|
request.Header.Set("X-Source", source)
|
||||||
|
request.Header.Set("X-Date", datetime)
|
||||||
|
request.Header.Set("Authorization", auth)
|
||||||
|
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
return request
|
||||||
|
},
|
||||||
|
a.config,
|
||||||
|
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||||
|
if jsonResult1 == nil {
|
||||||
|
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
if !jsonResult1["Result"].(map[string]interface{})["success"].(bool) {
|
||||||
|
errLevel = platformapi.ErrLevelGeneralFail
|
||||||
|
err = utils.NewErrorCode(jsonResult1["Result"].(map[string]interface{})["errMsg"].(string), "false")
|
||||||
|
baseapi.SugarLogger.Debugf("txcloud AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||||
|
}
|
||||||
|
retVal = jsonResult1
|
||||||
|
}
|
||||||
|
return errLevel, err
|
||||||
|
})
|
||||||
|
return retVal, err
|
||||||
|
}
|
||||||
|
|
||||||
type GetWaybillDetailInfoResult struct {
|
type GetWaybillDetailInfoResult struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
No string `json:"no"`
|
No string `json:"no"`
|
||||||
@@ -126,16 +156,32 @@ func (a *API) GetWaybillDetailInfo(vendorWaybillID, comType string) (getWaybillD
|
|||||||
return getWaybillDetailInfoResult, err
|
return getWaybillDetailInfoResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) Address(vendorWaybillID, comType string) (getWaybillDetailInfoResult *GetWaybillDetailInfoResult, err error) {
|
type AddressDistinguishResult struct {
|
||||||
|
RequestID string `json:"RequestId"`
|
||||||
|
Result struct {
|
||||||
|
Data struct {
|
||||||
|
AddressDetail string `json:"addressDetail"`
|
||||||
|
City string `json:"city"`
|
||||||
|
CityCode int `json:"cityCode"`
|
||||||
|
District string `json:"district"`
|
||||||
|
DistrictCode int `json:"districtCode"`
|
||||||
|
DivisionZip string `json:"divisionZip"`
|
||||||
|
MobileNO string `json:"mobileNO"`
|
||||||
|
PersonalName string `json:"personalName"`
|
||||||
|
Province string `json:"province"`
|
||||||
|
ProvinceCode int `json:"provinceCode"`
|
||||||
|
} `json:"data"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
} `json:"Result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) AddressDistinguish(address string) (addressDistinguishResult *AddressDistinguishResult, err error) {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"num": vendorWaybillID,
|
"address": address,
|
||||||
}
|
}
|
||||||
if comType != "" {
|
result, err := a.AccessAPI2("https://service-7daeqy5n-1301652365.bj.apigw.tencentcs.com/release/address_parse", params)
|
||||||
params["com"] = comType
|
|
||||||
}
|
|
||||||
result, err := a.AccessAPI("https://service-5hof02so-1300683954.gz.apigw.tencentcs.com/release/kuaidi", params)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
utils.Map2StructByJson(result, &getWaybillDetailInfoResult, false)
|
utils.Map2StructByJson(result, &addressDistinguishResult, false)
|
||||||
}
|
}
|
||||||
return getWaybillDetailInfoResult, err
|
return addressDistinguishResult, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,3 +27,11 @@ func TestGetWaybillDetailInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log(utils.Format4Output(result, false))
|
t.Log(utils.Format4Output(result, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddressDistinguish(t *testing.T) {
|
||||||
|
result, err := api.AddressDistinguish("班")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user