All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.service.MapServiceImpl.ftl Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package ${packageName}.service.party.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import ${packageName}.common.constants.Constants;
import ${packageName}.common.properties.MapTencentProperties;
import ${packageName}.common.utils.HttpsRequestUtils;
import ${packageName}.service.party.service.MapService;
import org.yes.tools.core.exception.YesBaseException;

/**
 * @author Co.
 * @name MapServiceImpl
 * @date 2023/2/24 16:05
 */
@Service
public class MapServiceImpl implements MapService {

    @Override
    public Object suggestion(String keyword) {
        String md5Url = "/ws/place/v1/suggestion/?key=%s&keyword=%s%s";
        String format = String.format(md5Url, MapTencentProperties.KEY, keyword, MapTencentProperties.SECRET_KEY);
        String md5 = DigestUtils.md5Hex(format);

        JSONObject sessionData = HttpsRequestUtils.httpsRequest(String.format(Constants.TENCENT_SUGGESTION_URL, MapTencentProperties.KEY, keyword, md5), "GET", null);
        if (!sessionData.get("status").toString().equals("0")) {
            throw new YesBaseException("搜索失败");
        }
        Object data = sessionData.get("data");
        return data;
    }

    @Override
    public Object geocoderAddress(String address) {
        String md5Url = "/ws/geocoder/v1/?address=%s&key=%s%s";
        String format = String.format(md5Url, address, MapTencentProperties.KEY, MapTencentProperties.SECRET_KEY);
        String md5 = DigestUtils.md5Hex(format);

        JSONObject sessionData = HttpsRequestUtils.httpsRequest(String.format(Constants.TENCENT_GEOCODER_ADDRESS_URL, MapTencentProperties.KEY, address, md5), "GET", null);
        if (!sessionData.get("status").toString().equals("0")) {
            throw new YesBaseException("搜索失败");
        }
        Object data = sessionData.get("result");
        return data;
    }

    @Override
    public Object geocoderLocation(String location) {
        String md5Url = "/ws/geocoder/v1/?key=%s&location=%s%s";
        String format = String.format(md5Url, MapTencentProperties.KEY, location, MapTencentProperties.SECRET_KEY);
        String md5 = DigestUtils.md5Hex(format);

        JSONObject sessionData = HttpsRequestUtils.httpsRequest(String.format(Constants.TENCENT_GEOCODER_LOCATION_URL, MapTencentProperties.KEY, location, md5), "GET", null);

        if (!sessionData.get("status").toString().equals("0")) {
            throw new YesBaseException("搜索失败");
        }
        Object data = sessionData.get("result");
        return data;
    }

    @Override
    public Object locationIp() {
        String md5Url = "/ws/location/v1/ip/?key=%s%s";
        String format = String.format(md5Url, MapTencentProperties.KEY, MapTencentProperties.SECRET_KEY);
        String md5 = DigestUtils.md5Hex(format);
        JSONObject sessionData = HttpsRequestUtils.httpsRequest(String.format(Constants.TENCENT_LOCATION_IP_URL, MapTencentProperties.KEY, md5), "GET", null);
        if (!sessionData.get("status").toString().equals("0")) {
            throw new YesBaseException("搜索失败");
        }
        Object data = sessionData.get("result");
        return data;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy