package com.fs.hisapi.util;

import com.fs.common.utils.sign.Md5Utils;
import com.fs.hisapi.config.HisApiConfig;

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class SignUtil {


    static String token= HisApiConfig.token;

    public static String getSign(Map map){
        return createSignOutChar(map, token).toUpperCase();
    }

    public static String createSignOutChar(Map<String, String> params, String paternerKey) {
        params.remove("sign");
        String stringA = packageSignWithOutChar(params);
        String stringSignTemp = stringA + paternerKey;
        return Md5Utils.hash(stringSignTemp);
    }

    public static String packageSignWithOutChar(Map<String, String> params) {
        TreeMap<String, String> sortedParams = new TreeMap(params);
        StringBuilder sb = new StringBuilder();
        Iterator var5 = sortedParams.entrySet().iterator();
        while (var5.hasNext()) {
            Map.Entry<String, String> param = (Map.Entry) var5.next();
            String value = (String) param.getValue();
            sb.append((String) param.getKey()).append(value);
        }
        return sb.toString();
    }


}
