package com.thinkgem.jeesite.modules.pay.huanqiuhuiju.utils;

import com.thinkgem.jeesite.modules.pay.juhezhong.utils.MD5Utils;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

public class SignUtils {
    public static String createSign(SortedMap<Object,Object> parameters, String APIKEY) throws Exception {
        StringBuffer buffer = new StringBuffer();
        Set set = parameters.entrySet();
        Iterator iterator = set.iterator();
        while(iterator.hasNext()){
            Map.Entry entry = (Map.Entry) iterator.next();
            String key = (String)entry.getKey();
            Object value = (String)entry.getValue();
            if(null != value && !"".equals(value) && !"sign".equals(key) && !"key".equals(key)){
                buffer.append(key);
                buffer.append("=");
                buffer.append(value);
            }
        }
        buffer.append(APIKEY);
        String sign =MD5Utils.md5(buffer.toString()).toUpperCase();
        System.out.println("签名参数："+sign);
        return sign;
    }
}
