【问题标题】:Cordova android fcm plugin jquery php background notification on clickCordova android fcm插件jquery php点击背景通知
【发布时间】:2019-11-15 19:09:29
【问题描述】:

我使用 cordova 和 Google FMC 通知插件制作应用程序,在应用程序处于前台之前一切正常。

//MY index.php
<div id="load"></div>  
<script>  
FCMPlugin.onNotification(function(data){
          alert( JSON.stringify(data) );
    // I DONT UNDERSTAND THIS SECTION ???
    // WHAT I SCHOULT DO HERE???

    if(data.wasTapped){
      //Notification was received on device tray and tapped by the user.
      alert( JSON.stringify(data) );

      // I RECIVED THE DATA ON "CLOSED" APP!  GET VARS AND LOAD FILE INTO div id="load" WITH AJAX BASED ON KEY SENDTH FROM FIREBASE CONSOLE
      // EXAMPLE KEY = MESSAGE =  10890 
      // $AJAX LOAD FILE MESSAGE ?ID=10890
      // CLEAR NOTIFICATIONS

       //example ajax
       var message= 10890; // GET FROM CORDOVA NOTIFICATION
       var dataString = '& message=' + message;             
       $.ajax({
       type: "POST",
       url: "https://mywebsite.com/LOAD.php",
       data: dataString,
       success: function(response) {
                        $('#info').html(response);
                                   }
              });

    }else{
      //Notification was received in foreground. Maybe the user needs to be notified.
      alert( JSON.stringify(data) );

      // I RECIVED THE DATA ON OPEN APP!  GET VARS AND LOAD FILE INTO div id="load" WITH AJAX BASED ON KEY SENDTH FROM FIREBASE CONSOLE
      // EXAMPLE KEY = MESSAGE =  10890 
      // $AJAX LOAD FILE MESSAGE ?ID=10890
      // CLEAR NOTIFICATIONS
      // HOW TO GET VAR FROM alert( JSON.stringify(data) ); ??

       //example ajax
       var message= 10890; // GET FROM CORDOVA NOTIFICATION
       var dataString = '& message=' + message;             
       $.ajax({
       type: "POST",
       url: "https://mywebsite.com/LOAD.php",
       data: dataString,
       success: function(response) {
                        $('#info').html(response);
                                   }
              });

    }

    });
    </script>

如果有人能帮助解开这个谜团,请多多关照。我希望它可以帮助其他像我这样不专业的人。 我仅将应用程序用作包装器并加载外部 .php 应用程序适用于我需要的所有功能,这只是我需要解决的问题。

谢谢你,对不起,我是新手

【问题讨论】:

  • Funk Forty Niner 我不是发帖专家,所以我很抱歉用大写的标题发帖,下次我会记住的!谢谢
  • 直截了当,不要在问题中添加噪音。我删除了所有这些以及 PHP 标记,因为您的问题中没有 PHP 代码。
  • 我需要在已经加载了 ajax 的 php 文件上加载 load.php 文件和脚本,这就是我放置 php 标记的原因。

标签: android jquery firebase cordova


【解决方案1】:

发送通知的问题

<?php
    $url = "https://fcm.googleapis.com/fcm/send";
    $token = "xxxx";
    $serverKey = 'xxx';

    $topic = 'mytopic';
    $title = "title";
    $body = "Message.";
    $img = 'https://url.com/images/img.jpg';


    $data = array('USR_id' => '1000',
                  'USR_name' => 'Name',
                  'MSG_id' => '1004',
                  'SEN_id' => '1001',                 
                  'USR_level' => 'user');



        $android = array('senderID' => 'xxxxxxxxxxxx',
                  'sound' => true,
                  'vibrate' => true,
                  'clearNotifications' => true,               
                  'forceShow' => true);



    $notification = array('title' =>$title,
                           'body' => $body,
                          'image' => $img,
                          'sound' => 'audio.mp3',
                          'color' => '#F6C02B',
                   'click_action' => 'FCM_PLUGIN_ACTIVITY',
                          'badge' => '1');

    $arrayToSend = array('to' => '/topics/' . $topic, 
               'notification' => $notification,
                       'data' => $data,
                    'android' => $android,
                   'priority' => 'high');

    $json = json_encode($arrayToSend);
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: key='. $serverKey;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
    //Send the request
    $response = curl_exec($ch);
    //Close request
    if ($response === FALSE) {
    //die('FCM Send Error: ' . curl_error($ch));
    }
    curl_close($ch);
?>

在我用完美的 php 发送它之后

【讨论】:

    猜你喜欢
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多