Search in sources :

Example 1 with GaodeLocation

use of com.paascloud.provider.model.dto.gaode.GaodeLocation in project paascloud-master by paascloud.

the class OpcRpcServiceImpl method getLocationById.

@Override
public String getLocationById(String addressId) {
    try {
        Wrapper<GaodeLocation> wrapper = opcGaodeFeignApi.getLocationByIpAddr(addressId);
        if (wrapper == null) {
            throw new MdcBizException(ErrorCodeEnum.GL99990002);
        }
        if (wrapper.error()) {
            throw new MdcBizException(ErrorCodeEnum.MDC10021002);
        }
        GaodeLocation result = wrapper.getResult();
        assert result != null;
        return result.getProvince().contains("市") ? result.getCity() : result.getProvince() + GlobalConstant.Symbol.SHORT_LINE + result.getCity();
    } catch (Exception e) {
        log.error("getLocationById={}", e.getMessage(), e);
    }
    return null;
}
Also used : MdcBizException(com.paascloud.provider.exceptions.MdcBizException) GaodeLocation(com.paascloud.provider.model.dto.gaode.GaodeLocation) MdcBizException(com.paascloud.provider.exceptions.MdcBizException)

Example 2 with GaodeLocation

use of com.paascloud.provider.model.dto.gaode.GaodeLocation in project paascloud-master by paascloud.

the class GaoDeUtil method getCityByIpAddr.

/**
 * Gets city by ip addr.
 *
 * @param ipAddr the ip addr
 *
 * @return the city by ip addr
 */
public static GaodeLocation getCityByIpAddr(String ipAddr) {
    // http://lbs.amap.com/api/webservice/guide/api/ipconfig/
    log.info("getCityByIpAddr - 根据IP定位. ipAddr={}", ipAddr);
    GaodeLocation location = null;
    String urlAddressIp = "http://restapi.amap.com/v3/ip?key=f8bdce6f882a98635bb0b7b897331327&ip=%s";
    String url = String.format(urlAddressIp, ipAddr);
    try {
        String str = HttpClientUtil.get(HttpConfig.custom().url(url));
        location = new ObjectMapper().readValue(str, GaodeLocation.class);
    } catch (Exception e) {
        log.error("getCityByIpAddr={}", e.getMessage(), e);
    }
    log.info("getCityByIpAddr - 根据IP定位. ipAddr={}, location={}", ipAddr, location);
    return location;
}
Also used : GaodeLocation(com.paascloud.provider.model.dto.gaode.GaodeLocation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

GaodeLocation (com.paascloud.provider.model.dto.gaode.GaodeLocation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MdcBizException (com.paascloud.provider.exceptions.MdcBizException)1