B4J Question how to convert php to b4j?

Isac

Active Member
Licensed User
Longtime User
This code works to send messages to firebase, how can i convert it to b4j?




PHP:
<?php

$title="ALert";
$descrizione="NEWS id 1";
$idnews=1;   
$topic="all";

$url="https://fcm.googleapis.com/fcm/send";

$headers= array(
"Authorization:  key=AAAAVeez71A:APA91bF0_9w25.........................................,
   
"Content-Type: application/json"
    );
   
$message= array(
  "notification"=>array(
       "title"=> $title,
       "body"=>$descrizione,
       "sound"=>"default",
       "click_action"=>"FCM_PLUGIN_ACTIVITY",
       "icon"=>"fcm_push_icon"),   
  "data"=>array("idnews"=>$idnews),
  "to"=>"/topics/".$topic,
  "priority"=>"normal",
  "restricted_package_name"=>""
    );
   
   
$jfields = json_encode($message);

//echo $jfields;   


        // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, CURLOPT_URL, $url);

        //return the transfer as a string
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jfields);
        //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   
        // $output contains the output string
        $output = curl_exec($ch);
       
if($output===FALSE) {
    echo "Errore invio dati". curl_error($ch);
   
} else {
    echo "Ok invio effettuato";
}
        
        // close curl resource to free up system resources
        curl_close($ch);    



    ?>
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top