package com.cpop.api.tencent.location.handler;

import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSONObject;
import com.cpop.api.tencent.location.core.constant.TencentApiUrl;
import com.cpop.common.utils.http.HttpUtils;
import com.cpop.core.base.exception.UtilException;
import com.cpop.core.utils.SpringUtils;
import okhttp3.Response;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

/**
 * 腾讯位置服务工具类
 * @author DB
 * @version 1.0.0
 * @since 2024-02-21 9:26
 */
@Component
public class TencentLocationHandler {

    /**
     * 根据经纬度获取位置信息
     * @author DB
     * @since 2024/2/21
     * @param longitude 经度
     * @param latitude 纬度
     * @param key 密钥
     */
    public JSONObject geocoder(String longitude, String latitude, String key) {
        String url = TencentApiUrl.GEOCODER + "?key=" + key + "&location=" + latitude + "," + longitude;
        RestTemplate restTemplate = SpringUtils.getBean(RestTemplate.class);
        return restTemplate.getForObject(TencentApiUrl.BASE_URL + url, JSONObject.class);
    }
}
