一个不错的签名算法

/**
     * 传入的是map
     * @param map
     * @return
     */
    public static String getSignbyMap(Map<String,Object> map){
        ArrayList<String> list = new ArrayList<String>();
        map.put("sign", "");//此处是去除不签名的字符串
        for(Map.Entry<String,Object> entry:map.entrySet()){
            if(entry.getValue()!=""){
                list.add(entry.getKey() + "=" + entry.getValue() + "&");
            }
        }
        int size = list.size();
        String [] arrayToSort = list.toArray(new String[size]);
        Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < size; i ++) {
            sb.append(arrayToSort[i]);
        }
        String result = sb.toString();
        result += "key=" +"123456";
        //Util.log("Sign Before MD5:" + result);
        result = MD5Wx.MD5Encode(result).toUpperCase();
        //Util.log("Sign Result:" + result);
        return result;
    }

你可能感兴趣的:(一个不错的签名算法)