public static String Myget(String endereco, String deviceId,
String clientId, long timeStamp, String assinatura) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
String comando = "/dispositivo/" + deviceId + "/" + endereco + "?client_id="
+ clientId + "×tamp=" + timeStamp;
System.setProperty("jsse.enableSNIExtension", "false");
URL urlForGetRequest = new URL("https://armariosinteligentes.com/api/v2" + comando + "&signature=" + assinatura);
System.out.println(urlForGetRequest);
HttpURLConnection conection = (HttpURLConnection) urlForGetRequest.openConnection();
conection.setRequestMethod("GET");
conection.setRequestProperty("Content-Type", "application/json");
conection.setRequestProperty("User-Agent", "Mozilla/5.0");
conection.setDoInput(true);
conection.setDoOutput(true);
String readLine = null;
BufferedReader in = new BufferedReader(new InputStreamReader(conection.getInputStream()));
StringBuffer response = new StringBuffer();
while ((readLine = in.readLine()) != null) {
response.append(readLine);
}
in.close();
// print result
System.out.println(
"JSON String Result " + response.toString());
File arquivo = new File("arquivo.txt"); // Gerando log
if (!arquivo.exists()) {
arquivo.createNewFile();
}
FileWriter arq = new FileWriter("C:\\Program Files\\log\\" + endereco + ".txt");
PrintWriter gravarArq = new PrintWriter(arq);
gravarArq.printf(response.toString());
arq.close();
return response.toString();
}
public static String ip() throws IOException, InvalidKeyException, NoSuchAlgorithmException {
Instant currTimeStamp = Instant.now();
long valorRetornoTempo = currTimeStamp.getEpochSecond();
SecretKeySpec keySpec = new SecretKeySpec(
"7e2cc5ee9ee2021cb6752052fdfd8730".getBytes(),
"HmacSHA256");
String comando = "/dispositivo/" + "0B6389406212A0E14D50D7A7DB8D6EE6/" + "ip" + "?client_id="
+ "396b8f007f73124631105c1c81c4bd89" + "×tamp=" + valorRetornoTempo;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(keySpec);
byte[] rawHmac = mac.doFinal(comando.getBytes());
String assinatura = (javax.xml.bind.DatatypeConverter.printHexBinary(rawHmac));
//System.out.println("https://armariosinteligentes.com/api/v2" + comando + "&signature=" + assinatura.toLowerCase());
return Myget("ip", "0B6389406212A0E14D50D7A7DB8D6EE6", "396b8f007f73124631105c1c81c4bd89", valorRetornoTempo, assinatura.toLowerCase());
}
public static void main(String[] args) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
consumo.ip();
}