test_class.declarator: LOGGER = LoggerFactory.getLogger(DemoApiToolTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(DemoApiToolTest.class);
test_class.type: Logger
test_class.var_name: LOGGER
test_class.file: samples/dianping-java-samples/src/test/java/com/dianping/open/samples/DemoApiToolTest.java
test_class.identifier: DemoApiToolTest
test_case.body: @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);
      }
test_case.class_method_signature: DemoApiToolTest.testSign()
test_case.full_signature: @Test public void testSign()
test_case.identifier: testSign
test_case.invocations: put put put put put put put put put put put put put sign info assertNotNull
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSign()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(DemoApiTool.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(DemoApiTool.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.file: samples/dianping-java-samples/src/main/java/com/dianping/open/samples/DemoApiTool.java
focal_class.identifier: DemoApiTool
focal_class.class_method_signature: DemoApiTool.sign(String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String sign(String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: sign
focal_class.modifiers: public static
focal_class.parameters: (String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String sign(String appKey, String secret, Map<String, String> paramMap)
focal_class.class_method_signature: DemoApiTool.getQueryString(String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String getQueryString(String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: getQueryString
focal_class.modifiers: public static
focal_class.parameters: (String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String getQueryString(String appKey, String secret, Map<String, String> paramMap)
focal_class.class_method_signature: DemoApiTool.requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: requestApi
focal_class.modifiers: public static
focal_class.parameters: (String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.class_method_signature: DemoApiTool.requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.full_signature: public static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.identifier: requestPostApi
focal_class.modifiers: public static
focal_class.parameters: (String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_class.return: String
focal_class.signature: String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap)
focal_method.body: 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();
  
          // SHA-1编码， 这里使用的是Apache
          // codec，即可获得签名(shaHex()会首先将中文转换为UTF8编码然后进行sha1计算，使用其他的工具包请注意UTF8编码转换)
          /*
           * 以下sha1签名代码效果等同 byte[] sha =
           * org.apache.commons.codec.digest.DigestUtils
           * .sha(org.apache.commons.codec
           * .binary.StringUtils.getBytesUtf8(codes)); String sign =
           * org.apache.commons
           * .codec.binary.Hex.encodeHexString(sha).toUpperCase();
           */
          String sign = org.apache.commons.codec.digest.DigestUtils.shaHex(codes).toUpperCase();
  
          return sign;
      }
focal_method.class_method_signature: DemoApiTool.sign(String appKey, String secret, Map<String, String> paramMap)
focal_method.full_signature: public static String sign(String appKey, String secret, Map<String, String> paramMap)
focal_method.identifier: sign
focal_method.invocations: toArray keySet sort append append append get append toString toUpperCase shaHex
focal_method.modifiers: public static
focal_method.parameters: (String appKey, String secret, Map<String, String> paramMap)
focal_method.return: String
focal_method.signature: String sign(String appKey, String secret, Map<String, String> paramMap)