@Test public void testSign() { String appKey = "XXXXXXXX"; String secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("city", "上海"); paramMap.put("latitude", "31.21524"); paramMap.put("longitude", "121.420033"); paramMap.put("category", "美食"); paramMap.put("region", "长宁区"); paramMap.put("limit", "20"); paramMap.put("radius", "2000"); paramMap.put("offset_type", "0"); paramMap.put("has_coupon", "1"); paramMap.put("has_deal", "1"); paramMap.put("keyword", "泰国菜"); paramMap.put("sort", "7"); paramMap.put("format", "json"); String sign = DemoApiTool.sign(appKey, secret, paramMap); LOGGER.info(sign); Assert.assertNotNull(sign); }
public static String sign(String appKey, String secret, Map<String, String> paramMap) { String[] keyArray = paramMap.keySet().toArray(new String[0]); Arrays.sort(keyArray); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(appKey); for (String key : keyArray) { stringBuilder.append(key).append(paramMap.get(key)); } stringBuilder.append(secret); String codes = stringBuilder.toString(); String sign = org.apache.commons.codec.digest.DigestUtils.shaHex(codes).toUpperCase(); return sign; }
DemoApiTool { public static String sign(String appKey, String secret, Map<String, String> paramMap) { String[] keyArray = paramMap.keySet().toArray(new String[0]); Arrays.sort(keyArray); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(appKey); for (String key : keyArray) { stringBuilder.append(key).append(paramMap.get(key)); } stringBuilder.append(secret); String codes = stringBuilder.toString(); String sign = org.apache.commons.codec.digest.DigestUtils.shaHex(codes).toUpperCase(); return sign; } }
DemoApiTool { public static String sign(String appKey, String secret, Map<String, String> paramMap) { String[] keyArray = paramMap.keySet().toArray(new String[0]); Arrays.sort(keyArray); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(appKey); for (String key : keyArray) { stringBuilder.append(key).append(paramMap.get(key)); } stringBuilder.append(secret); String codes = stringBuilder.toString(); String sign = org.apache.commons.codec.digest.DigestUtils.shaHex(codes).toUpperCase(); return sign; }  }
DemoApiTool { public static String sign(String appKey, String secret, Map<String, String> paramMap) { String[] keyArray = paramMap.keySet().toArray(new String[0]); Arrays.sort(keyArray); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(appKey); for (String key : keyArray) { stringBuilder.append(key).append(paramMap.get(key)); } stringBuilder.append(secret); String codes = stringBuilder.toString(); String sign = org.apache.commons.codec.digest.DigestUtils.shaHex(codes).toUpperCase(); return sign; }  static String sign(String appKey, String secret, Map<String, String> paramMap); static String getQueryString(String appKey, String secret, Map<String, String> paramMap); static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap); static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap); }
DemoApiTool { public static String sign(String appKey, String secret, Map<String, String> paramMap) { String[] keyArray = paramMap.keySet().toArray(new String[0]); Arrays.sort(keyArray); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(appKey); for (String key : keyArray) { stringBuilder.append(key).append(paramMap.get(key)); } stringBuilder.append(secret); String codes = stringBuilder.toString(); String sign = org.apache.commons.codec.digest.DigestUtils.shaHex(codes).toUpperCase(); return sign; }  static String sign(String appKey, String secret, Map<String, String> paramMap); static String getQueryString(String appKey, String secret, Map<String, String> paramMap); static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap); static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap);  }