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

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

import java.util.*;

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+"="+value+"&");
            }
        }
        buffer.append("key="+APIKEY);
        String sign =MD5Utils.md5(buffer.toString()).toUpperCase();
        System.out.println("签名参数："+sign);
        return sign;
    }
}
