/*
package com.sikey.wa04.business.infrastructure.adapter.amap;

import com.sikey.wa04.business.infrastructure.dto.response.baidu.BaiduLocationResponse;
import com.sikey.wa04.common.utils.BaiduLocationApiClient;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

*/
/**
 * @Author: qin
 * @Date: 2025/3/21
 * @Description: 百度地图
 *//*

@Slf4j
@Component
public class AMapBaiduRequestService {

    */
/**
     * 正常
     *//*

    private static final String AM_AP_BAIDU_SUCCESSFUL_STATUS = "0";

    @Value("${amapBaidu.key}")
    private String amapBaiduKey;

    @Value("${amapBaidu.url}")
    private String amapBaiduUrl;

    @Value("${amapBaidu.trace}")
    private boolean amapBaiduTrace;

    @Value("${amapBaidu.sk}")
    private String sk;

    private final OkHttpClient client = new OkHttpClient();

    */
/**
     * 百度定位
     *
     * @param map 百度定位
     * @return
     *//*

    public BaiduLocationResponse locate(Map map) {
        // baiduLocationRequest.setKey(amapBaiduKey);
        // baiduLocationRequest.setTrace(false);


        try {
            BaiduLocationApiClient locationApiClient = new BaiduLocationApiClient();
            locationApiClient.locate(map);
        } catch (Exception e) {
            e.getStackTrace();
        }
        return null;

        */
/*Map<String, Object> stringObjectMap = BaiduUtil.convertToSortedMap(baiduLocationRequest);// JSONUtil.toJsonStr(baiduLocationRequest)
        String wholeStr = new String("/locapi/v2?" + stringObjectMap + sk);
        // 对上面wholeStr再作utf8编码
        String tempStr = URLEncoder.encode(wholeStr, StandardCharsets.UTF_8);
        String sn = BaiduUtil.SNForMD5(tempStr);*//*


        // 构建请求体
        // RequestBody body = RequestBody.create(wholeStr, MediaType.parse("application/json"));
        // 构建请求
        */
/*Request request = new Request.Builder().url(amapBaiduUrl).post(body).build();
        try (Response response = client.newCall(request).execute()) {
            if (Objects.isNull(response.body())) {
                log.warn("[百度定位]百度定位失败，未获取结果");
                throw new BusinessException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "百度定位失败，未获取结果");
            }

            String errcode = String.valueOf(JSONUtil.parseObj(response.body().string()).get("errcode"));
            String msg = String.valueOf(JSONUtil.parseObj(response.body().string()).get("msg"));
            if (!response.isSuccessful() || response.code() != HttpStatus.OK.value() || !errcode.equals(AM_AP_BAIDU_SUCCESSFUL_STATUS)) {
                log.warn("[百度定位]百度定位失败：{}", msg);
                throw new BusinessException(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
            }
            return JSONUtil.toBean(JSONUtil.toJsonStr(response.body()), BaiduLocationResponse.class);
        } catch (Exception e) {
            throw new BusinessException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
        }*//*

    }

    */
/*private void test(String[] args) throws Exception {
        // 计算sn跟参数对出现顺序有关，get请求请使用LinkedHashMap保存<key,value>，该方法根据key的插入顺序排序；post请使用TreeMap保存<key,value>，该方法会自动将key按照字母a-z顺序排序。所以get请求可自定义参数顺序（sn参数必须在最后）发送请求，但是post请求必须按照字母a-z顺序填充body（sn参数必须在最后）。以get请求为例：http://api.map.baidu.com/geocoder/v2/?address=百度大厦&output=json&ak=yourak，paramsMap中先放入address，再放output，然后放ak，放入顺序必须跟get请求中对应参数的出现顺序保持一致。

        Map paramsMap = new LinkedHashMap<String, String>();
        paramsMap.put("address", "百度大厦");
        paramsMap.put("output", "json");
        paramsMap.put("ak", "yourak");

        // 调用下面的toQueryString方法，对LinkedHashMap内所有value作utf8编码，拼接返回结果address=%E7%99%BE%E5%BA%A6%E5%A4%A7%E5%8E%A6&output=json&ak=yourak
        String paramsStr = BaiduUtil.toQueryString(paramsMap);

        // 对paramsStr前面拼接上/geocoder/v2/?，后面直接拼接yoursk得到/geocoder/v2/?address=%E7%99%BE%E5%BA%A6%E5%A4%A7%E5%8E%A6&output=json&ak=yourakyoursk
        String wholeStr = new String("/locapi/v2/?" + paramsStr + "yoursk");

        // 对上面wholeStr再作utf8编码
        String tempStr = URLEncoder.encode(wholeStr, "UTF-8");

        // 调用下面的MD5方法得到最后的sn签名7de5a22212ffaa9e326444c75a58f9a0
        System.out.println(BaiduUtil.SNForMD5(tempStr));
    }*//*


}
*/
