package com.usky.cdi.service.util;

import cn.hutool.crypto.SecureUtil;
import com.usky.common.core.utils.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

public class SignUtil {

    /**
     * 使用 Map按key进行排序
     *
     * @param map
     * @return
     */
    public static Map<String, String> sortMapByKey(Map<String, String> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }
        //升序排序
        Map<String, String> sortMap = new TreeMap<>(String::compareTo);
        sortMap.putAll(map);
        return sortMap;
    }

    public static String sign(String body, Map<String, String[]> params, Map<String, String> requestPathMap,
                              String secretKey, String timestamp, String appKey) {
        String a = String.join("#", secretKey, timestamp, appKey);
        return SecureUtil.md5(a);
    }
}
