字段名的 ascii 码从小到 大排序后使用 QueryString 的格式(即 key1=value1&key2=value2…)拼接而成

/**
 * 生成签名,根据字段名ascii码,从小大到大
 * @param info
 * @return
 */
public static String putPairsSequenceAndTogether(Map info) {
    List> infoIds = new ArrayList>(info.entrySet());
    Collections.sort(infoIds, new Comparator>() {
        @Override
        public int compare(Map.Entry arg0, Map.Entry arg1) {
            return (arg0.getKey()).compareTo(arg1.getKey());
        }
    });
    String ret = "";
    for (Map.Entry entry : infoIds) {
        ret += entry.getKey();
        ret += "=";
        ret += entry.getValue();
        ret += "&";
    }
    ret = ret.substring(0, ret.length() - 1);
    return ret;
}

你可能感兴趣的:(java基础)