// 这个应该是你想要的
private static String sign(HashMap<String, Object> parameters) throws Exception {
List<String> keys = new ArrayList<String>(parameters.keySet());
Collections.sort(keys, new Comparator<String>() {
@
Override public int compare(String s1, String s2) {
return s1.compareTo(s2);
}
});
StringBuilder signature = new StringBuilder("");
for (String key : keys) {
if (key.equalsIgnoreCase("sign")) {
continue;
}
signature.append(key);
Object value = parameters.get(key);
if (value instanceof HashMap) {
signature.append(sign((HashMap<String, Object>) value));
continue;
}
if (((String) value).equals("")) {
continue;
}
signature.append((String) value);
}
return signature.toString();
}