Advertisement
Guest User

GCM Decompilada

a guest
Mar 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.73 KB | None | 0 0
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by Fernflower decompiler)
  4. //
  5.  
  6. package com.gcm.operation;
  7.  
  8. import com.gcm.classes.Message;
  9. import com.gcm.util.GCMUtils;
  10. import com.google.gson.Gson;
  11. import java.io.BufferedReader;
  12. import java.io.IOException;
  13. import java.io.InputStreamReader;
  14. import java.io.OutputStream;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.function.Consumer;
  20. import javax.net.ssl.HttpsURLConnection;
  21.  
  22. public class GCMCommunication {
  23.     private GCMCommunication gcmc;
  24.  
  25.     public GCMCommunication() {
  26.     }
  27.  
  28.     public boolean sendMessage(String msj, String recurso, String modulo, String operacion, ArrayList<String> trabajos, String... keys) {
  29.         Message message = new Message();
  30.         if(keys != null) {
  31.             String[] var8 = keys;
  32.             int var9 = keys.length;
  33.  
  34.             for(int var10 = 0; var10 < var9; ++var10) {
  35.                 String key = var8[var10];
  36.                 message.addRegistrationId(key);
  37.             }
  38.         }
  39.  
  40.         message.addData("msj", msj);
  41.         message.addData("recurso", recurso);
  42.         message.addData("modulo", modulo);
  43.         message.addData("operacion", operacion);
  44.         message.addData("trabajos", (new Gson()).toJson(trabajos));
  45.         String sendMsj = (new Gson()).toJson(message);
  46.  
  47.         try {
  48.             URL urlConn = new URL(GCMUtils.IP_CLOUD);
  49.             HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
  50.             httpConn.setRequestMethod("POST");
  51.             httpConn.addRequestProperty("Authorization", "key= " + GCMUtils.ApiKey_ECA_APP);
  52.             httpConn.addRequestProperty("Content-Type", "application/json");
  53.             httpConn.setDoOutput(true);
  54.             OutputStream os = httpConn.getOutputStream();
  55.             os.write(sendMsj.getBytes());
  56.             switch(httpConn.getResponseCode()) {
  57.             case 200:
  58.                 BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
  59.  
  60.                 String line;
  61.                 while((line = br.readLine()) != null) {
  62.                     System.out.print(line);
  63.                 }
  64.  
  65.                 System.out.println();
  66.                 System.out.println("*********************");
  67.                 return true;
  68.             case 401:
  69.                 System.out.println("Fallo autenticacion");
  70.                 break;
  71.             case 500:
  72.                 System.out.println("Internal error");
  73.                 break;
  74.             case 501:
  75.                 System.out.println("Sin implementacion");
  76.             }
  77.         } catch (MalformedURLException var14) {
  78.             ;
  79.         } catch (IOException var15) {
  80.             ;
  81.         }
  82.  
  83.         return false;
  84.     }
  85.  
  86.     public boolean sendMessageWithApi(String msj, String keyApi, String... keys) {
  87.         Message message = new Message();
  88.         if(keys != null) {
  89.             String[] var5 = keys;
  90.             int var6 = keys.length;
  91.  
  92.             for(int var7 = 0; var7 < var6; ++var7) {
  93.                 String key = var5[var7];
  94.                 message.addRegistrationId(key);
  95.             }
  96.         }
  97.  
  98.         message.addData("msj", msj);
  99.         String sendMsj = (new Gson()).toJson(message);
  100.  
  101.         try {
  102.             URL urlConn = new URL(GCMUtils.IP_CLOUD);
  103.             HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
  104.             httpConn.setRequestMethod("POST");
  105.             if(keyApi == null) {
  106.                 httpConn.addRequestProperty("Authorization", "key= " + GCMUtils.ApiKey_ECA_APP);
  107.             } else {
  108.                 httpConn.addRequestProperty("Authorization", "key= " + keyApi);
  109.             }
  110.  
  111.             httpConn.addRequestProperty("Content-Type", "application/json");
  112.             httpConn.setDoOutput(true);
  113.             OutputStream os = httpConn.getOutputStream();
  114.             os.write(sendMsj.getBytes());
  115.             switch(httpConn.getResponseCode()) {
  116.             case 200:
  117.                 BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
  118.  
  119.                 String line;
  120.                 while((line = br.readLine()) != null) {
  121.                     System.out.print(line);
  122.                 }
  123.  
  124.                 System.out.println();
  125.                 System.out.println("*********************");
  126.                 return true;
  127.             case 401:
  128.                 System.out.println("Fallo autenticacion");
  129.                 break;
  130.             case 500:
  131.                 System.out.println("Internal error");
  132.                 break;
  133.             case 501:
  134.                 System.out.println("Sin implementacion");
  135.             }
  136.         } catch (MalformedURLException var11) {
  137.             ;
  138.         } catch (IOException var12) {
  139.             ;
  140.         }
  141.  
  142.         return false;
  143.     }
  144.  
  145.     public boolean sendMessage(String key, HashMap<String, String> data, ArrayList<String> gcmIDs) {
  146.         Message message = new Message();
  147.         if(gcmIDs != null) {
  148.             gcmIDs.stream().forEach((gcmID) -> {
  149.                 message.addRegistrationId(gcmID);
  150.             });
  151.         }
  152.  
  153.         message.addAllData(data);
  154.         String sendMsj = (new Gson()).toJson(message);
  155.  
  156.         try {
  157.             URL urlConn = new URL(GCMUtils.IP_CLOUD);
  158.             HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
  159.             httpConn.setRequestMethod("POST");
  160.             httpConn.addRequestProperty("Authorization", "key= " + key);
  161.             httpConn.addRequestProperty("Content-Type", "application/json");
  162.             httpConn.setDoOutput(true);
  163.             OutputStream os = httpConn.getOutputStream();
  164.             os.write(sendMsj.getBytes());
  165.             switch(httpConn.getResponseCode()) {
  166.             case 200:
  167.                 BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
  168.  
  169.                 String line;
  170.                 while((line = br.readLine()) != null) {
  171.                     System.out.print(line);
  172.                 }
  173.  
  174.                 System.out.println();
  175.                 System.out.println("*********************");
  176.                 return true;
  177.             case 401:
  178.                 System.out.println("Fallo autenticacion");
  179.                 break;
  180.             case 500:
  181.                 System.out.println("Internal error");
  182.                 break;
  183.             case 501:
  184.                 System.out.println("Sin implementacion");
  185.             }
  186.         } catch (MalformedURLException var11) {
  187.             ;
  188.         } catch (IOException var12) {
  189.             ;
  190.         }
  191.  
  192.         return false;
  193.     }
  194.  
  195.     public boolean sendMessage(String gcmId, String msj, String recurso, String modulo, String operacion, String trabajos, ArrayList<String> keys) {
  196.         Message message = new Message();
  197.         if(keys != null && !keys.isEmpty()) {
  198.             message.setRegistration_ids(keys);
  199.         }
  200.  
  201.         message.addData("msj", msj);
  202.         message.addData("recurso", recurso);
  203.         message.addData("modulo", modulo);
  204.         message.addData("operacion", operacion);
  205.         if(trabajos != null) {
  206.             message.addData("trabajos", (new Gson()).toJson(trabajos));
  207.         }
  208.  
  209.         String sendMsj = (new Gson()).toJson(message);
  210.  
  211.         try {
  212.             URL urlConn = new URL(GCMUtils.IP_CLOUD);
  213.             HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
  214.             httpConn.setRequestMethod("POST");
  215.             httpConn.addRequestProperty("Authorization", "key= " + gcmId);
  216.             httpConn.addRequestProperty("Content-Type", "application/json");
  217.             httpConn.setDoOutput(true);
  218.             OutputStream os = httpConn.getOutputStream();
  219.             os.write(sendMsj.getBytes());
  220.             switch(httpConn.getResponseCode()) {
  221.             case 200:
  222.                 BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
  223.  
  224.                 String line;
  225.                 while((line = br.readLine()) != null) {
  226.                     System.out.print(line);
  227.                 }
  228.  
  229.                 System.out.println();
  230.                 System.out.println("*********************");
  231.                 return true;
  232.             case 401:
  233.                 System.out.println("Fallo autenticacion");
  234.                 break;
  235.             case 500:
  236.                 System.out.println("Internal error");
  237.                 break;
  238.             case 501:
  239.                 System.out.println("Sin implementacion");
  240.             }
  241.         } catch (MalformedURLException var15) {
  242.             ;
  243.         } catch (IOException var16) {
  244.             ;
  245.         }
  246.  
  247.         return false;
  248.     }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement