简体   繁体   English

使用 Firebase 将通知从 WordPress 推送到 Ionic APP

[英]Using Firebase to push notification from WordPress to Ionic APP

I am trying to push a notification from a plugin using firebase so that the notification is received by the android app.我正在尝试使用 firebase 从插件推送通知,以便 android 应用程序收到通知。 I have the API key from google but don't know how to get the device token so that I can push notification using CURL.我有来自谷歌的 API 密钥,但不知道如何获取设备令牌,以便我可以使用 CURL 推送通知。 This is a post from Sending Firebase notification with PHP I have been following but stuck in device token.这是来自使用 PHP 发送 Firebase 通知的帖子,我一直在关注但卡在设备令牌中。 How can I get it?我怎么才能得到它?

This what the link mentioned above has recommended:这是上面提到的链接所推荐的:

<?php
    $message = 'ojlaasdasdasd';
    $title = 'ojla';
    $path_to_fcm = 'https://fcm.googleapis.com/fcm/send';    $server_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5LnDZO2BpC2aoPMshfKwRbJAJfZL8C33qRxxxxxxxxxxxxL6';
    $key = 'eqnlxIQ1SWA:APA91bGf1COAZamVzT4onl66_lEdE1nWfY7rIADcnt9gtNYnw7iWTwa7AYPYTHESFholkZ89ydCQS3QeL-lCIuiWTXiqoDREO0xhNdEYboPvqg8QsBYkrQVRlrCLewC4N-hHUja1NG4f';
    $headers = array(
                    'Authorization:key=' .$server_key,
                    'Content-Type: application/json');
    
    $fields = array
                (
                    'to'        => $key,
                    'notification'  => array('title' => $title,'body' => $message)
                );
    
    
    $payload = json_encode($fields);
    
    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, '$path_to_fcm' );
    curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch,CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt( $ch,CURLOPT_POSTFIELDS, $payload);
    $result = curl_exec($ch);
    echo $result;
    curl_close($ch);
    ?>

Any help on this would be highly appreciated.对此的任何帮助将不胜感激。

The easiest way is to enable subscription to a topic by the device.最简单的方法是启用设备订阅主题。 The below code will subscribe the users to the topic named "ALL-USERS".下面的代码将使用户订阅名为“ALL-USERS”的主题。

Now while sending messages using CURL, use the 'to' field as '/topics/ALL-USERS'!现在,在使用 CURL 发送消息时,将“to”字段用作“/topics/ALL-USERS”!

FirebaseMessaging.getInstance().subscribeToTopic("ALL-USERS").addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
    sharedPref.setSubscibeNotif(task.isSuccessful());
}});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建本地通知以响应cordova / ionic中的推送通知(来自firebase) - Creating a local notification in response to a push notification (from firebase) in cordova/ionic 如何将图像添加到来自 firebase 的 android 推送通知。 使用ionic 3开发 - How to add image to android push notification from firebase. developed using ionic 3 在离子应用程序中实现推送通知 - implementing push notification in ionic app 聊天应用程序的Firebase推送通知 - Firebase Push Notification for chat app 应用程序在前台时推送通知(使用 Firebase 触发器) - Push notification when app is in foreground (using Firebase triggers) 应用销毁后如何使用Firebase显示推送通知 - How to show push notification using firebase when app is destroyed 使用解析从应用推送通知 - Push notification from app using parse Firebase 在 android 中从后台删除应用程序时未收到推送通知 - Firebase push notification not received when app remove from background in android 当通过fireBase收到推送通知时,IONIC2在android后台应用程序时增加徽章 - IONIC2 Increment badges while app in background on android when push notification is received via fireBase 使用PHP的Firebase推送通知 - Firebase push notification using PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM