first commit

This commit is contained in:
MaddoScientisto 2026-03-14 20:04:39 +01:00
commit 4d332ef662
27586 changed files with 3281783 additions and 0 deletions

View file

@ -0,0 +1,15 @@
package com.ablia.cloudmsg;
public class ApnsJson {
private HeadersJson headers;
public HeadersJson getHeaders() {
if (this.headers == null)
this.headers = new HeadersJson();
return this.headers;
}
public void setHeaders(HeadersJson headers) {
this.headers = headers;
}
}

View file

@ -0,0 +1,51 @@
package com.ablia.cloudmsg;
public class CloudMsgJson {
private MsgJson notification;
private MsgJson data;
private String to;
private ApnsJson apns;
public CloudMsgJson(MsgJson notification, MsgJson data, String token) {
this.notification = notification;
this.data = data;
this.to = token;
}
public CloudMsgJson() {}
public MsgJson getNotification() {
return this.notification;
}
public void setNotification(MsgJson notification) {
this.notification = notification;
}
public MsgJson getData() {
return this.data;
}
public void setData(MsgJson data) {
this.data = data;
}
public String getTo() {
return this.to;
}
public void setTo(String to) {
this.to = to;
}
public ApnsJson getApns() {
return this.apns;
}
public void setApns(ApnsJson apns) {
this.apns = apns;
}
}

View file

@ -0,0 +1,16 @@
package com.ablia.cloudmsg;
import com.google.gson.annotations.SerializedName;
public class HeadersJson {
@SerializedName("apns-priority")
private String apnspriority;
public String getApnspriority() {
return (this.apnspriority == null) ? "10" : this.apnspriority.trim();
}
public void setApnspriority(String apnspriority) {
this.apnspriority = apnspriority;
}
}

View file

@ -0,0 +1,61 @@
package com.ablia.cloudmsg;
public class MsgJson {
private String notificationType;
private String title;
private String body;
private String sound;
private String priority;
public MsgJson(String notificationType, String title, String body) {
this.notificationType = notificationType;
this.title = title;
this.body = body;
}
public MsgJson() {}
public String getNotificationType() {
return this.notificationType;
}
public void setNotificationType(String notificationType) {
this.notificationType = notificationType;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return this.body;
}
public void setBody(String body) {
this.body = body;
}
public String getSound() {
return (this.sound == null) ? "default" : this.sound.trim();
}
public void setSound(String sound) {
this.sound = sound;
}
public String getPriority() {
return (this.priority == null) ? "high" : this.priority.trim();
}
public void setPriority(String priprity) {
this.priority = priprity;
}
}

View file

@ -0,0 +1,61 @@
package com.ablia.cloudmsg;
import com.google.gson.Gson;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
public class PushNotificationService {
public PushNotificationService(String serverkey) {
setFirebaseServerkey(serverkey);
}
private final String FIREBASE_API_URL = "https://fcm.googleapis.com/fcm/send";
private String firebaseServerkey;
public void sendPushNotification(List<String> tokens, MsgJson notifica, MsgJson data) {
tokens.forEach(token -> {
System.out.println("\nCalling fcm Server >>>>>>>");
String response = callToFcmServer(token, paramMsgJson1, paramMsgJson2);
System.out.println("Got response from fcm Server : " + response + "\n\n");
});
}
private String callToFcmServer(String token, MsgJson notifica, MsgJson data) {
CloudMsgJson cmj = new CloudMsgJson(notifica, data, token);
StringBuilder result = new StringBuilder();
try {
CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost("https://fcm.googleapis.com/fcm/send");
request.setHeader("Content-Type", "application/json");
request.setHeader("Authorization", "key=" + getFirebaseServerkey());
Gson gson = new Gson();
StringEntity params = new StringEntity(gson.toJson(cmj));
request.setEntity((HttpEntity)params);
HttpResponse resp = closeableHttpClient.execute((HttpUriRequest)request);
String content = EntityUtils.toString(resp.getEntity());
int statusCode = resp.getStatusLine().getStatusCode();
result.append("Status Code: " + statusCode);
result.append("\nstatusCode = " + statusCode);
result.append("\ncontent = " + content);
} catch (Exception e) {
e.printStackTrace();
}
return result.toString();
}
public String getFirebaseServerkey() {
return this.firebaseServerkey;
}
public void setFirebaseServerkey(String firebaseServerkey) {
this.firebaseServerkey = firebaseServerkey;
}
}