[英]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.