@Test public void testExecuteGet() { try { String type = "forecast_f"; String appid = "0efe9e3c08151b8d"; String date = "201503030741"; String areaid = "101010100"; String key = "a0f6ac_SmartWeatherAPI_cd7e788"; String data = "http: String str = WeatherSecurity.standardURLEncoder(data + appid, key); assertEquals(str, "ocxOZEXG%2BM9aqzMKw0eZK0mXcaA%3D"); String result = data + appid.substring(0, 6) + "&key=" + str; assertEquals(result, "http: } catch (Exception e) { e.printStackTrace(); } }
public static String standardURLEncoder(String data, String key) { try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "HmacSHA1"); mac.init(spec); byte[] byteHMAC = mac.doFinal(data.getBytes()); if (byteHMAC != null) { String oauth = encode(byteHMAC); return URLEncoder.encode(oauth, "utf8"); } } catch (Exception e1) { e1.printStackTrace(); } return ""; }
WeatherSecurity { public static String standardURLEncoder(String data, String key) { try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "HmacSHA1"); mac.init(spec); byte[] byteHMAC = mac.doFinal(data.getBytes()); if (byteHMAC != null) { String oauth = encode(byteHMAC); return URLEncoder.encode(oauth, "utf8"); } } catch (Exception e1) { e1.printStackTrace(); } return ""; } }
WeatherSecurity { public static String standardURLEncoder(String data, String key) { try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "HmacSHA1"); mac.init(spec); byte[] byteHMAC = mac.doFinal(data.getBytes()); if (byteHMAC != null) { String oauth = encode(byteHMAC); return URLEncoder.encode(oauth, "utf8"); } } catch (Exception e1) { e1.printStackTrace(); } return ""; }  }
WeatherSecurity { public static String standardURLEncoder(String data, String key) { try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "HmacSHA1"); mac.init(spec); byte[] byteHMAC = mac.doFinal(data.getBytes()); if (byteHMAC != null) { String oauth = encode(byteHMAC); return URLEncoder.encode(oauth, "utf8"); } } catch (Exception e1) { e1.printStackTrace(); } return ""; }  static String standardURLEncoder(String data, String key); static String encode(byte[] from); }
WeatherSecurity { public static String standardURLEncoder(String data, String key) { try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "HmacSHA1"); mac.init(spec); byte[] byteHMAC = mac.doFinal(data.getBytes()); if (byteHMAC != null) { String oauth = encode(byteHMAC); return URLEncoder.encode(oauth, "utf8"); } } catch (Exception e1) { e1.printStackTrace(); } return ""; }  static String standardURLEncoder(String data, String key); static String encode(byte[] from);  }