【问题标题】:Using Firebase to push notification from WordPress to Ionic APP使用 Firebase 将通知从 WordPress 推送到 Ionic APP
【发布时间】:2020-09-17 18:07:02
【问题描述】:

我正在尝试使用 firebase 从插件推送通知,以便 android 应用程序接收到通知。 我有来自谷歌的 API 密钥,但不知道如何获取设备令牌,以便我可以使用 CURL 推送通知。 这是来自Sending Firebase notification with PHP 的帖子,我一直在关注但卡在设备令牌中。我怎样才能得到它?

这是上面提到的链接所推荐的:

<?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);
    ?>

对此的任何帮助将不胜感激。

【问题讨论】:

    标签: android ios wordpress firebase woocommerce


    【解决方案1】:

    最简单的方法是启用设备订阅主题。下面的代码将为用户订阅名为“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());
    }});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 2017-11-17
      • 1970-01-01
      • 2015-08-19
      • 2017-01-27
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多