在推送通知接收并替换旧通知时添加新通知

时间:2018-03-29 07:38:26

标签: php android google-app-engine push-notification cordova-plugin-fcm

我在我的应用上使用推送通知。我曾经在推送通知到来时显示通知。如果我发送另一个通知(不清除之前的通知),它会替换新通知。请尽快给我解决方案,这对我来说非常必要。  这是我的代码

<?php
// API access key from Google API's Console
 	function sendNotification($token,$message){
 		$url = 'https://android.googleapis.com/gcm/send';
 		$msg = array
          (
		'body' 	=> 'T...thoihgcggc',
		'title'	=> 'Dexter Studio 123',
		'subtitle'=> 'This is a subtitle. subtitle',
         'tickerText'=> 'Ticker text here...Ticker text here...Ticker text here',
        'vibrate'=>1,
         'sound'=>'default',
         'tag'=>'hellesjhasvhd',
         'badge'=>0,
         'ID'=>12,
             	
          );
 		$fields = array(
            'registration_ids' => $token, // HERE IT IS
            'data' => $msg
        );
 		
 		define("GOOGLE_API_KEY", "Apikey"); 
 		$headers = array(
        'Authorization: key='. GOOGLE_API_KEY,
        'Content-Type: application/json'
    );
 		//print_r($headers);

 		$ch = curl_init();
		curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
		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_POSTFIELDS, json_encode( $fields ) );
		$result = curl_exec($ch );
		echo $result;
		curl_close( $ch );
 	}

 
 	$conn = mysqli_connect("hostname","usrname","password","db");
 	$query = "SELECT * from tbltoken";
 	$token = array();
 	$results = mysqli_query($conn,$query);

 		if(mysqli_num_rows($results)>0 ){
 			while($row = mysqli_fetch_assoc($results)){
 				$token[] = $row["Token"]; 
 			}
 		}
 		//print_r($token);

	mysqli_close($conn); 

	$message = array("message" => "FCM push notification" );
	$message_status = sendNotification($token,$message);
	echo $message_status;

0 个答案:

没有答案