public static String getSign(Map<String, String> params) { Map<String, String> sortMap = new TreeMap<String, String>(); sortMap.putAll(params); // 以k1=v1&k2=v2...方式拼接参数 StringBuilder builder = new StringBuilder(); for (Map.Entry<String, String> s : sortMap.entrySet()) { String k = s.getKey(); String v = s.getValue(); if (StringUtils.isBlank(v)) {// 过滤空值 continue; } builder.append(k).append("=").append(v).append("&"); } if (!sortMap.isEmpty()) { builder.deleteCharAt(builder.length() - 1); } return builder.toString(); } public static void main(String[] args) { Map<String,String> paraMap = new HashMap<String,String>(); paraMap.put("total_fee","200"); paraMap.put("appid", "wxd678efh567hg6787"); paraMap.put("body", "测试"); paraMap.put("out_trade_no","20150806125346"); System.out.println(getSign(paraMap)); }