Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
- package com.gcm.operation;
- import com.gcm.classes.Message;
- import com.gcm.util.GCMUtils;
- import com.google.gson.Gson;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.function.Consumer;
- import javax.net.ssl.HttpsURLConnection;
- public class GCMCommunication {
- private GCMCommunication gcmc;
- public GCMCommunication() {
- }
- public boolean sendMessage(String msj, String recurso, String modulo, String operacion, ArrayList<String> trabajos, String... keys) {
- Message message = new Message();
- if(keys != null) {
- String[] var8 = keys;
- int var9 = keys.length;
- for(int var10 = 0; var10 < var9; ++var10) {
- String key = var8[var10];
- message.addRegistrationId(key);
- }
- }
- message.addData("msj", msj);
- message.addData("recurso", recurso);
- message.addData("modulo", modulo);
- message.addData("operacion", operacion);
- message.addData("trabajos", (new Gson()).toJson(trabajos));
- String sendMsj = (new Gson()).toJson(message);
- try {
- URL urlConn = new URL(GCMUtils.IP_CLOUD);
- HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
- httpConn.setRequestMethod("POST");
- httpConn.addRequestProperty("Authorization", "key= " + GCMUtils.ApiKey_ECA_APP);
- httpConn.addRequestProperty("Content-Type", "application/json");
- httpConn.setDoOutput(true);
- OutputStream os = httpConn.getOutputStream();
- os.write(sendMsj.getBytes());
- switch(httpConn.getResponseCode()) {
- case 200:
- BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
- String line;
- while((line = br.readLine()) != null) {
- System.out.print(line);
- }
- System.out.println();
- System.out.println("*********************");
- return true;
- case 401:
- System.out.println("Fallo autenticacion");
- break;
- case 500:
- System.out.println("Internal error");
- break;
- case 501:
- System.out.println("Sin implementacion");
- }
- } catch (MalformedURLException var14) {
- ;
- } catch (IOException var15) {
- ;
- }
- return false;
- }
- public boolean sendMessageWithApi(String msj, String keyApi, String... keys) {
- Message message = new Message();
- if(keys != null) {
- String[] var5 = keys;
- int var6 = keys.length;
- for(int var7 = 0; var7 < var6; ++var7) {
- String key = var5[var7];
- message.addRegistrationId(key);
- }
- }
- message.addData("msj", msj);
- String sendMsj = (new Gson()).toJson(message);
- try {
- URL urlConn = new URL(GCMUtils.IP_CLOUD);
- HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
- httpConn.setRequestMethod("POST");
- if(keyApi == null) {
- httpConn.addRequestProperty("Authorization", "key= " + GCMUtils.ApiKey_ECA_APP);
- } else {
- httpConn.addRequestProperty("Authorization", "key= " + keyApi);
- }
- httpConn.addRequestProperty("Content-Type", "application/json");
- httpConn.setDoOutput(true);
- OutputStream os = httpConn.getOutputStream();
- os.write(sendMsj.getBytes());
- switch(httpConn.getResponseCode()) {
- case 200:
- BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
- String line;
- while((line = br.readLine()) != null) {
- System.out.print(line);
- }
- System.out.println();
- System.out.println("*********************");
- return true;
- case 401:
- System.out.println("Fallo autenticacion");
- break;
- case 500:
- System.out.println("Internal error");
- break;
- case 501:
- System.out.println("Sin implementacion");
- }
- } catch (MalformedURLException var11) {
- ;
- } catch (IOException var12) {
- ;
- }
- return false;
- }
- public boolean sendMessage(String key, HashMap<String, String> data, ArrayList<String> gcmIDs) {
- Message message = new Message();
- if(gcmIDs != null) {
- gcmIDs.stream().forEach((gcmID) -> {
- message.addRegistrationId(gcmID);
- });
- }
- message.addAllData(data);
- String sendMsj = (new Gson()).toJson(message);
- try {
- URL urlConn = new URL(GCMUtils.IP_CLOUD);
- HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
- httpConn.setRequestMethod("POST");
- httpConn.addRequestProperty("Authorization", "key= " + key);
- httpConn.addRequestProperty("Content-Type", "application/json");
- httpConn.setDoOutput(true);
- OutputStream os = httpConn.getOutputStream();
- os.write(sendMsj.getBytes());
- switch(httpConn.getResponseCode()) {
- case 200:
- BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
- String line;
- while((line = br.readLine()) != null) {
- System.out.print(line);
- }
- System.out.println();
- System.out.println("*********************");
- return true;
- case 401:
- System.out.println("Fallo autenticacion");
- break;
- case 500:
- System.out.println("Internal error");
- break;
- case 501:
- System.out.println("Sin implementacion");
- }
- } catch (MalformedURLException var11) {
- ;
- } catch (IOException var12) {
- ;
- }
- return false;
- }
- public boolean sendMessage(String gcmId, String msj, String recurso, String modulo, String operacion, String trabajos, ArrayList<String> keys) {
- Message message = new Message();
- if(keys != null && !keys.isEmpty()) {
- message.setRegistration_ids(keys);
- }
- message.addData("msj", msj);
- message.addData("recurso", recurso);
- message.addData("modulo", modulo);
- message.addData("operacion", operacion);
- if(trabajos != null) {
- message.addData("trabajos", (new Gson()).toJson(trabajos));
- }
- String sendMsj = (new Gson()).toJson(message);
- try {
- URL urlConn = new URL(GCMUtils.IP_CLOUD);
- HttpsURLConnection httpConn = (HttpsURLConnection)urlConn.openConnection();
- httpConn.setRequestMethod("POST");
- httpConn.addRequestProperty("Authorization", "key= " + gcmId);
- httpConn.addRequestProperty("Content-Type", "application/json");
- httpConn.setDoOutput(true);
- OutputStream os = httpConn.getOutputStream();
- os.write(sendMsj.getBytes());
- switch(httpConn.getResponseCode()) {
- case 200:
- BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
- String line;
- while((line = br.readLine()) != null) {
- System.out.print(line);
- }
- System.out.println();
- System.out.println("*********************");
- return true;
- case 401:
- System.out.println("Fallo autenticacion");
- break;
- case 500:
- System.out.println("Internal error");
- break;
- case 501:
- System.out.println("Sin implementacion");
- }
- } catch (MalformedURLException var15) {
- ;
- } catch (IOException var16) {
- ;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement