我已在安全环境中部署了Web应用程序。我正在使用FCM HTTP服务器协议来请求FCM应用服务器以将推送通知发送到订户列表。我想在通知中显示一个图标,服务器上存在我的图标文件。我怎样才能做到这一点。请帮忙。
以下是Java中用于推送通知的代码。
private MsgDTO pushNotificationService(String[] tokenArray,
String serverKey, SendNotificationReqType sendNotificationReqType)
throws AppException {
MsgDTO msgDTO = new MsgDTO();
{
HttpURLConnection httpcon = (HttpURLConnection) ((new URL(
"https://fcm.googleapis.com/fcm/send").openConnection()));
httpcon.setDoOutput(true);
httpcon.setRequestProperty("Content-Type", "application/json");
httpcon.setRequestProperty(
"Authorization",
"key="+serverKey);
httpcon.setRequestMethod("POST");
httpcon.connect();
LOG.debug("Connected!");
JSONObject json = new JSONObject();
json.put("registration_ids", tokenArray);
JSONObject info = new JSONObject();
info.put("title", sendNotificationReqType.getTitle()); // Notification title
info.put("body", sendNotificationReqType.getMessage()); // Notification body
info.put("icon","*icon url*"); //
json.put("notification", info);
LOG.debug("pushNotification : "+json.toString());
OutputStreamWriter wr = new OutputStreamWriter(
httpcon.getOutputStream());
wr.write(json.toString());
wr.flush();
}
以下是客户端上的JS代码。
messaging.onMessage(function(payload) {
// Customize notification here
var notificationTitle = payload.notification.title;
var notificationOptions = {
body: payload.notification.body,
icon: '*icon url*'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});