Send FCM messages from server side to android device

前端 未结 7 1533
情话喂你
情话喂你 2020-12-03 05:45

With the new update, FCM is now going to be used.

I tried the sample app from git and it\'s working all fine. I can send notifications from the console.

But

7条回答
  •  遥遥无期
    2020-12-03 06:15

    Try this below code this will give push notication for Android from php server side and you can get the device token from android you need pass dynamically to get push notication for more android device.

     array($devicetoken));//get the device token from Android 
            $headers = array( 'Authorization: key=' . $api_key,'Content-Type: application/json');
            $ch = curl_init();
            curl_setopt( $ch, CURLOPT_URL, $url );
            curl_setopt( $ch, CURLOPT_POST, true );
            curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
            curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($fields) );
            $result = curl_exec($ch);
            if(curl_errno($ch)){
                return 'Curl error: ' . curl_error($ch);
            }
            curl_close($ch);
            $cur_message=json_decode($result);
            if($cur_message->success==1)
                return true;
            else
                return false;
    }
    ?>
    

提交回复
热议问题