package com.ibeetl.admin.flow.utils;

import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.*;

public class SignatureUtil {


    public static String signatureStr(Map<String,Object> maps,String key){
        String signastr="";
        Collection<String> keyset= maps.keySet();
        List list=new ArrayList<String>(keyset);
        Collections.sort(list);
        for(int i=0;i<list.size();i++){
            signastr+=list.get(i)+"="+maps.get(list.get(i));
//            signastr+=maps.get(list.get(i));
        }
        System.out.println("-------"+signastr);
        return DigestUtils.sha1Hex(signastr+key);
    }

    public static Map<String,Object> upMaps(Map<String,Object> maps){
        Map<String,Object> outmap=new HashMap<>();
        for(String ob:maps.keySet()){
            outmap.put(ob,(JSON.parseArray(maps.get(ob).toString()).toArray(new String[0]))[0]);
        }
        return outmap;
    }

    public static void main(String[] args) {
        Map<String,Object> sigMap=new HashMap<>();
        sigMap.put("timestamp","timestamp");
        sigMap.put("nonce","nonce");
        sigMap.put("token","token");
        System.out.println(signatureStr(sigMap,""));
    }
}
